예제 #1
0
 @Test
 public void testCubic() {
   ComplexNumber[] result = CUBIC.getRoots(ONE_REAL_ROOT);
   assertEquals(result.length, 3);
   assertComplexEquals(result[0], new ComplexNumber(1, 0));
   assertComplexEquals(result[1], new ComplexNumber(0, Math.sqrt(10 / 3.)));
   assertComplexEquals(result[2], new ComplexNumber(0, -Math.sqrt(10 / 3.)));
   result = CUBIC.getRoots(ONE_DISTINCT_ROOT);
   assertEquals(result.length, 3);
   for (final ComplexNumber c : result) {
     assertComplexEquals(c, new ComplexNumber(1, 0));
   }
   result = CUBIC.getRoots(THREE_ROOTS);
   assertEquals(result.length, 3);
   assertComplexEquals(result[0], new ComplexNumber(1, 0));
   assertComplexEquals(result[1], new ComplexNumber(3, 0));
   assertComplexEquals(result[2], new ComplexNumber(2, 0));
 }
예제 #2
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void testNonCubic1() {
   CUBIC.getRoots(new RealPolynomialFunction1D(new double[] {1, 1, 1, 1, 1}));
 }
예제 #3
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void testNullFunction1() {
   CUBIC.getRoots(null);
 }