@Test public void testGetParamValuesForDegreeAsArray() { String[] params = new String[] {"A", "B", "C"}; // Ax^2 + Bx + C ParametrisedPolynomial poly = new ParametrisedPolynomial(params); assertArrayEquals(new Double[] {1.0, 0.0, 0.0}, poly.getParamValuesForDegreeAsArray(2)); assertArrayEquals(new Double[] {0.0, 1.0, 0.0}, poly.getParamValuesForDegreeAsArray(1)); assertArrayEquals(new Double[] {0.0, 0.0, 1.0}, poly.getParamValuesForDegreeAsArray(0)); }
@Test public void testMultiplyByScalar() { String[] params = new String[] {"A", "B", "C"}; // Ax^2 + Bx + C ParametrisedPolynomial poly = new ParametrisedPolynomial(params); ParametrisedPolynomial poly3 = poly.multiplyByScalar(18.0); assertArrayEquals(new Double[] {18.0, 0.0, 0.0}, poly3.getParamValuesForDegreeAsArray(2)); assertArrayEquals(new Double[] {0.0, 18.0, 0.0}, poly3.getParamValuesForDegreeAsArray(1)); assertArrayEquals(new Double[] {0.0, 0.0, 18.0}, poly3.getParamValuesForDegreeAsArray(0)); }
@Test public void testMultiplyBySingleArgumentBinomial() { // Let's multiply by x Polynomial poly = Polynomial.getSingleArgumentPolynomialOfDegree(1); String[] params = new String[] {"A", "B"}; // Ax^2 + Bx + C ParametrisedPolynomial paramPoly1 = new ParametrisedPolynomial(params); ParametrisedPolynomial resultPoly1 = paramPoly1.multiplyByPolynomial(poly); assertArrayEquals(new Double[] {1.0, 0.0}, resultPoly1.getParamValuesForDegreeAsArray(2)); assertArrayEquals(new Double[] {0.0, 1.0}, resultPoly1.getParamValuesForDegreeAsArray(1)); assertArrayEquals(new Double[] {0.0, 0.0}, resultPoly1.getParamValuesForDegreeAsArray(0)); }
@Test public void testMultiplyBySingularPolynomial() { // Test singular case - multiplying by 1 Polynomial simplePoly = Polynomial.getSingularPolynomial(); String[] params = new String[] {"A", "B"}; // Ax^2 + Bx + C ParametrisedPolynomial paramPoly1 = new ParametrisedPolynomial(params); ParametrisedPolynomial resultPoly1 = paramPoly1.multiplyByPolynomial(simplePoly); assertArrayEquals(new Double[] {1.0, 0.0}, resultPoly1.getParamValuesForDegreeAsArray(1)); assertArrayEquals(new Double[] {0.0, 1.0}, resultPoly1.getParamValuesForDegreeAsArray(0)); }