Пример #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);
 }