PolynomialRootUtils { public static double getMaximumNegativeRealRoot(ImmutableList<Complex> roots) { return getMaximumNegativeRealRoot(roots, 1e-9); } private  PolynomialRootUtils(); static double getMinimumPositiveRealRoot(ImmutableList<Complex> roots); static double getMinimumPositiveRealRoot(ImmutableList<Complex> roots, double epsilon); static double getMaximumNegativeRealRoot(ImmutableList<Complex> roots); static double getMaximumNegativeRealRoot(ImmutableList<Complex> roots, double epsilon);  }
@Test void getMaximumNegativeRealRoot_whenMultipleNegativeRootsProvided_thenReturnsCorrectValue() { ImmutableList<Complex> roots = ImmutableList.of( new Complex(-2, 0), new Complex(-1, 0), new Complex(-3, 0) ); Assertions.assertEquals(-1, PolynomialRootUtils.getMaximumNegativeRealRoot(roots)); }
@Test void getMaximumNegativeRealRoot_whenComplexRootHasSmallImaginaryPart_thenReturnsRealValue() { ImmutableList<Complex> roots = ImmutableList.of( new Complex(-1, 0.01) ); Assertions.assertEquals(-1, PolynomialRootUtils.getMaximumNegativeRealRoot(roots, 0.1)); }
@Test void getMaximumNegativeRealRoot_whenUnsuitableRootsProvided_thenReturnsCorrectValue() { ImmutableList<Complex> roots = ImmutableList.of( new Complex(1, 0), new Complex(-1, 1), new Complex(-1, -1), new Complex(-53, 0) ); Assertions.assertEquals(-53, PolynomialRootUtils.getMaximumNegativeRealRoot(roots)); }
@Test void getMaximumNegativeRealRoot_whenNoSuitableRootProvided_thenThrowsException() { ImmutableList<Complex> roots = ImmutableList.of( new Complex(0, 0), new Complex(0, 100), new Complex(100, 0) ); Assertions.assertThrows(IllegalArgumentException.class, () -> PolynomialRootUtils.getMaximumNegativeRealRoot(roots)); }
@Test void getMaximumNegativeRealRoot_whenNoRootsProvided_thenThrowsException() { Assertions.assertThrows(IllegalArgumentException.class, () -> PolynomialRootUtils.getMaximumNegativeRealRoot(ImmutableList.of())); }