### Question:
SumToOne { public double[] transform(double[] fitParms) { ArgChecker.isTrue(fitParms.length == _n - 1, "length of fitParms is {}, but must be {} ", fitParms.length, _n - 1); double[] s2 = new double[_n - 1]; double[] c2 = new double[_n - 1]; for (int j = 0; j < _n - 1; j++) { double temp = Math.sin(fitParms[j]); temp *= temp; s2[j] = temp; c2[j] = 1.0 - temp; } double[] res = new double[_n]; for (int i = 0; i < _n; i++) { double prod = 1.0; for (int j = 0; j < _n - 1; j++) { if (_set[i][j] == 1) { prod *= s2[j]; } else if (_set[i][j] == -1) { prod *= c2[j]; } } res[i] = prod; } return res; } SumToOne(int n); double[] transform(double[] fitParms); DoubleArray transform(DoubleArray fitParms); double[] inverseTransform(double[] modelParms); DoubleArray inverseTransform(DoubleArray modelParms); double[][] jacobian(double[] fitParms); DoubleMatrix jacobian(DoubleArray fitParms);  }### Answer:
@Test public void transformTest() { for (int n = 2; n < 13; n++) { double[] from = new double[n - 1]; for (int j = 0; j < n - 1; j++) { from[j] = RANDOM.nextDouble() * Math.PI / 2; } SumToOne trans = new SumToOne(n); DoubleArray to = trans.transform(DoubleArray.copyOf(from)); assertThat(n).isEqualTo(to.size()); double sum = 0; for (int i = 0; i < n; i++) { sum += to.get(i); } assertThat(sum).as("vector length " + n).isCloseTo(1.0, offset(1e-9)); } }