diff --git a/hipparchus-clustering/src/test/java/org/hipparchus/clustering/DBSCANClustererTest.java b/hipparchus-clustering/src/test/java/org/hipparchus/clustering/DBSCANClustererTest.java index 5156fad8b..c226ead4d 100644 --- a/hipparchus-clustering/src/test/java/org/hipparchus/clustering/DBSCANClustererTest.java +++ b/hipparchus-clustering/src/test/java/org/hipparchus/clustering/DBSCANClustererTest.java @@ -181,16 +181,12 @@ void testGetMinPts() { @Test void testNegativeEps() { - assertThrows(MathIllegalArgumentException.class, () -> { - new DBSCANClusterer(-2.0, 5); - }); + assertThrows(MathIllegalArgumentException.class, () -> new DBSCANClusterer(-2.0, 5)); } @Test void testNegativeMinPts() { - assertThrows(MathIllegalArgumentException.class, () -> { - new DBSCANClusterer(2.0, -5); - }); + assertThrows(MathIllegalArgumentException.class, () -> new DBSCANClusterer(2.0, -5)); } @Test diff --git a/hipparchus-clustering/src/test/java/org/hipparchus/clustering/FuzzyKMeansClustererTest.java b/hipparchus-clustering/src/test/java/org/hipparchus/clustering/FuzzyKMeansClustererTest.java index 9a09e955d..a417ed6d3 100644 --- a/hipparchus-clustering/src/test/java/org/hipparchus/clustering/FuzzyKMeansClustererTest.java +++ b/hipparchus-clustering/src/test/java/org/hipparchus/clustering/FuzzyKMeansClustererTest.java @@ -89,9 +89,7 @@ void testCluster() { @Test void testTooSmallFuzzynessFactor() { - assertThrows(MathIllegalArgumentException.class, () -> { - new FuzzyKMeansClusterer(3, 1.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new FuzzyKMeansClusterer(3, 1.0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/CalculusFieldElementAbstractTest.java b/hipparchus-core/src/test/java/org/hipparchus/CalculusFieldElementAbstractTest.java index 5f7bc1376..d15a58842 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/CalculusFieldElementAbstractTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/CalculusFieldElementAbstractTest.java @@ -594,7 +594,7 @@ public void testSign() { @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 5.0e-16, 1.0); + doTestLinearCombinationReference(this::build, 5.0e-16, 1.0); } protected void doTestLinearCombinationReference(final DoubleFunction builder, diff --git a/hipparchus-core/src/test/java/org/hipparchus/UnitTestUtils.java b/hipparchus-core/src/test/java/org/hipparchus/UnitTestUtils.java index 05f0ee3f5..321c4811e 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/UnitTestUtils.java +++ b/hipparchus-core/src/test/java/org/hipparchus/UnitTestUtils.java @@ -153,9 +153,7 @@ public static Object serializeAndRecover(Object o) { ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream si = new ObjectInputStream(bis); return si.readObject(); - } catch (IOException ioe) { - return null; - } catch (ClassNotFoundException cnfe) { + } catch (IOException | ClassNotFoundException ioe) { return null; } } diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/FieldFunctionsTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/FieldFunctionsTest.java index 34bc5eb4f..9bd8aed51 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/FieldFunctionsTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/FieldFunctionsTest.java @@ -34,7 +34,7 @@ public > T value(T x) { } }; CalculusFieldUnivariateFunction f1Converted = f1.toCalculusFieldUnivariateFunction(Binary64Field.getInstance()); - CalculusFieldUnivariateFunction f2 = x -> x.twice(); + CalculusFieldUnivariateFunction f2 = CalculusFieldElement::twice; for (double x = 0; x < 1; x += 0.01) { assertEquals(f2.value(new Binary64(x)).getReal(), diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/FunctionUtilsTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/FunctionUtilsTest.java index 3bf81816f..b8e82ff19 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/FunctionUtilsTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/FunctionUtilsTest.java @@ -226,23 +226,17 @@ void testFixingArguments() { @Test void testSampleWrongBounds(){ - assertThrows(MathIllegalArgumentException.class, () -> { - FunctionUtils.sample(new Sin(), FastMath.PI, 0.0, 10); - }); + assertThrows(MathIllegalArgumentException.class, () -> FunctionUtils.sample(new Sin(), FastMath.PI, 0.0, 10)); } @Test void testSampleNegativeNumberOfPoints(){ - assertThrows(MathIllegalArgumentException.class, () -> { - FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, -1); - }); + assertThrows(MathIllegalArgumentException.class, () -> FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, -1)); } @Test void testSampleNullNumberOfPoints(){ - assertThrows(MathIllegalArgumentException.class, () -> { - FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, 0)); } @Test @@ -260,24 +254,9 @@ void testSample() { @Test void testToDifferentiableUnivariate() { - final UnivariateFunction f0 = new UnivariateFunction() { - @Override - public double value(final double x) { - return x * x; - } - }; - final UnivariateFunction f1 = new UnivariateFunction() { - @Override - public double value(final double x) { - return 2 * x; - } - }; - final UnivariateFunction f2 = new UnivariateFunction() { - @Override - public double value(final double x) { - return 2; - } - }; + final UnivariateFunction f0 = x -> x * x; + final UnivariateFunction f1 = x -> 2 * x; + final UnivariateFunction f2 = x -> 2; final UnivariateDifferentiableFunction f = FunctionUtils.toDifferentiable(f0, f1, f2); DSFactory factory = new DSFactory(1, 2); @@ -306,18 +285,8 @@ void testToDifferentiableMultivariate() { final double a = 1.5; final double b = 0.5; - final MultivariateFunction f = new MultivariateFunction() { - @Override - public double value(final double[] point) { - return a * point[0] + b * point[1]; - } - }; - final MultivariateVectorFunction gradient = new MultivariateVectorFunction() { - @Override - public double[] value(final double[] point) { - return new double[] { a, b }; - } - }; + final MultivariateFunction f = point -> a * point[0] + b * point[1]; + final MultivariateVectorFunction gradient = point -> new double[] { a, b }; final MultivariateDifferentiableFunction mdf = FunctionUtils.toDifferentiable(f, gradient); DSFactory factory11 = new DSFactory(1, 1); @@ -358,18 +327,8 @@ void testToDifferentiableMultivariateInconsistentGradient() { final double a = 1.5; final double b = 0.5; - final MultivariateFunction f = new MultivariateFunction() { - @Override - public double value(final double[] point) { - return a * point[0] + b * point[1]; - } - }; - final MultivariateVectorFunction gradient = new MultivariateVectorFunction() { - @Override - public double[] value(final double[] point) { - return new double[] { a, b, 0.0 }; - } - }; + final MultivariateFunction f = point -> a * point[0] + b * point[1]; + final MultivariateVectorFunction gradient = point -> new double[] { a, b, 0.0 }; final MultivariateDifferentiableFunction mdf = FunctionUtils.toDifferentiable(f, gradient); DSFactory factory = new DSFactory(1, 1); diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DSCompilerTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DSCompilerTest.java index 902298063..08ee556bd 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DSCompilerTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DSCompilerTest.java @@ -142,16 +142,12 @@ void testIndices() { @Test void testIncompatibleParams() { - assertThrows(MathIllegalArgumentException.class, () -> { - DSCompiler.getCompiler(3, 2).checkCompatibility(DSCompiler.getCompiler(4, 2)); - }); + assertThrows(MathIllegalArgumentException.class, () -> DSCompiler.getCompiler(3, 2).checkCompatibility(DSCompiler.getCompiler(4, 2))); } @Test void testIncompatibleOrder() { - assertThrows(MathIllegalArgumentException.class, () -> { - DSCompiler.getCompiler(3, 3).checkCompatibility(DSCompiler.getCompiler(3, 2)); - }); + assertThrows(MathIllegalArgumentException.class, () -> DSCompiler.getCompiler(3, 3).checkCompatibility(DSCompiler.getCompiler(3, 2))); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DerivativeStructureTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DerivativeStructureTest.java index e9f34ee82..620da63d6 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DerivativeStructureTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DerivativeStructureTest.java @@ -69,23 +69,17 @@ protected DerivativeStructure build(final double x) { @Test void testWrongVariableIndex() { - assertThrows(MathIllegalArgumentException.class, () -> { - new DSFactory(3, 1).variable(3, 1.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(3, 1).variable(3, 1.0)); } @Test void testMissingOrders() { - assertThrows(MathIllegalArgumentException.class, () -> { - new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(0, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(0, 1)); } @Test void testTooLargeOrder() { - assertThrows(MathIllegalArgumentException.class, () -> { - new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(1, 1, 2); - }); + assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(1, 1, 2)); } @Test @@ -1518,9 +1512,7 @@ void testDegRad() { @Test void testComposeMismatchedDimensions() { - assertThrows(MathIllegalArgumentException.class, () -> { - new DSFactory(1, 3).variable(0, 1.2).compose(new double[3]); - }); + assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(1, 3).variable(0, 1.2).compose(new double[3])); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureAbstractTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureAbstractTest.java index f0de6b4af..e3826ca80 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureAbstractTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureAbstractTest.java @@ -78,9 +78,7 @@ protected FieldDerivativeStructure build(final double x) { @Test public void testWrongFieldVariableIndex() { - assertThrows(MathIllegalArgumentException.class, () -> { - buildFactory(3, 1).variable(3, buildScalar(1.0)); - }); + assertThrows(MathIllegalArgumentException.class, () -> buildFactory(3, 1).variable(3, buildScalar(1.0))); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureComplexTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureComplexTest.java index 5c6dffb63..260bc19f2 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureComplexTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureComplexTest.java @@ -65,25 +65,7 @@ public void testHypotNoOverflow() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 4.8e-16, 1.0); - } - - @Override - @Test - public void testLinearCombination1DSDS() { - doTestLinearCombination1DSDS(1.0e-15); - } - - @Override - @Test - public void testLinearCombination1FieldDS() { - doTestLinearCombination1FieldDS(1.0e-15); - } - - @Override - @Test - public void testLinearCombination1DoubleDS() { - doTestLinearCombination1DoubleDS(1.0e-15); + doTestLinearCombinationReference(this::build, 4.8e-16, 1.0); } @Override diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureDfpTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureDfpTest.java index 7ce173b1f..91807ad4a 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureDfpTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureDfpTest.java @@ -60,7 +60,7 @@ public void testHypotNoOverflow() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 4.15e-9, 4.21e-9); + doTestLinearCombinationReference(this::build, 4.15e-9, 4.21e-9); } @Override diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientBinary64Test.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientBinary64Test.java index d67454e8e..54446db52 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientBinary64Test.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientBinary64Test.java @@ -41,6 +41,6 @@ public void testHashcode() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 5.0e-16, 1.0); + doTestLinearCombinationReference(this::build, 5.0e-16, 1.0); } } diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientDfpTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientDfpTest.java index 1fd7fba2c..e6175fe3c 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientDfpTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldGradientDfpTest.java @@ -47,7 +47,7 @@ public void testHashcode() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 5.0e-9, 4.212e-9); + doTestLinearCombinationReference(this::build, 5.0e-9, 4.212e-9); } @Override diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1Binary64Test.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1Binary64Test.java index c11a1e1bb..6003c9af3 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1Binary64Test.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1Binary64Test.java @@ -48,6 +48,6 @@ void testHashcode() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 5.0e-9, 1.0); + doTestLinearCombinationReference(this::build, 5.0e-9, 1.0); } } diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1DfpTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1DfpTest.java index bc9a1f18a..d013744c0 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1DfpTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative1DfpTest.java @@ -47,7 +47,7 @@ void testHashcode() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 5.0e-9, 4.212e-9); + doTestLinearCombinationReference(this::build, 5.0e-9, 4.212e-9); } @Override diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2Binary64Test.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2Binary64Test.java index 66f757215..57cc6a079 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2Binary64Test.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2Binary64Test.java @@ -41,6 +41,6 @@ public void testHashcode() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 5.0e-16, 1.0); + doTestLinearCombinationReference(this::build, 5.0e-16, 1.0); } } diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2DfpTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2DfpTest.java index a9819db1b..e9d8149d5 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2DfpTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldUnivariateDerivative2DfpTest.java @@ -47,7 +47,7 @@ public void testHashcode() { @Override @Test public void testLinearCombinationReference() { - doTestLinearCombinationReference(x -> build(x), 5.0e-9, 4.212e-9); + doTestLinearCombinationReference(this::build, 5.0e-9, 4.212e-9); } @Override diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java index 1a2c21a0c..f939a93b6 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FiniteDifferencesDifferentiatorTest.java @@ -46,16 +46,12 @@ class FiniteDifferencesDifferentiatorTest { @Test void testWrongNumberOfPoints() { - assertThrows(MathIllegalArgumentException.class, () -> { - new FiniteDifferencesDifferentiator(1, 1.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new FiniteDifferencesDifferentiator(1, 1.0)); } @Test void testWrongStepSize() { - assertThrows(MathIllegalArgumentException.class, () -> { - new FiniteDifferencesDifferentiator(3, 0.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new FiniteDifferencesDifferentiator(3, 0.0)); } @Test @@ -73,12 +69,7 @@ void testConstant() { FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 0.01); UnivariateDifferentiableFunction f = - differentiator.differentiate(new UnivariateFunction() { - @Override - public double value(double x) { - return 42.0; - } - }); + differentiator.differentiate((UnivariateFunction) x -> 42.0); DSFactory factory = new DSFactory(1, 2); for (double x = -10; x < 10; x += 0.1) { DerivativeStructure y = f.value(factory.variable(0, x)); @@ -93,12 +84,7 @@ void testLinear() { FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 0.01); UnivariateDifferentiableFunction f = - differentiator.differentiate(new UnivariateFunction() { - @Override - public double value(double x) { - return 2 - 3 * x; - } - }); + differentiator.differentiate((UnivariateFunction) x -> 2 - 3 * x); DSFactory factory = new DSFactory(1, 2); for (double x = -10; x < 10; x += 0.1) { DerivativeStructure y = f.value(factory.variable(0, x)); @@ -184,13 +170,10 @@ void testStepSizeUnstability() { void testWrongOrder() { assertThrows(MathIllegalArgumentException.class, () -> { UnivariateDifferentiableFunction f = - new FiniteDifferencesDifferentiator(3, 0.01).differentiate(new UnivariateFunction() { - @Override - public double value(double x) { - // this exception should not be thrown because wrong order - // should be detected before function call - throw MathRuntimeException.createInternalError(); - } + new FiniteDifferencesDifferentiator(3, 0.01).differentiate((UnivariateFunction) x -> { + // this exception should not be thrown because wrong order + // should be detected before function call + throw MathRuntimeException.createInternalError(); }); f.value(new DSFactory(1, 3).variable(0, 1.0)); }); @@ -200,13 +183,10 @@ public double value(double x) { void testWrongOrderVector() { assertThrows(MathIllegalArgumentException.class, () -> { UnivariateDifferentiableVectorFunction f = - new FiniteDifferencesDifferentiator(3, 0.01).differentiate(new UnivariateVectorFunction() { - @Override - public double[] value(double x) { - // this exception should not be thrown because wrong order - // should be detected before function call - throw MathRuntimeException.createInternalError(); - } + new FiniteDifferencesDifferentiator(3, 0.01).differentiate((UnivariateVectorFunction) x -> { + // this exception should not be thrown because wrong order + // should be detected before function call + throw MathRuntimeException.createInternalError(); }); f.value(new DSFactory(1, 3).variable(0, 1.0)); }); @@ -216,13 +196,10 @@ public double[] value(double x) { void testWrongOrderMatrix() { assertThrows(MathIllegalArgumentException.class, () -> { UnivariateDifferentiableMatrixFunction f = - new FiniteDifferencesDifferentiator(3, 0.01).differentiate(new UnivariateMatrixFunction() { - @Override - public double[][] value(double x) { - // this exception should not be thrown because wrong order - // should be detected before function call - throw MathRuntimeException.createInternalError(); - } + new FiniteDifferencesDifferentiator(3, 0.01).differentiate((UnivariateMatrixFunction) x -> { + // this exception should not be thrown because wrong order + // should be detected before function call + throw MathRuntimeException.createInternalError(); }); f.value(new DSFactory(1, 3).variable(0, 1.0)); }); @@ -230,27 +207,22 @@ public double[][] value(double x) { @Test void testTooLargeStep() { - assertThrows(MathIllegalArgumentException.class, () -> { - new FiniteDifferencesDifferentiator(3, 2.5, 0.0, 1.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new FiniteDifferencesDifferentiator(3, 2.5, 0.0, 1.0)); } @Test void testBounds() { final double slope = 2.5; - UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - if (x < 0) { - throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_SMALL, - x, 0); - } else if (x > 1) { - throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE, - x, 1); - } else { - return slope * x; - } + UnivariateFunction f = x -> { + if (x < 0) { + throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_SMALL, + x, 0); + } else if (x > 1) { + throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE, + x, 1); + } else { + return slope * x; } }; @@ -301,12 +273,7 @@ void testBoundedSqrt() { UnivariateFunctionDifferentiator differentiator = new FiniteDifferencesDifferentiator(9, 1.0 / 32, 0.0, Double.POSITIVE_INFINITY); - UnivariateDifferentiableFunction sqrt = differentiator.differentiate(new UnivariateFunction() { - @Override - public double value(double x) { - return FastMath.sqrt(x); - } - }); + UnivariateDifferentiableFunction sqrt = differentiator.differentiate(x -> FastMath.sqrt(x)); // we are able to compute derivative near 0, but the accuracy is much poorer there DSFactory factory = new DSFactory(1, 1); @@ -325,14 +292,7 @@ void testVectorFunction() { FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(7, 0.01); UnivariateDifferentiableVectorFunction f = - differentiator.differentiate(new UnivariateVectorFunction() { - - @Override - public double[] value(double x) { - return new double[] { FastMath.cos(x), FastMath.sin(x) }; - } - - }); + differentiator.differentiate((UnivariateVectorFunction) x -> new double[] { FastMath.cos(x), FastMath.sin(x) }); DSFactory factory = new DSFactory(1, 2); for (double x = -10; x < 10; x += 0.1) { @@ -362,17 +322,10 @@ void testMatrixFunction() { FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(7, 0.01); UnivariateDifferentiableMatrixFunction f = - differentiator.differentiate(new UnivariateMatrixFunction() { - - @Override - public double[][] value(double x) { - return new double[][] { + differentiator.differentiate((UnivariateMatrixFunction) x -> new double[][] { { FastMath.cos(x), FastMath.sin(x) }, { FastMath.cosh(x), FastMath.sinh(x) } - }; - } - - }); + }); DSFactory factory = new DSFactory(1, 2); for (double x = -1; x < 1; x += 0.02) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/GaussianTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/GaussianTest.java index b979a03b9..d5321e689 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/GaussianTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/GaussianTest.java @@ -43,9 +43,7 @@ class GaussianTest { @Test void testPreconditions() { - assertThrows(MathIllegalArgumentException.class, () -> { - new Gaussian(1, 2, -1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Gaussian(1, 2, -1)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/LogisticTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/LogisticTest.java index b689190ff..2c99397ac 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/LogisticTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/LogisticTest.java @@ -41,16 +41,12 @@ class LogisticTest { @Test void testPreconditions1() { - assertThrows(MathIllegalArgumentException.class, () -> { - new Logistic(1, 0, 1, 1, 0, -1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Logistic(1, 0, 1, 1, 0, -1)); } @Test void testPreconditions2() { - assertThrows(MathIllegalArgumentException.class, () -> { - new Logistic(1, 0, 1, 1, 0, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Logistic(1, 0, 1, 1, 0, 0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SincTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SincTest.java index 735e0f528..042f0d6fb 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SincTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SincTest.java @@ -37,12 +37,9 @@ class SincTest { @Test void testShortcut() { final Sinc s = new Sinc(); - final UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - Dfp dfpX = new DfpField(25).newDfp(x); - return DfpMath.sin(dfpX).divide(dfpX).toDouble(); - } + final UnivariateFunction f = x -> { + Dfp dfpX = new DfpField(25).newDfp(x); + return DfpMath.sin(dfpX).divide(dfpX).toDouble(); }; for (double x = 1e-30; x < 1e10; x *= 2) { @@ -112,13 +109,10 @@ void testDerivatives1Dot2Normalized() { @Test void testDerivativeShortcut() { final Sinc sinc = new Sinc(); - final UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - Dfp dfpX = new DfpField(25).newDfp(x); - return DfpMath.cos(dfpX).subtract(DfpMath.sin(dfpX).divide(dfpX)).divide(dfpX).toDouble(); - } - }; + final UnivariateFunction f = x -> { + Dfp dfpX = new DfpField(25).newDfp(x); + return DfpMath.cos(dfpX).subtract(DfpMath.sin(dfpX).divide(dfpX)).divide(dfpX).toDouble(); + }; DSFactory factory = new DSFactory(1, 1); for (double x = 1e-30; x < 1e10; x *= 2) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SqrtTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SqrtTest.java index c94b0218e..b42fa8b32 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SqrtTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/SqrtTest.java @@ -34,12 +34,7 @@ class SqrtTest { @Test void testComparison() { final Sqrt s = new Sqrt(); - final UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - return FastMath.sqrt(x); - } - }; + final UnivariateFunction f = x -> FastMath.sqrt(x); for (double x = 1e-30; x < 1e10; x *= 2) { final double fX = f.value(x); @@ -51,12 +46,7 @@ public double value(double x) { @Test void testDerivativeComparison() { final UnivariateDifferentiableFunction sPrime = new Sqrt(); - final UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - return 1 / (2 * FastMath.sqrt(x)); - } - }; + final UnivariateFunction f = x -> 1 / (2 * FastMath.sqrt(x)); DSFactory factory = new DSFactory(1, 1); for (double x = 1e-30; x < 1e10; x *= 2) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/StepFunctionTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/StepFunctionTest.java index ef0184848..a0f60b781 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/function/StepFunctionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/function/StepFunctionTest.java @@ -38,44 +38,32 @@ class StepFunctionTest { @Test void testPreconditions1() { - assertThrows(NullArgumentException.class, () -> { - new StepFunction(null, new double[]{0, -1, -2}); - }); + assertThrows(NullArgumentException.class, () -> new StepFunction(null, new double[]{0, -1, -2})); } @Test void testPreconditions2() { - assertThrows(NullArgumentException.class, () -> { - new StepFunction(new double[]{0, 1}, null); - }); + assertThrows(NullArgumentException.class, () -> new StepFunction(new double[]{0, 1}, null)); } @Test void testPreconditions3() { - assertThrows(MathIllegalArgumentException.class, () -> { - new StepFunction(new double[]{0}, new double[]{}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new StepFunction(new double[]{0}, new double[]{})); } @Test void testPreconditions4() { - assertThrows(MathIllegalArgumentException.class, () -> { - new StepFunction(new double[]{}, new double[]{0}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new StepFunction(new double[]{}, new double[]{0})); } @Test void testPreconditions5() { - assertThrows(MathIllegalArgumentException.class, () -> { - new StepFunction(new double[]{0, 1}, new double[]{0, -1, -2}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new StepFunction(new double[]{0, 1}, new double[]{0, -1, -2})); } @Test void testPreconditions6() { - assertThrows(MathIllegalArgumentException.class, () -> { - new StepFunction(new double[]{1, 0, 1}, new double[]{0, -1, -2}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new StepFunction(new double[]{1, 0, 1}, new double[]{0, -1, -2})); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldIterativeLegendreGaussIntegratorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldIterativeLegendreGaussIntegratorTest.java index e2f9954cc..142b5ae13 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldIterativeLegendreGaussIntegratorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldIterativeLegendreGaussIntegratorTest.java @@ -49,7 +49,7 @@ void testSinFunction() { double expected = 2; double tolerance = FastMath.max(integrator.getAbsoluteAccuracy(), FastMath.abs(expected * integrator.getRelativeAccuracy())); - double result = integrator.integrate(10000, x -> x.sin(), min, max).getReal(); + double result = integrator.integrate(10000, Binary64::sin, min, max).getReal(); assertEquals(expected, result, tolerance); min = new Binary64(-FastMath.PI/3); @@ -57,7 +57,7 @@ void testSinFunction() { expected = -0.5; tolerance = FastMath.max(integrator.getAbsoluteAccuracy(), FastMath.abs(expected * integrator.getRelativeAccuracy())); - result = integrator.integrate(10000, x -> x.sin(), min, max).getReal(); + result = integrator.integrate(10000, Binary64::sin, min, max).getReal(); assertEquals(expected, result, tolerance); } diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldMidPointIntegratorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldMidPointIntegratorTest.java index 59856f10d..82fbe6c16 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldMidPointIntegratorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldMidPointIntegratorTest.java @@ -72,7 +72,7 @@ void testSinFunction() { Binary64 max = new Binary64(FastMath.PI); double expected = 2; double tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - double result = integrator.integrate(Integer.MAX_VALUE, x -> x.sin(), min, max).getReal(); + double result = integrator.integrate(Integer.MAX_VALUE, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < Integer.MAX_VALUE / 2); assertTrue(integrator.getIterations() < MidPointIntegrator.MIDPOINT_MAX_ITERATIONS_COUNT / 2); assertEquals(expected, result, tolerance); @@ -81,7 +81,7 @@ void testSinFunction() { max = new Binary64(0); expected = -0.5; tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - result = integrator.integrate(Integer.MAX_VALUE, x -> x.sin(), min, max).getReal(); + result = integrator.integrate(Integer.MAX_VALUE, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < Integer.MAX_VALUE / 2); assertTrue(integrator.getIterations() < MidPointIntegrator.MIDPOINT_MAX_ITERATIONS_COUNT / 2); assertEquals(expected, result, tolerance); @@ -134,7 +134,7 @@ void testParameters() { try { // bad interval - new FieldMidPointIntegrator<>(Binary64Field.getInstance()).integrate(1000, x -> x.sin(), + new FieldMidPointIntegrator<>(Binary64Field.getInstance()).integrate(1000, Binary64::sin, new Binary64(1), new Binary64(-1)); fail("Expecting MathIllegalArgumentException - bad interval"); } catch (MathIllegalArgumentException ex) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldRombergIntegratorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldRombergIntegratorTest.java index 6ad36b580..bf9309180 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldRombergIntegratorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldRombergIntegratorTest.java @@ -54,7 +54,7 @@ void testSinFunction() { Binary64 max = new Binary64(FastMath.PI); double expected = 2; double tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - double result = integrator.integrate(100, x -> x.sin(), min, max).getReal(); + double result = integrator.integrate(100, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < 50); assertTrue(integrator.getIterations() < 10); assertEquals(expected, result, tolerance); @@ -63,7 +63,7 @@ void testSinFunction() { max = new Binary64(0); expected = -0.5; tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - result = integrator.integrate(100, x -> x.sin(), min, max).getReal(); + result = integrator.integrate(100, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < 50); assertTrue(integrator.getIterations() < 10); assertEquals(expected, result, tolerance); @@ -114,7 +114,7 @@ void testParameters() { try { // bad interval - new FieldRombergIntegrator<>(Binary64Field.getInstance()).integrate(1000, x -> x.sin(), + new FieldRombergIntegrator<>(Binary64Field.getInstance()).integrate(1000, Binary64::sin, new Binary64(1), new Binary64(-1)); fail("Expecting MathIllegalArgumentException - bad interval"); } catch (MathIllegalArgumentException ex) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldSimpsonIntegratorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldSimpsonIntegratorTest.java index 9827dbbb7..35e0fd2b1 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldSimpsonIntegratorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldSimpsonIntegratorTest.java @@ -53,7 +53,7 @@ void testSinFunction() { Binary64 max = new Binary64(FastMath.PI); double expected = 2; double tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - double result = integrator.integrate(1000, x -> x.sin(), min, max).getReal(); + double result = integrator.integrate(1000, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < 100); assertTrue(integrator.getIterations() < 10); assertEquals(expected, result, tolerance); @@ -62,7 +62,7 @@ void testSinFunction() { max = new Binary64(0); expected = -0.5; tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - result = integrator.integrate(1000, x -> x.sin(), min, max).getReal(); + result = integrator.integrate(1000, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < 50); assertTrue(integrator.getIterations() < 10); assertEquals(expected, result, tolerance); @@ -112,7 +112,7 @@ void testQuinticFunction() { void testParameters() { try { // bad interval - new FieldSimpsonIntegrator<>(Binary64Field.getInstance()).integrate(1000, x -> x.sin(), + new FieldSimpsonIntegrator<>(Binary64Field.getInstance()).integrate(1000, Binary64::sin, new Binary64(1), new Binary64(-1)); fail("Expecting MathIllegalArgumentException - bad interval"); } catch (MathIllegalArgumentException ex) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldTrapezoidIntegratorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldTrapezoidIntegratorTest.java index bbd22ea98..6e27c40fa 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldTrapezoidIntegratorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/FieldTrapezoidIntegratorTest.java @@ -53,7 +53,7 @@ void testSinFunction() { Binary64 max = new Binary64(FastMath.PI); double expected = 2; double tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - double result = integrator.integrate(10000, x -> x.sin(), min, max).getReal(); + double result = integrator.integrate(10000, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < 2500); assertTrue(integrator.getIterations() < 15); assertEquals(expected, result, tolerance); @@ -62,7 +62,7 @@ void testSinFunction() { max = new Binary64(0); expected = -0.5; tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy()); - result = integrator.integrate(10000, x -> x.sin(), min, max).getReal(); + result = integrator.integrate(10000, Binary64::sin, min, max).getReal(); assertTrue(integrator.getEvaluations() < 2500); assertTrue(integrator.getIterations() < 15); assertEquals(expected, result, tolerance); @@ -113,7 +113,7 @@ void testQuinticFunction() { void testParameters() { try { // bad interval - new FieldTrapezoidIntegrator<>(Binary64Field.getInstance()).integrate(1000, x -> x.sin(), + new FieldTrapezoidIntegrator<>(Binary64Field.getInstance()).integrate(1000, Binary64::sin, new Binary64(1), new Binary64(-1)); fail("Expecting MathIllegalArgumentException - bad interval"); } catch (MathIllegalArgumentException ex) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/IterativeLegendreGaussIntegratorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/IterativeLegendreGaussIntegratorTest.java index 58615327a..ffc5458f9 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/IterativeLegendreGaussIntegratorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/IterativeLegendreGaussIntegratorTest.java @@ -133,12 +133,7 @@ void testNormalDistributionWithLargeSigma() { @Test void testIssue464() { final double value = 0.2; - UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - return (x >= 0 && x <= 5) ? value : 0.0; - } - }; + UnivariateFunction f = x -> (x >= 0 && x <= 5) ? value : 0.0; IterativeLegendreGaussIntegrator gauss = new IterativeLegendreGaussIntegrator(5, 3, 100); diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/FieldLegendreTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/FieldLegendreTest.java index 512be3aeb..0c238746b 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/FieldLegendreTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/FieldLegendreTest.java @@ -53,7 +53,7 @@ void testTooLArgeNumberOfPoints() { @Test void testCos() { final FieldGaussIntegrator integrator = factory.legendre(7, new Binary64(0), new Binary64(Math.PI / 2)); - final double s = integrator.integrate(x -> FastMath.cos(x)).getReal(); + final double s = integrator.integrate(FastMath::cos).getReal(); // System.out.println("s=" + s + " e=" + 1); assertEquals(1, s, Math.ulp(1d)); } @@ -66,7 +66,7 @@ void testInverse() { final Binary64 hi = new Binary64(456.78); final FieldGaussIntegrator integrator = factory.legendre(60, lo, hi); - final double s = integrator.integrate(x -> x.reciprocal()).getReal(); + final double s = integrator.integrate(Binary64::reciprocal).getReal(); final double expected = FastMath.log(hi).subtract(FastMath.log(lo)).getReal(); // System.out.println("s=" + s + " e=" + expected); assertEquals(expected, s, 1e-14); diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/HermiteTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/HermiteTest.java index 6bcb0fba8..7f5ccfc22 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/HermiteTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/HermiteTest.java @@ -48,11 +48,9 @@ void testNormalDistribution() { // N(x, mu, sigma) // is transformed to // f(y) * exp(-y^2) - final UnivariateFunction f = new UnivariateFunction() { - public double value(double y) { - return oneOverSqrtPi; // Constant function. - } - }; + final UnivariateFunction f = y -> { + return oneOverSqrtPi; // Constant function. + }; final GaussIntegrator integrator = factory.hermite(numPoints); final double result = integrator.integrate(f); @@ -75,11 +73,7 @@ void testNormalMean() { // x * N(x, mu, sigma) // is transformed to // f(y) * exp(-y^2) - final UnivariateFunction f = new UnivariateFunction() { - public double value(double y) { - return oneOverSqrtPi * (sqrtTwo * sigma * y + mu); - } - }; + final UnivariateFunction f = y -> oneOverSqrtPi * (sqrtTwo * sigma * y + mu); final GaussIntegrator integrator = factory.hermite(numPoints); final double result = integrator.integrate(f); @@ -101,11 +95,7 @@ void testNormalVariance() { // (x - mu)^2 * N(x, mu, sigma) // is transformed to // f(y) * exp(-y^2) - final UnivariateFunction f = new UnivariateFunction() { - public double value(double y) { - return twoOverSqrtPi * sigma2 * y * y; - } - }; + final UnivariateFunction f = y -> twoOverSqrtPi * sigma2 * y * y; final GaussIntegrator integrator = factory.hermite(numPoints); final double result = integrator.integrate(f); diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/LaguerreTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/LaguerreTest.java index bda95a320..723d36b21 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/LaguerreTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/integration/gauss/LaguerreTest.java @@ -41,12 +41,7 @@ void testGamma() { for (int i = 2; i < 10; i += 1) { final double t = i; - final UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - return FastMath.pow(x, t - 1); - } - }; + final UnivariateFunction f = x -> FastMath.pow(x, t - 1); final GaussIntegrator integrator = factory.laguerre(7); final double s = integrator.integrate(f); diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatingFunctionTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatingFunctionTest.java index a9b3ad306..6be0f0bdc 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatingFunctionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatingFunctionTest.java @@ -224,30 +224,10 @@ void testPlane() { final double maxTolerance = 1e-14; // Function values - BivariateFunction f = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 2 * x - 3 * y + 5; - } - }; - BivariateFunction dfdx = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 2; - } - }; - BivariateFunction dfdy = new BivariateFunction() { - @Override - public double value(double x, double y) { - return -3; - } - }; - BivariateFunction d2fdxdy = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 0; - } - }; + BivariateFunction f = (x, y) -> 2 * x - 3 * y + 5; + BivariateFunction dfdx = (x, y) -> 2; + BivariateFunction dfdy = (x, y) -> -3; + BivariateFunction d2fdxdy = (x, y) -> 0; testInterpolation(minimumX, maximumX, @@ -282,30 +262,10 @@ void testParaboloid() { final double maxTolerance = 1e-12; // Function values - BivariateFunction f = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 2 * x * x - 3 * y * y + 4 * x * y - 5; - } - }; - BivariateFunction dfdx = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 4 * (x + y); - } - }; - BivariateFunction dfdy = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 4 * x - 6 * y; - } - }; - BivariateFunction d2fdxdy = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 4; - } - }; + BivariateFunction f = (x, y) -> 2 * x * x - 3 * y * y + 4 * x * y - 5; + BivariateFunction dfdx = (x, y) -> 4 * (x + y); + BivariateFunction dfdy = (x, y) -> 4 * x - 6 * y; + BivariateFunction d2fdxdy = (x, y) -> 4; testInterpolation(minimumX, maximumX, diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatorTest.java index 47c512bb5..0f0b5668a 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/BicubicInterpolatorTest.java @@ -86,12 +86,7 @@ void testPreconditions() { */ @Test void testPlane() { - BivariateFunction f = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 2 * x - 3 * y + 5; - } - }; + BivariateFunction f = (x, y) -> 2 * x - 3 * y + 5; testInterpolation(3000, 1e-13, @@ -106,12 +101,7 @@ public double value(double x, double y) { */ @Test void testParaboloid() { - BivariateFunction f = new BivariateFunction() { - @Override - public double value(double x, double y) { - return 2 * x * x - 3 * y * y + 4 * x * y - 5; - } - }; + BivariateFunction f = (x, y) -> 2 * x * x - 3 * y * y + 4 * x * y - 5; testInterpolation(3000, 1e-12, diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/FieldHermiteInterpolatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/FieldHermiteInterpolatorTest.java index ea50e7d61..6ea9be00d 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/FieldHermiteInterpolatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/FieldHermiteInterpolatorTest.java @@ -263,16 +263,12 @@ private PolynomialFunction randomPolynomial(int degree, Random random) { @Test void testEmptySampleValue() { - assertThrows(MathIllegalArgumentException.class, () -> { - new FieldHermiteInterpolator().value(BigFraction.ZERO); - }); + assertThrows(MathIllegalArgumentException.class, () -> new FieldHermiteInterpolator().value(BigFraction.ZERO)); } @Test void testEmptySampleDerivative() { - assertThrows(MathIllegalArgumentException.class, () -> { - new FieldHermiteInterpolator().derivatives(BigFraction.ZERO, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new FieldHermiteInterpolator().derivatives(BigFraction.ZERO, 1)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/HermiteInterpolatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/HermiteInterpolatorTest.java index a6bec87c1..fe4676b3e 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/HermiteInterpolatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/HermiteInterpolatorTest.java @@ -274,9 +274,7 @@ private PolynomialFunction randomPolynomial(int degree, Random random) { @Test void testEmptySample() { - assertThrows(MathIllegalArgumentException.class, () -> { - new HermiteInterpolator().value(0.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new HermiteInterpolator().value(0.0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/LoessInterpolatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/LoessInterpolatorTest.java index d78bc2f20..9dec2f42a 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/LoessInterpolatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/LoessInterpolatorTest.java @@ -165,30 +165,22 @@ void testIncreasingRobustnessItersIncreasesSmoothnessWithOutliers() { @Test void testUnequalSizeArguments() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LoessInterpolator().smooth(new double[]{1, 2, 3}, new double[]{1, 2, 3, 4}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LoessInterpolator().smooth(new double[]{1, 2, 3}, new double[]{1, 2, 3, 4})); } @Test void testEmptyData() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LoessInterpolator().smooth(new double[]{}, new double[]{}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LoessInterpolator().smooth(new double[]{}, new double[]{})); } @Test void testNonStrictlyIncreasing1() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LoessInterpolator().smooth(new double[]{4, 3, 1, 2}, new double[]{3, 4, 5, 6}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LoessInterpolator().smooth(new double[]{4, 3, 1, 2}, new double[]{3, 4, 5, 6})); } @Test void testNonStrictlyIncreasing2() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LoessInterpolator().smooth(new double[]{1, 2, 2, 3}, new double[]{3, 4, 5, 6}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LoessInterpolator().smooth(new double[]{1, 2, 2, 3}, new double[]{3, 4, 5, 6})); } @Test @@ -256,16 +248,12 @@ void testInsufficientBandwidth() { @Test void testCompletelyIncorrectBandwidth1() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LoessInterpolator(-0.2, 3, 1e-12); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LoessInterpolator(-0.2, 3, 1e-12)); } @Test void testCompletelyIncorrectBandwidth2() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LoessInterpolator(1.1, 3, 1e-12); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LoessInterpolator(1.1, 3, 1e-12)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/MicrosphereProjectionInterpolatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/MicrosphereProjectionInterpolatorTest.java index 2fac77d22..a69acadea 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/MicrosphereProjectionInterpolatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/MicrosphereProjectionInterpolatorTest.java @@ -53,14 +53,11 @@ final class MicrosphereProjectionInterpolatorTest { */ @Test void testLinearFunction2D() { - MultivariateFunction f = new MultivariateFunction() { - @Override - public double value(double[] x) { - if (x.length != 2) { - throw new IllegalArgumentException(); - } - return 2 * x[0] - 3 * x[1] + 5; + MultivariateFunction f = x -> { + if (x.length != 2) { + throw new IllegalArgumentException(); } + return 2 * x[0] - 3 * x[1] + 5; }; final double darkFraction = 0.5; diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java index b00a7a135..4ab15a518 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/PiecewiseBicubicSplineInterpolatorTest.java @@ -143,12 +143,7 @@ void testInterpolation1() { } // Function values - BivariateFunction f = new BivariateFunction() { - @Override - public double value( double x, double y ) { - return 2 * x - 3 * y + 5; - } - }; + BivariateFunction f = (x, y) -> 2 * x - 3 * y + 5; double[][] zval = new double[xval.length][yval.length]; for ( int i = 0; i < xval.length; i++ ) { for ( int j = 0; j < yval.length; j++ ) { @@ -192,12 +187,7 @@ void testInterpolation2() { } // Function values - BivariateFunction f = new BivariateFunction() { - @Override - public double value( double x, double y ) { - return 2 * x * x - 3 * y * y + 4 * x * y - 5; - } - }; + BivariateFunction f = (x, y) -> 2 * x * x - 3 * y * y + 4 * x * y - 5; double[][] zval = new double[xval.length][yval.length]; for ( int i = 0; i < xval.length; i++ ) { for ( int j = 0; j < yval.length; j++ ) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatingFunctionTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatingFunctionTest.java index d91ecad33..f92a6286a 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatingFunctionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatingFunctionTest.java @@ -488,40 +488,15 @@ private void testInterpolation(double minimumX, */ @Test void testPlane() { - final TrivariateFunction f = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 2 * x - 3 * y - 4 * z + 5; - } - }; + final TrivariateFunction f = (x, y, z) -> 2 * x - 3 * y - 4 * z + 5; - final TrivariateFunction dfdx = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 2; - } - }; + final TrivariateFunction dfdx = (x, y, z) -> 2; - final TrivariateFunction dfdy = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return -3; - } - }; + final TrivariateFunction dfdy = (x, y, z) -> -3; - final TrivariateFunction dfdz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return -4; - } - }; + final TrivariateFunction dfdz = (x, y, z) -> -4; - final TrivariateFunction zero = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 0; - } - }; + final TrivariateFunction zero = (x, y, z) -> 0; testInterpolation(-10, 3, 4.5, 6, @@ -550,61 +525,21 @@ public double value(double x, double y, double z) { */ @Test void testQuadric() { - final TrivariateFunction f = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 2 * x * x - 3 * y * y - 4 * z * z + 5 * x * y + 6 * x * z - 2 * y * z + 3; - } - }; + final TrivariateFunction f = (x, y, z) -> 2 * x * x - 3 * y * y - 4 * z * z + 5 * x * y + 6 * x * z - 2 * y * z + 3; - final TrivariateFunction dfdx = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 4 * x + 5 * y + 6 * z; - } - }; + final TrivariateFunction dfdx = (x, y, z) -> 4 * x + 5 * y + 6 * z; - final TrivariateFunction dfdy = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return -6 * y + 5 * x - 2 * z; - } - }; + final TrivariateFunction dfdy = (x, y, z) -> -6 * y + 5 * x - 2 * z; - final TrivariateFunction dfdz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return -8 * z + 6 * x - 2 * y; - } - }; + final TrivariateFunction dfdz = (x, y, z) -> -8 * z + 6 * x - 2 * y; - final TrivariateFunction d2fdxdy = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 5; - } - }; + final TrivariateFunction d2fdxdy = (x, y, z) -> 5; - final TrivariateFunction d2fdxdz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 6; - } - }; + final TrivariateFunction d2fdxdz = (x, y, z) -> 6; - final TrivariateFunction d2fdydz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return -2; - } - }; + final TrivariateFunction d2fdydz = (x, y, z) -> -2; - final TrivariateFunction d3fdxdydz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 0; - } - }; + final TrivariateFunction d3fdxdydz = (x, y, z) -> 0; testInterpolation(-10, 3, 4.5, 6, @@ -639,68 +574,23 @@ void testWave() { final double kx = 0.8; final double ky = 1; - final TrivariateFunction arg = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return omega * z - kx * x - ky * y; - } - }; + final TrivariateFunction arg = (x, y, z) -> omega * z - kx * x - ky * y; - final TrivariateFunction f = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return a * FastMath.cos(arg.value(x, y, z)); - } - }; + final TrivariateFunction f = (x, y, z) -> a * FastMath.cos(arg.value(x, y, z)); - final TrivariateFunction dfdx = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return kx * a * FastMath.sin(arg.value(x, y, z)); - } - }; + final TrivariateFunction dfdx = (x, y, z) -> kx * a * FastMath.sin(arg.value(x, y, z)); - final TrivariateFunction dfdy = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return ky * a * FastMath.sin(arg.value(x, y, z)); - } - }; + final TrivariateFunction dfdy = (x, y, z) -> ky * a * FastMath.sin(arg.value(x, y, z)); - final TrivariateFunction dfdz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return -omega * a * FastMath.sin(arg.value(x, y, z)); - } - }; + final TrivariateFunction dfdz = (x, y, z) -> -omega * a * FastMath.sin(arg.value(x, y, z)); - final TrivariateFunction d2fdxdy = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return -ky * kx * a * FastMath.cos(arg.value(x, y, z)); - } - }; + final TrivariateFunction d2fdxdy = (x, y, z) -> -ky * kx * a * FastMath.cos(arg.value(x, y, z)); - final TrivariateFunction d2fdxdz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return omega * kx * a * FastMath.cos(arg.value(x, y, z)); - } - }; + final TrivariateFunction d2fdxdz = (x, y, z) -> omega * kx * a * FastMath.cos(arg.value(x, y, z)); - final TrivariateFunction d2fdydz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return omega * ky * a * FastMath.cos(arg.value(x, y, z)); - } - }; + final TrivariateFunction d2fdydz = (x, y, z) -> omega * ky * a * FastMath.cos(arg.value(x, y, z)); - final TrivariateFunction d3fdxdydz = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return omega * ky * kx * a * FastMath.sin(arg.value(x, y, z)); - } - }; + final TrivariateFunction d3fdxdydz = (x, y, z) -> omega * ky * kx * a * FastMath.sin(arg.value(x, y, z)); testInterpolation(-10, 3, 4.5, 6, diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatorTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatorTest.java index 6a45754d2..0e80ed2f7 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/interpolation/TricubicInterpolatorTest.java @@ -131,12 +131,7 @@ void testPlane() { double[] zval = new double[] {-12, -8, -5.5, -3, 0, 2.5}; // Function values - TrivariateFunction f = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return 2 * x - 3 * y - 4 * z + 5; - } - }; + TrivariateFunction f = (x, y, z) -> 2 * x - 3 * y - 4 * z + 5; double[][][] fval = new double[xval.length][yval.length][zval.length]; @@ -189,12 +184,7 @@ void testWave() { final double ky = 1; // Function values - TrivariateFunction f = new TrivariateFunction() { - @Override - public double value(double x, double y, double z) { - return a * FastMath.cos(omega * z - kx * x - ky * y); - } - }; + TrivariateFunction f = (x, y, z) -> a * FastMath.cos(omega * z - kx * x - ky * y); double[][][] fval = new double[xval.length][yval.length][zval.length]; for (int i = 0; i < xval.length; i++) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/polynomials/PolynomialsUtilsTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/polynomials/PolynomialsUtilsTest.java index 63df4e611..3fef40bd6 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/polynomials/PolynomialsUtilsTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/polynomials/PolynomialsUtilsTest.java @@ -85,12 +85,7 @@ void testChebyshevDifferentials() { @Test void testChebyshevOrthogonality() { - UnivariateFunction weight = new UnivariateFunction() { - @Override - public double value(double x) { - return 1 / FastMath.sqrt(1 - x * x); - } - }; + UnivariateFunction weight = x -> 1 / FastMath.sqrt(1 - x * x); for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createChebyshevPolynomial(i); for (int j = 0; j <= i; ++j) { @@ -137,12 +132,7 @@ void testHermiteDifferentials() { @Test void testHermiteOrthogonality() { - UnivariateFunction weight = new UnivariateFunction() { - @Override - public double value(double x) { - return FastMath.exp(-x * x); - } - }; + UnivariateFunction weight = x -> FastMath.exp(-x * x); for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createHermitePolynomial(i); for (int j = 0; j <= i; ++j) { @@ -195,12 +185,7 @@ void testLaguerreDifferentials() { @Test void testLaguerreOrthogonality() { - UnivariateFunction weight = new UnivariateFunction() { - @Override - public double value(double x) { - return FastMath.exp(-x); - } - }; + UnivariateFunction weight = x -> FastMath.exp(-x); for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createLaguerrePolynomial(i); for (int j = 0; j <= i; ++j) { @@ -247,12 +232,7 @@ void testLegendreDifferentials() { @Test void testLegendreOrthogonality() { - UnivariateFunction weight = new UnivariateFunction() { - @Override - public double value(double x) { - return 1; - } - }; + UnivariateFunction weight = x -> 1; for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createLegendrePolynomial(i); for (int j = 0; j <= i; ++j) { @@ -313,12 +293,7 @@ void testJacobiOrthogonality() { for (int w = v; w < 5; ++w) { final int vv = v; final int ww = w; - UnivariateFunction weight = new UnivariateFunction() { - @Override - public double value(double x) { - return FastMath.pow(1 - x, vv) * FastMath.pow(1 + x, ww); - } - }; + UnivariateFunction weight = x -> FastMath.pow(1 - x, vv) * FastMath.pow(1 + x, ww); for (int i = 0; i < 10; ++i) { PolynomialFunction pi = PolynomialsUtils.createJacobiPolynomial(i, v, w); for (int j = 0; j <= i; ++j) { @@ -397,12 +372,7 @@ private void checkOrthogonality(final PolynomialFunction p1, final double a, final double b, final double nonZeroThreshold, final double zeroThreshold) { - UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - return weight.value(x) * p1.value(x) * p2.value(x); - } - }; + UnivariateFunction f = x -> weight.value(x) * p1.value(x) * p2.value(x); double dotProduct = new IterativeLegendreGaussIntegrator(5, 1.0e-9, 1.0e-8, 2, 15).integrate(1000000, f, a, b); if (p1.degree() == p2.degree()) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BisectionSolverTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BisectionSolverTest.java index 39674fb09..4a90c2a58 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BisectionSolverTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BisectionSolverTest.java @@ -99,9 +99,7 @@ void testMath369() { @Test void testHipparchusGithub40() { - assertThrows(MathIllegalArgumentException.class, () -> { - new BisectionSolver().solve(100, x -> Math.cos(x) + 2, 0.0, 5.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new BisectionSolver().solve(100, x -> Math.cos(x) + 2, 0.0, 5.0)); } } diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BracketingNthOrderBrentSolverTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BracketingNthOrderBrentSolverTest.java index 751cd150c..baf7efe7a 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BracketingNthOrderBrentSolverTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/BracketingNthOrderBrentSolverTest.java @@ -59,24 +59,17 @@ protected int[] getQuinticEvalCounts() { @Test void testInsufficientOrder1() { - assertThrows(MathIllegalArgumentException.class, () -> { - - new BracketingNthOrderBrentSolver(1.0e-10, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new BracketingNthOrderBrentSolver(1.0e-10, 1)); } @Test void testInsufficientOrder2() { - assertThrows(MathIllegalArgumentException.class, () -> { - new BracketingNthOrderBrentSolver(1.0e-10, 1.0e-10, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new BracketingNthOrderBrentSolver(1.0e-10, 1.0e-10, 1)); } @Test void testInsufficientOrder3() { - assertThrows(MathIllegalArgumentException.class, () -> { - new BracketingNthOrderBrentSolver(1.0e-10, 1.0e-10, 1.0e-10, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new BracketingNthOrderBrentSolver(1.0e-10, 1.0e-10, 1.0e-10, 1)); } @Test @@ -115,12 +108,7 @@ void testConvergenceOnFunctionAccuracy() { void testIssue716() { BracketingNthOrderBrentSolver solver = new BracketingNthOrderBrentSolver( 1.0e-12, 1.0e-10, 1.0e-22, 5); - UnivariateFunction sharpTurn = new UnivariateFunction() { - - public double value(double x) { - return (2 * x + 1) / (1.0e9 * (x + 1)); - } - }; + UnivariateFunction sharpTurn = x -> (2 * x + 1) / (1.0e9 * (x + 1)); double result = solver.solve(100, sharpTurn, -0.9999999, 30, 15, AllowedSolution.RIGHT_SIDE); assertEquals(0, sharpTurn.value(result), diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java index e8b54adaa..8a4eb1a13 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/FieldBracketingNthOrderBrentSolverTest.java @@ -46,12 +46,10 @@ final class FieldBracketingNthOrderBrentSolverTest { @Test void testInsufficientOrder3() { - assertThrows(MathIllegalArgumentException.class, () -> { - new FieldBracketingNthOrderBrentSolver(relativeAccuracy, - absoluteAccuracy, - functionValueAccuracy, - 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new FieldBracketingNthOrderBrentSolver(relativeAccuracy, + absoluteAccuracy, + functionValueAccuracy, + 1)); } @Test @@ -115,41 +113,17 @@ void testNeta() { // intern J. Computer Math Vol 23 pp 265-282 // available here: http://www.math.nps.navy.mil/~bneta/SeveralNewMethods.PDF for (AllowedSolution allowed : AllowedSolution.values()) { - check(new CalculusFieldUnivariateFunction() { - public Dfp value(Dfp x) { - return DfpMath.sin(x).subtract(x.half()); - } - }, 200, -2.0, 2.0, allowed); - - check(new CalculusFieldUnivariateFunction() { - public Dfp value(Dfp x) { - return DfpMath.pow(x, 5).add(x).subtract(field.newDfp(10000)); - } - }, 200, -5.0, 10.0, allowed); - - check(new CalculusFieldUnivariateFunction() { - public Dfp value(Dfp x) { - return x.sqrt().subtract(field.getOne().divide(x)).subtract(field.newDfp(3)); - } - }, 200, 0.001, 10.0, allowed); - - check(new CalculusFieldUnivariateFunction() { - public Dfp value(Dfp x) { - return DfpMath.exp(x).add(x).subtract(field.newDfp(20)); - } - }, 200, -5.0, 5.0, allowed); - - check(new CalculusFieldUnivariateFunction() { - public Dfp value(Dfp x) { - return DfpMath.log(x).add(x.sqrt()).subtract(field.newDfp(5)); - } - }, 200, 0.001, 10.0, allowed); - - check(new CalculusFieldUnivariateFunction() { - public Dfp value(Dfp x) { - return x.subtract(field.getOne()).multiply(x).multiply(x).subtract(field.getOne()); - } - }, 200, -0.5, 1.5, allowed); + check(x -> DfpMath.sin(x).subtract(x.half()), 200, -2.0, 2.0, allowed); + + check(x -> DfpMath.pow(x, 5).add(x).subtract(field.newDfp(10000)), 200, -5.0, 10.0, allowed); + + check(x -> x.sqrt().subtract(field.getOne().divide(x)).subtract(field.newDfp(3)), 200, 0.001, 10.0, allowed); + + check(x -> DfpMath.exp(x).add(x).subtract(field.newDfp(20)), 200, -5.0, 5.0, allowed); + + check(x -> DfpMath.log(x).add(x.sqrt()).subtract(field.newDfp(5)), 200, 0.001, 10.0, allowed); + + check(x -> x.subtract(field.getOne()).multiply(x).multiply(x).subtract(field.getOne()), 200, -0.5, 1.5, allowed); } } diff --git a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/UnivariateSolverUtilsTest.java b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/UnivariateSolverUtilsTest.java index e8cb352cc..905e9a0e2 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/UnivariateSolverUtilsTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/analysis/solvers/UnivariateSolverUtilsTest.java @@ -41,13 +41,11 @@ class UnivariateSolverUtilsTest { private UnivariateFunction sin = new Sin(); - private CalculusFieldUnivariateFunction fieldSin = x -> x.sin(); + private CalculusFieldUnivariateFunction fieldSin = Binary64::sin; @Test void testSolveNull() { - assertThrows(NullArgumentException.class, () -> { - UnivariateSolverUtils.solve(null, 0.0, 4.0); - }); + assertThrows(NullArgumentException.class, () -> UnivariateSolverUtils.solve(null, 0.0, 4.0)); } @Test @@ -92,9 +90,7 @@ void testSolveAccuracySin() { @Test void testSolveNoRoot() { - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.solve(sin, 1.0, 1.5); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.solve(sin, 1.0, 1.5)); } @Test @@ -137,22 +133,12 @@ void testBracketHigh(){ @Test void testBracketLinear(){ - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(new UnivariateFunction() { - public double value(double x) { - return 1 - x; - } - }, 1000, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 100); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(x -> 1 - x, 1000, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 100)); } @Test void testBracketExponential(){ - double[] result = UnivariateSolverUtils.bracket(new UnivariateFunction() { - public double value(double x) { - return 1 - x; - } - }, 1000, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0, 2.0, 10); + double[] result = UnivariateSolverUtils.bracket(x -> 1 - x, 1000, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1.0, 2.0, 10); assertTrue(result[0] <= 1); assertTrue(result[1] >= 1); } @@ -166,30 +152,22 @@ void testBracketEndpointRoot() { @Test void testNullFunction() { - assertThrows(NullArgumentException.class, () -> { - UnivariateSolverUtils.bracket(null, 1.5, 0, 2.0); - }); + assertThrows(NullArgumentException.class, () -> UnivariateSolverUtils.bracket(null, 1.5, 0, 2.0)); } @Test void testBadInitial() { - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(sin, 2.5, 0, 2.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(sin, 2.5, 0, 2.0)); } @Test void testBadAdditive() { - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(sin, 1.0, -2.0, 3.0, -1.0, 1.0, 100); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(sin, 1.0, -2.0, 3.0, -1.0, 1.0, 100)); } @Test void testIterationExceeded() { - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(sin, 1.0, -2.0, 3.0, 1.0e-5, 1.0, 100); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(sin, 1.0, -2.0, 3.0, 1.0e-5, 1.0, 100)); } @Test @@ -257,25 +235,15 @@ void testFieldBracketHigh(){ @Test void testFieldBracketLinear(){ - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(new CalculusFieldUnivariateFunction() { - public Binary64 value(Binary64 x) { - return x.negate().add(1); - } - }, - new Binary64(1000), - new Binary64(Double.NEGATIVE_INFINITY), new Binary64(Double.POSITIVE_INFINITY), - new Binary64(1.0), new Binary64(1.0), 100); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(x -> x.negate().add(1), + new Binary64(1000), + new Binary64(Double.NEGATIVE_INFINITY), new Binary64(Double.POSITIVE_INFINITY), + new Binary64(1.0), new Binary64(1.0), 100)); } @Test void testFieldBracketExponential(){ - Binary64[] result = UnivariateSolverUtils.bracket(new CalculusFieldUnivariateFunction() { - public Binary64 value(Binary64 x) { - return x.negate().add(1); - } - }, + Binary64[] result = UnivariateSolverUtils.bracket(x -> x.negate().add(1), new Binary64(1000), new Binary64(Double.NEGATIVE_INFINITY), new Binary64(Double.POSITIVE_INFINITY), new Binary64(1.0), new Binary64(2.0), 10); @@ -294,32 +262,24 @@ void testFieldBracketEndpointRoot() { @Test void testFieldNullFunction() { - assertThrows(NullArgumentException.class, () -> { - UnivariateSolverUtils.bracket(null, new Binary64(1.5), new Binary64(0), new Binary64(2.0)); - }); + assertThrows(NullArgumentException.class, () -> UnivariateSolverUtils.bracket(null, new Binary64(1.5), new Binary64(0), new Binary64(2.0))); } @Test void testFieldBadInitial() { - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(fieldSin, new Binary64(2.5), new Binary64(0), new Binary64(2.0)); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(fieldSin, new Binary64(2.5), new Binary64(0), new Binary64(2.0))); } @Test void testFieldBadAdditive() { - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(fieldSin, new Binary64(1.0), new Binary64(-2.0), new Binary64(3.0), - new Binary64(-1.0), new Binary64(1.0), 100); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(fieldSin, new Binary64(1.0), new Binary64(-2.0), new Binary64(3.0), + new Binary64(-1.0), new Binary64(1.0), 100)); } @Test void testFieldIterationExceeded() { - assertThrows(MathIllegalArgumentException.class, () -> { - UnivariateSolverUtils.bracket(fieldSin, new Binary64(1.0), new Binary64(-2.0), new Binary64(3.0), - new Binary64(1.0e-5), new Binary64(1.0), 100); - }); + assertThrows(MathIllegalArgumentException.class, () -> UnivariateSolverUtils.bracket(fieldSin, new Binary64(1.0), new Binary64(-2.0), new Binary64(3.0), + new Binary64(1.0e-5), new Binary64(1.0), 100)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexTest.java b/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexTest.java index 370dec029..548835803 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexTest.java @@ -543,16 +543,12 @@ void testEqualsNull() { @Test void testFloatingPointEqualsPrecondition1() { - assertThrows(NullPointerException.class, () -> { - Complex.equals(new Complex(3.0, 4.0), null, 3); - }); + assertThrows(NullPointerException.class, () -> Complex.equals(new Complex(3.0, 4.0), null, 3)); } @Test void testFloatingPointEqualsPrecondition2() { - assertThrows(NullPointerException.class, () -> { - Complex.equals(null, new Complex(3.0, 4.0), 3); - }); + assertThrows(NullPointerException.class, () -> Complex.equals(null, new Complex(3.0, 4.0), 3)); } @SuppressWarnings("unlikely-arg-type") @@ -1276,9 +1272,7 @@ void testScalarPowZero() { @Test void testpowNull() { - assertThrows(NullArgumentException.class, () -> { - Complex.ONE.pow(null); - }); + assertThrows(NullArgumentException.class, () -> Complex.ONE.pow(null)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexUtilsTest.java b/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexUtilsTest.java index 3bd2d468a..d2d185e17 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexUtilsTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/complex/ComplexUtilsTest.java @@ -81,9 +81,7 @@ protected Complex altPolar(double r, double theta) { @Test void testPolar2ComplexIllegalModulus() { - assertThrows(MathIllegalArgumentException.class, () -> { - ComplexUtils.polar2Complex(-1, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> ComplexUtils.polar2Complex(-1, 0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/complex/FieldComplexTest.java b/hipparchus-core/src/test/java/org/hipparchus/complex/FieldComplexTest.java index f9c0c0e97..7e4051115 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/complex/FieldComplexTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/complex/FieldComplexTest.java @@ -598,16 +598,12 @@ void testEqualsNull() { @Test void testFloatingPointEqualsPrecondition1() { - assertThrows(NullPointerException.class, () -> { - FieldComplex.equals(build(3.0, 4.0), null, 3); - }); + assertThrows(NullPointerException.class, () -> FieldComplex.equals(build(3.0, 4.0), null, 3)); } @Test void testFloatingPointEqualsPrecondition2() { - assertThrows(NullPointerException.class, () -> { - FieldComplex.equals(null, build(3.0, 4.0), 3); - }); + assertThrows(NullPointerException.class, () -> FieldComplex.equals(null, build(3.0, 4.0), 3)); } @SuppressWarnings("unlikely-arg-type") @@ -1363,9 +1359,7 @@ void testScalarPowZero() { @Test void testpowNull() { - assertThrows(NullArgumentException.class, () -> { - FieldComplex.getOne(Binary64Field.getInstance()).pow((FieldComplex) null); - }); + assertThrows(NullArgumentException.class, () -> FieldComplex.getOne(Binary64Field.getInstance()).pow((FieldComplex) null)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/complex/QuaternionTest.java b/hipparchus-core/src/test/java/org/hipparchus/complex/QuaternionTest.java index bd36db988..97e909b1c 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/complex/QuaternionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/complex/QuaternionTest.java @@ -91,9 +91,7 @@ final void testAccessors3() { @Test void testWrongDimension() { - assertThrows(MathIllegalArgumentException.class, () -> { - new Quaternion(new double[]{1, 2}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Quaternion(new double[]{1, 2})); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/dfp/DfpTest.java b/hipparchus-core/src/test/java/org/hipparchus/dfp/DfpTest.java index 4b5eae42b..7d6824d38 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/dfp/DfpTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/dfp/DfpTest.java @@ -1846,7 +1846,7 @@ void testRunTimeClass() { @Test public void testLinearCombinationReference() { final DfpField field25 = new DfpField(25); - doTestLinearCombinationReference(x -> field25.newDfp(x), 4.15e-9, 4.21e-9); + doTestLinearCombinationReference(field25::newDfp, 4.15e-9, 4.21e-9); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ExponentialDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ExponentialDistributionTest.java index c5fd68ff4..58bc61298 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ExponentialDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ExponentialDistributionTest.java @@ -122,9 +122,7 @@ void testMeanAccessors() { @Test void testPreconditions() { - assertThrows(MathIllegalArgumentException.class, () -> { - new ExponentialDistribution(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new ExponentialDistribution(0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/LogNormalDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/LogNormalDistributionTest.java index ef9199d03..a57329183 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/LogNormalDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/LogNormalDistributionTest.java @@ -182,9 +182,7 @@ void testGetShape() { @Test void testPreconditions() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LogNormalDistribution(1, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LogNormalDistribution(1, 0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/NormalDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/NormalDistributionTest.java index 56ca639c4..f1c966e03 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/NormalDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/NormalDistributionTest.java @@ -144,9 +144,7 @@ void testGetStandardDeviation() { @Test void testPreconditions() { - assertThrows(MathIllegalArgumentException.class, () -> { - new NormalDistribution(1, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new NormalDistribution(1, 0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ParetoDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ParetoDistributionTest.java index 3277390c6..969386822 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ParetoDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/ParetoDistributionTest.java @@ -153,9 +153,7 @@ void testGetShape() { @Test void testPreconditions() { - assertThrows(MathIllegalArgumentException.class, () -> { - new ParetoDistribution(1, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new ParetoDistribution(1, 0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/RealDistributionAbstractTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/RealDistributionAbstractTest.java index b0b1160f1..27980f490 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/RealDistributionAbstractTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/RealDistributionAbstractTest.java @@ -334,11 +334,7 @@ public void testDensityIntegrals() { final double tol = 1.0e-9; final BaseAbstractUnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(5, 1.0e-12, 1.0e-10); - final UnivariateFunction d = new UnivariateFunction() { - public double value(double x) { - return distribution.density(x); - } - }; + final UnivariateFunction d = x -> distribution.density(x); final ArrayList integrationTestPoints = new ArrayList(); for (int i = 0; i < cumulativeTestPoints.length; i++) { if (Double.isNaN(cumulativeTestValues[i]) || diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TDistributionTest.java index 293da940c..a32914523 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TDistributionTest.java @@ -129,9 +129,7 @@ void testDfAccessors() { @Test void testPreconditions() { - assertThrows(MathIllegalArgumentException.class, () -> { - new TDistribution(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new TDistribution(0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TriangularDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TriangularDistributionTest.java index ddb2882c4..78ca0e173 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TriangularDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/TriangularDistributionTest.java @@ -159,33 +159,25 @@ void testGetUpperBound() { /** Test pre-condition for equal lower/upper limit. */ @Test void testPreconditions1() { - assertThrows(MathIllegalArgumentException.class, () -> { - new TriangularDistribution(0, 0, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new TriangularDistribution(0, 0, 0)); } /** Test pre-condition for lower limit larger than upper limit. */ @Test void testPreconditions2() { - assertThrows(MathIllegalArgumentException.class, () -> { - new TriangularDistribution(1, 1, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new TriangularDistribution(1, 1, 0)); } /** Test pre-condition for mode larger than upper limit. */ @Test void testPreconditions3() { - assertThrows(MathIllegalArgumentException.class, () -> { - new TriangularDistribution(0, 2, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new TriangularDistribution(0, 2, 1)); } /** Test pre-condition for mode smaller than lower limit. */ @Test void testPreconditions4() { - assertThrows(MathIllegalArgumentException.class, () -> { - new TriangularDistribution(2, 1, 3); - }); + assertThrows(MathIllegalArgumentException.class, () -> new TriangularDistribution(2, 1, 3)); } /** Test mean/variance. */ diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/UniformRealDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/UniformRealDistributionTest.java index 5382e64c8..25b0092c8 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/UniformRealDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/continuous/UniformRealDistributionTest.java @@ -92,17 +92,13 @@ void testGetUpperBound() { /** Test pre-condition for equal lower/upper bound. */ @Test void testPreconditions1() { - assertThrows(MathIllegalArgumentException.class, () -> { - new UniformRealDistribution(0, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new UniformRealDistribution(0, 0)); } /** Test pre-condition for lower bound larger than upper bound. */ @Test void testPreconditions2() { - assertThrows(MathIllegalArgumentException.class, () -> { - new UniformRealDistribution(1, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new UniformRealDistribution(1, 0)); } /** Test mean/variance. */ diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/PoissonDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/PoissonDistributionTest.java index fa287713e..71be696ec 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/PoissonDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/PoissonDistributionTest.java @@ -157,9 +157,7 @@ void testDegenerateInverseCumulativeProbability() { @Test void testNegativeMean() { - assertThrows(MathIllegalArgumentException.class, () -> { - new PoissonDistribution(-1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new PoissonDistribution(-1)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/ZipfDistributionTest.java b/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/ZipfDistributionTest.java index 44a381b68..43f8142dc 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/ZipfDistributionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/distribution/discrete/ZipfDistributionTest.java @@ -44,16 +44,12 @@ public ZipfDistributionTest() { @Test void testPreconditions1() { - assertThrows(MathIllegalArgumentException.class, () -> { - new ZipfDistribution(0, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new ZipfDistribution(0, 1)); } @Test void testPreconditions2() { - assertThrows(MathIllegalArgumentException.class, () -> { - new ZipfDistribution(1, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new ZipfDistribution(1, 0)); } //-------------- Implementations for abstract methods ----------------------- diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/CholeskyDecompositionTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/CholeskyDecompositionTest.java index 7e70e8392..e68142596 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/CholeskyDecompositionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/CholeskyDecompositionTest.java @@ -55,9 +55,7 @@ void testDimensions() { /** test non-square matrix */ @Test void testNonSquare() { - assertThrows(MathIllegalArgumentException.class, () -> { - new CholeskyDecomposition(MatrixUtils.createRealMatrix(new double[3][2])); - }); + assertThrows(MathIllegalArgumentException.class, () -> new CholeskyDecomposition(MatrixUtils.createRealMatrix(new double[3][2]))); } /** test non-symmetric matrix */ @@ -73,15 +71,13 @@ void testNotSymmetricMatrixException() { /** test non positive definite matrix */ @Test void testNotPositiveDefinite() { - assertThrows(MathIllegalArgumentException.class, () -> { - new CholeskyDecomposition(MatrixUtils.createRealMatrix(new double[][]{ - {14, 11, 13, 15, 24}, - {11, 34, 13, 8, 25}, - {13, 13, 14, 15, 21}, - {15, 8, 15, 18, 23}, - {24, 25, 21, 23, 45} - })); - }); + assertThrows(MathIllegalArgumentException.class, () -> new CholeskyDecomposition(MatrixUtils.createRealMatrix(new double[][]{ + {14, 11, 13, 15, 24}, + {11, 34, 13, 8, 25}, + {13, 13, 14, 15, 21}, + {15, 8, 15, 18, 23}, + {24, 25, 21, 23, 45} + }))); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/DiagonalMatrixTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/DiagonalMatrixTest.java index 23d360898..2e898a564 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/DiagonalMatrixTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/DiagonalMatrixTest.java @@ -445,9 +445,7 @@ void testSetEntryOutOfRange() { @Test void testNull() { - assertThrows(NullArgumentException.class, () -> { - new DiagonalMatrix(null, false); - }); + assertThrows(NullArgumentException.class, () -> new DiagonalMatrix(null, false)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/FieldLUDecompositionTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/FieldLUDecompositionTest.java index 3f9679b63..fec6e03de 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/FieldLUDecompositionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/FieldLUDecompositionTest.java @@ -24,6 +24,7 @@ import org.hipparchus.CalculusFieldElement; import org.hipparchus.Field; +import org.hipparchus.FieldElement; import org.hipparchus.UnitTestUtils; import org.hipparchus.complex.Complex; import org.hipparchus.exception.LocalizedCoreFormats; @@ -349,7 +350,7 @@ void testSignedZeroPivot() { @Test void testSolve() { FieldDecompositionSolver solver = - new FieldLUDecomposer(e -> e.isZero()). + new FieldLUDecomposer(FieldElement::isZero). decompose(new Array2DRowFieldMatrix(FractionField.getInstance(), testData)); FieldVector solution = solver.solve(new ArrayFieldVector<>(new Fraction[] { @@ -423,7 +424,7 @@ private > void doTestComparisonWithReal(final void testIssue134() { FieldMatrix matrix = new Array2DRowFieldMatrix(FractionField.getInstance(), testData); - FieldLUDecomposition lu = new FieldLUDecomposition(matrix, e -> e.isZero(), false); + FieldLUDecomposition lu = new FieldLUDecomposition(matrix, FieldElement::isZero, false); // L final FieldMatrix l = lu.getL(); diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/FieldMatrixTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/FieldMatrixTest.java index 1a4f54e14..534df800f 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/FieldMatrixTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/FieldMatrixTest.java @@ -60,7 +60,7 @@ void testDefaultTransposeMultiply() { @Test void testDefaultMap() { FieldMatrix a = createMatrix(new double[][] { {1d,2d,3d}, {2d,5d,3d}, {1d,0d,8d} }); - FieldMatrix result = a.add(a.map(x -> x.negate())); + FieldMatrix result = a.add(a.map(Binary64::negate)); result.walkInOptimizedOrder(new FieldMatrixPreservingVisitor() { @Override diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/OpenMapRealMatrixTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/OpenMapRealMatrixTest.java index 867915061..e452c2085 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/OpenMapRealMatrixTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/OpenMapRealMatrixTest.java @@ -31,9 +31,7 @@ final class OpenMapRealMatrixTest { @Test void testMath679() { - assertThrows(MathIllegalArgumentException.class, () -> { - new OpenMapRealMatrix(3, Integer.MAX_VALUE); - }); + assertThrows(MathIllegalArgumentException.class, () -> new OpenMapRealMatrix(3, Integer.MAX_VALUE)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorAbstractTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorAbstractTest.java index 83d5a3334..2b8639227 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorAbstractTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorAbstractTest.java @@ -212,16 +212,12 @@ public void testGetEntry() { @Test public void testGetEntryInvalidIndex1() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[4]).getEntry(-1); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[4]).getEntry(-1)); } @Test public void testGetEntryInvalidIndex2() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[4]).getEntry(4); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[4]).getEntry(4)); } @Test @@ -262,16 +258,12 @@ public void testSetEntry() { @Test public void testSetEntryInvalidIndex1() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[4]).setEntry(-1, getPreferredEntryValue()); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[4]).setEntry(-1, getPreferredEntryValue())); } @Test public void testSetEntryInvalidIndex2() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[4]).setEntry(4, getPreferredEntryValue()); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[4]).setEntry(4, getPreferredEntryValue())); } @Test @@ -313,16 +305,12 @@ public void testAddToEntry() { @Test public void testAddToEntryInvalidIndex1() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[3]).addToEntry(-1, getPreferredEntryValue()); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[3]).addToEntry(-1, getPreferredEntryValue())); } @Test public void testAddToEntryInvalidIndex2() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[3]).addToEntry(4, getPreferredEntryValue()); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[3]).addToEntry(4, getPreferredEntryValue())); } private void doTestAppendVector(final String message, final RealVector v1, @@ -451,23 +439,17 @@ public void testSetSubVectorMixedType() { @Test public void testSetSubVectorInvalidIndex1() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[10]).setSubVector(-1, create(new double[2])); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[10]).setSubVector(-1, create(new double[2]))); } @Test public void testSetSubVectorInvalidIndex2() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[10]).setSubVector(10, create(new double[2])); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[10]).setSubVector(10, create(new double[2]))); } @Test public void testSetSubVectorInvalidIndex3() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[10]).setSubVector(9, create(new double[2])); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[10]).setSubVector(9, create(new double[2]))); } @Test @@ -580,9 +562,7 @@ public void testAddMixedTypes() { @Test public void testAddDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.ADD); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.ADD)); } @Test @@ -597,9 +577,7 @@ public void testSubtractMixedTypes() { @Test public void testSubtractDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.SUB); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.SUB)); } @Test @@ -614,9 +592,7 @@ public void testEbeMultiplyMixedTypes() { @Test public void testEbeMultiplyDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.MUL); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.MUL)); } @Test @@ -631,9 +607,7 @@ public void testEbeDivideMixedTypes() { @Test public void testEbeDivideDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.DIV); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.DIV)); } private void doTestGetDistance(final boolean mixed) { @@ -669,9 +643,7 @@ public void testGetDistanceMixedTypes() { @Test public void testGetDistanceDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[4]).getDistance(createAlien(new double[5])); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[4]).getDistance(createAlien(new double[5]))); } @Test @@ -720,9 +692,7 @@ public void testGetL1DistanceMixedTypes() { @Test public void testGetL1DistanceDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[4]).getL1Distance(createAlien(new double[5])); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[4]).getL1Distance(createAlien(new double[5]))); } @Test @@ -771,9 +741,7 @@ public void testGetLInfDistanceMixedTypes() { @Test public void testGetLInfDistanceDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - create(new double[4]).getLInfDistance(createAlien(new double[5])); - }); + assertThrows(MathIllegalArgumentException.class, () -> create(new double[4]).getLInfDistance(createAlien(new double[5]))); } @Test @@ -1024,9 +992,7 @@ public void testProjectionMixedTypes() { @Test public void testProjectionNullVector() { - assertThrows(MathRuntimeException.class, () -> { - create(new double[4]).projection(create(new double[4])); - }); + assertThrows(MathRuntimeException.class, () -> create(new double[4]).projection(create(new double[4]))); } @Test @@ -1109,16 +1075,12 @@ private void doTestUnitVectorNullVector(final boolean inPlace) { @Test public void testUnitVectorNullVector() { - assertThrows(MathRuntimeException.class, () -> { - doTestUnitVectorNullVector(false); - }); + assertThrows(MathRuntimeException.class, () -> doTestUnitVectorNullVector(false)); } @Test public void testUnitizeNullVector() { - assertThrows(MathRuntimeException.class, () -> { - doTestUnitVectorNullVector(true); - }); + assertThrows(MathRuntimeException.class, () -> doTestUnitVectorNullVector(true)); } @Test @@ -1208,16 +1170,12 @@ public void testCombineMixedTypes() { @Test public void testCombineDimensionMismatchSameType() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestCombineDimensionMismatch(false, false); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestCombineDimensionMismatch(false, false)); } @Test public void testCombineDimensionMismatchMixedTypes() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestCombineDimensionMismatch(false, true); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestCombineDimensionMismatch(false, true)); } @Test @@ -1232,16 +1190,12 @@ public void testCombineToSelfMixedTypes() { @Test public void testCombineToSelfDimensionMismatchSameType() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestCombineDimensionMismatch(true, false); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestCombineDimensionMismatch(true, false)); } @Test public void testCombineToSelfDimensionMismatchMixedTypes() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestCombineDimensionMismatch(true, true); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestCombineDimensionMismatch(true, true)); } @Test @@ -1320,9 +1274,7 @@ public void testDotProductSameType() { @Test public void testDotProductDimensionMismatchSameType() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestDotProductDimensionMismatch(false); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestDotProductDimensionMismatch(false)); } @Test @@ -1333,9 +1285,7 @@ public void testDotProductMixedTypes() { @Test public void testDotProductDimensionMismatchMixedTypes() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestDotProductDimensionMismatch(true); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestDotProductDimensionMismatch(true)); } private void doTestCosine(final boolean mixed) { diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorTest.java index 3f06dd255..badb5fd1f 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/RealVectorTest.java @@ -46,19 +46,19 @@ public RealVector create(final double[] data) { @Test @Override public void testAppendVector() { - checkUnsupported(() -> super.testAppendVector()); + checkUnsupported(super::testAppendVector); } @Test @Override public void testAppendScalar() { - checkUnsupported(() -> super.testAppendScalar()); + checkUnsupported(super::testAppendScalar); } @Test @Override public void testGetSubVector() { - checkUnsupported(() -> super.testGetSubVector()); + checkUnsupported(super::testGetSubVector); } @Test @@ -100,89 +100,79 @@ public void testGetSubVectorInvalidIndex4() { @Test @Override public void testSetSubVectorSameType() { - checkUnsupported(() -> super.testSetSubVectorSameType()); + checkUnsupported(super::testSetSubVectorSameType); } @Test @Override public void testSetSubVectorMixedType() { - checkUnsupported(() -> super.testSetSubVectorMixedType()); + checkUnsupported(super::testSetSubVectorMixedType); } @Test @Override public void testSetSubVectorInvalidIndex1() { - assertThrows(UnsupportedOperationException.class, () -> { - create(new double[10]).setSubVector(-1, create(new double[2])); - }); + assertThrows(UnsupportedOperationException.class, () -> create(new double[10]).setSubVector(-1, create(new double[2]))); } @Test @Override public void testSetSubVectorInvalidIndex2() { - assertThrows(UnsupportedOperationException.class, () -> { - create(new double[10]).setSubVector(10, create(new double[2])); - }); + assertThrows(UnsupportedOperationException.class, () -> create(new double[10]).setSubVector(10, create(new double[2]))); } @Test @Override public void testSetSubVectorInvalidIndex3() { - assertThrows(UnsupportedOperationException.class, () -> { - create(new double[10]).setSubVector(9, create(new double[2])); - }); + assertThrows(UnsupportedOperationException.class, () -> create(new double[10]).setSubVector(9, create(new double[2]))); } @Test @Override public void testIsNaN() { - checkUnsupported(() -> super.testIsNaN()); + checkUnsupported(super::testIsNaN); } @Test @Override public void testIsInfinite() { - checkUnsupported(() -> super.testIsInfinite()); + checkUnsupported(super::testIsInfinite); } @Test @Override public void testEbeMultiplySameType() { - checkUnsupported(() -> super.testEbeMultiplySameType()); + checkUnsupported(super::testEbeMultiplySameType); } @Test @Override public void testEbeMultiplyMixedTypes() { - checkUnsupported(() -> super.testEbeMultiplyMixedTypes()); + checkUnsupported(super::testEbeMultiplyMixedTypes); } @Test @Override public void testEbeMultiplyDimensionMismatch() { - assertThrows(UnsupportedOperationException.class, () -> { - doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.MUL); - }); + assertThrows(UnsupportedOperationException.class, () -> doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.MUL)); } @Test @Override public void testEbeDivideSameType() { - checkUnsupported(() -> super.testEbeDivideSameType()); + checkUnsupported(super::testEbeDivideSameType); } @Test @Override public void testEbeDivideMixedTypes() { - checkUnsupported(() -> super.testEbeDivideMixedTypes()); + checkUnsupported(super::testEbeDivideMixedTypes); } @Test @Override public void testEbeDivideDimensionMismatch() { - assertThrows(UnsupportedOperationException.class, () -> { - doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.DIV); - }); + assertThrows(UnsupportedOperationException.class, () -> doTestEbeBinaryOperationDimensionMismatch(BinaryOperation.DIV)); } @Test @@ -217,13 +207,13 @@ void testSparseIterator() { @Test @Override public void testSerial() { - checkUnsupported(() -> super.testSerial()); + checkUnsupported(super::testSerial); } @Test @Override public void testEquals() { - checkUnsupported(() -> super.testEquals()); + checkUnsupported(super::testEquals); } interface Thunk { diff --git a/hipparchus-core/src/test/java/org/hipparchus/linear/SemiDefinitePositiveCholeskyDecompositionTest.java b/hipparchus-core/src/test/java/org/hipparchus/linear/SemiDefinitePositiveCholeskyDecompositionTest.java index 74523eabf..dc979c850 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/linear/SemiDefinitePositiveCholeskyDecompositionTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/linear/SemiDefinitePositiveCholeskyDecompositionTest.java @@ -47,23 +47,19 @@ void testDimensions() { /** test non-square matrix */ @Test void testNonSquare() { - assertThrows(MathIllegalArgumentException.class, () -> { - new SemiDefinitePositiveCholeskyDecomposition(MatrixUtils.createRealMatrix(new double[3][2])); - }); + assertThrows(MathIllegalArgumentException.class, () -> new SemiDefinitePositiveCholeskyDecomposition(MatrixUtils.createRealMatrix(new double[3][2]))); } /** test negative definite matrix */ @Test void testNotPositiveDefinite() { - assertThrows(MathIllegalArgumentException.class, () -> { - new SemiDefinitePositiveCholeskyDecomposition(MatrixUtils.createRealMatrix(new double[][]{ - {-14, 11, 13, 15, 24}, - {11, 34, 13, 8, 25}, - {-13, 13, 14, 15, 21}, - {15, 8, -15, 18, 23}, - {24, 25, 21, 23, -45} - })); - }); + assertThrows(MathIllegalArgumentException.class, () -> new SemiDefinitePositiveCholeskyDecomposition(MatrixUtils.createRealMatrix(new double[][]{ + {-14, 11, 13, 15, 24}, + {11, 34, 13, 8, 25}, + {-13, 13, 14, 15, 21}, + {15, 8, -15, 18, 23}, + {24, 25, 21, 23, -45} + }))); } /** test A = LLT */ diff --git a/hipparchus-core/src/test/java/org/hipparchus/random/RandomGeneratorAbstractTest.java b/hipparchus-core/src/test/java/org/hipparchus/random/RandomGeneratorAbstractTest.java index 6685f31dc..a3548098c 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/random/RandomGeneratorAbstractTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/random/RandomGeneratorAbstractTest.java @@ -235,16 +235,12 @@ public void testNextDouble() { @Test public void testNextIntPrecondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - generator.nextInt(-1); - }); + assertThrows(MathIllegalArgumentException.class, () -> generator.nextInt(-1)); } @Test public void testNextIntPrecondition2() { - assertThrows(MathIllegalArgumentException.class, () -> { - generator.nextInt(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> generator.nextInt(0)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/random/SynchronizedRandomGeneratorTest.java b/hipparchus-core/src/test/java/org/hipparchus/random/SynchronizedRandomGeneratorTest.java index 5c6c53e63..1853a053d 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/random/SynchronizedRandomGeneratorTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/random/SynchronizedRandomGeneratorTest.java @@ -102,16 +102,13 @@ private double[] doTestMath899(final boolean sync, final List> tasks = new ArrayList>(); for (int i = 0; i < numGenerators; i++) { - tasks.add(new Callable() { - @Override - public Double call() { - Double lastValue = 0d; - for (int j = 0; j < numSamples; j++) { - lastValue = wrapper.nextGaussian(); - } - return lastValue; - } - }); + tasks.add(() -> { + Double lastValue = 0d; + for (int j = 0; j < numSamples; j++) { + lastValue = wrapper.nextGaussian(); + } + return lastValue; + }); } final ExecutorService exec = Executors.newFixedThreadPool(numThreads); diff --git a/hipparchus-core/src/test/java/org/hipparchus/special/BesselJTest.java b/hipparchus-core/src/test/java/org/hipparchus/special/BesselJTest.java index ee02b3f80..38bf19e67 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/special/BesselJTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/special/BesselJTest.java @@ -773,15 +773,11 @@ void testBesselJ() { @Test void testIAEBadOrder() { - assertThrows(MathIllegalArgumentException.class, () -> { - BesselJ.value(-1, 1); - }); + assertThrows(MathIllegalArgumentException.class, () -> BesselJ.value(-1, 1)); } @Test void testIAEBadArgument() { - assertThrows(MathIllegalArgumentException.class, () -> { - BesselJ.value(1, 100000); - }); + assertThrows(MathIllegalArgumentException.class, () -> BesselJ.value(1, 100000)); } } diff --git a/hipparchus-core/src/test/java/org/hipparchus/special/BetaTest.java b/hipparchus-core/src/test/java/org/hipparchus/special/BetaTest.java index e716e3d21..4b828c0a5 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/special/BetaTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/special/BetaTest.java @@ -53,23 +53,17 @@ class BetaTest { final Class d = Double.TYPE; b = Beta.class; AtomicReference m = new AtomicReference<>(); - assertDoesNotThrow(() -> { - m.set(b.getDeclaredMethod("logGammaSum", d, d)); - }); + assertDoesNotThrow(() -> m.set(b.getDeclaredMethod("logGammaSum", d, d))); LOG_GAMMA_SUM_METHOD = m.get(); LOG_GAMMA_SUM_METHOD.setAccessible(true); m.set(null); - assertDoesNotThrow(() -> { - m.set(b.getDeclaredMethod("logGammaMinusLogGammaSum", d, d)); - }); + assertDoesNotThrow(() -> m.set(b.getDeclaredMethod("logGammaMinusLogGammaSum", d, d))); LOG_GAMMA_MINUS_LOG_GAMMA_SUM_METHOD = m.get(); LOG_GAMMA_MINUS_LOG_GAMMA_SUM_METHOD.setAccessible(true); m.set(null); - assertDoesNotThrow(() -> { - m.set(b.getDeclaredMethod("sumDeltaMinusDeltaSum", d, d)); - }); + assertDoesNotThrow(() -> m.set(b.getDeclaredMethod("sumDeltaMinusDeltaSum", d, d))); SUM_DELTA_MINUS_DELTA_SUM_METHOD = m.get(); SUM_DELTA_MINUS_DELTA_SUM_METHOD.setAccessible(true); } @@ -300,9 +294,7 @@ private static double logGammaSum(final double a, final double b) { */ try { return ((Double) LOG_GAMMA_SUM_METHOD.invoke(null, a, b)).doubleValue(); - } catch (final IllegalAccessException e) { - fail(e.getMessage()); - } catch (final IllegalArgumentException e) { + } catch (final IllegalAccessException | IllegalArgumentException e) { fail(e.getMessage()); } catch (final InvocationTargetException e) { final Throwable te = e.getTargetException(); @@ -332,34 +324,22 @@ void testLogGammaSum() { @Test void testLogGammaSumPrecondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - - logGammaSum(0.0, 1.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> logGammaSum(0.0, 1.0)); } @Test void testLogGammaSumPrecondition2() { - assertThrows(MathIllegalArgumentException.class, () -> { - - logGammaSum(3.0, 1.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> logGammaSum(3.0, 1.0)); } @Test void testLogGammaSumPrecondition3() { - assertThrows(MathIllegalArgumentException.class, () -> { - - logGammaSum(1.0, 0.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> logGammaSum(1.0, 0.0)); } @Test void testLogGammaSumPrecondition4() { - assertThrows(MathIllegalArgumentException.class, () -> { - - logGammaSum(1.0, 3.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> logGammaSum(1.0, 3.0)); } private static final double[][] LOG_GAMMA_MINUS_LOG_GAMMA_SUM_REF = { @@ -494,9 +474,7 @@ private static double logGammaMinusLogGammaSum(final double a, final double b) { try { final Method m = LOG_GAMMA_MINUS_LOG_GAMMA_SUM_METHOD; return ((Double) m.invoke(null, a, b)).doubleValue(); - } catch (final IllegalAccessException e) { - fail(e.getMessage()); - } catch (final IllegalArgumentException e) { + } catch (final IllegalAccessException | IllegalArgumentException e) { fail(e.getMessage()); } catch (final InvocationTargetException e) { final Throwable te = e.getTargetException(); @@ -526,16 +504,12 @@ void testLogGammaMinusLogGammaSum() { @Test void testLogGammaMinusLogGammaSumPrecondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - logGammaMinusLogGammaSum(-1.0, 8.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> logGammaMinusLogGammaSum(-1.0, 8.0)); } @Test void testLogGammaMinusLogGammaSumPrecondition2() { - assertThrows(MathIllegalArgumentException.class, () -> { - logGammaMinusLogGammaSum(1.0, 7.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> logGammaMinusLogGammaSum(1.0, 7.0)); } private static final double[][] SUM_DELTA_MINUS_DELTA_SUM_REF = { @@ -671,9 +645,7 @@ private static double sumDeltaMinusDeltaSum(final double a, try { final Method m = SUM_DELTA_MINUS_DELTA_SUM_METHOD; return ((Double) m.invoke(null, a, b)).doubleValue(); - } catch (final IllegalAccessException e) { - fail(e.getMessage()); - } catch (final IllegalArgumentException e) { + } catch (final IllegalAccessException | IllegalArgumentException e) { fail(e.getMessage()); } catch (final InvocationTargetException e) { final Throwable te = e.getTargetException(); @@ -704,18 +676,12 @@ void testSumDeltaMinusDeltaSum() { @Test void testSumDeltaMinusDeltaSumPrecondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - - sumDeltaMinusDeltaSum(9.0, 10.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> sumDeltaMinusDeltaSum(9.0, 10.0)); } @Test void testSumDeltaMinusDeltaSumPrecondition2() { - assertThrows(MathIllegalArgumentException.class, () -> { - - sumDeltaMinusDeltaSum(10.0, 9.0); - }); + assertThrows(MathIllegalArgumentException.class, () -> sumDeltaMinusDeltaSum(10.0, 9.0)); } private static final double[][] LOG_BETA_REF = { diff --git a/hipparchus-core/src/test/java/org/hipparchus/special/GammaTest.java b/hipparchus-core/src/test/java/org/hipparchus/special/GammaTest.java index 4a2fd18d0..0abb3d9ab 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/special/GammaTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/special/GammaTest.java @@ -153,16 +153,12 @@ void testRegularizedGammaPositivePositiveField() { @Test void testRegularizedGammaPMaxNumberOfIterationsExceeded(){ - assertThrows(MathIllegalStateException.class, () -> { - testRegularizedGamma(0.632120558828558, 1.0, 1.0, 1e-15, 1); - }); + assertThrows(MathIllegalStateException.class, () -> testRegularizedGamma(0.632120558828558, 1.0, 1.0, 1e-15, 1)); } @Test void testRegularizedGammaPMaxNumberOfIterationsExceededField(){ - assertThrows(MathIllegalStateException.class, () -> { - testRegularizedGammaField(0.632120558828558, one, one, 1e-15, 1); - }); + assertThrows(MathIllegalStateException.class, () -> testRegularizedGammaField(0.632120558828558, one, one, 1e-15, 1)); } @Test @@ -661,34 +657,22 @@ void testInvGamma1pm1Field() { @Test void testInvGamma1pm1Precondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.invGamma1pm1(-0.51); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.invGamma1pm1(-0.51)); } @Test void testInvGamma1pm1Precondition2() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.invGamma1pm1(1.51); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.invGamma1pm1(1.51)); } @Test void testInvGamma1pm1Precondition1Field() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.invGamma1pm1(new Binary64(-0.51)); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.invGamma1pm1(new Binary64(-0.51))); } @Test void testInvGamma1pm1Precondition2Field() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.invGamma1pm1(new Binary64(1.51)); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.invGamma1pm1(new Binary64(1.51))); } private static final double[][] LOG_GAMMA1P_REF = { @@ -741,34 +725,22 @@ void testLogGamma1pField() { @Test void testLogGamma1pPrecondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.logGamma1p(-0.51); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.logGamma1p(-0.51)); } @Test void testLogGamma1pPrecondition1Field() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.logGamma1p(new Binary64(-0.51)); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.logGamma1p(new Binary64(-0.51))); } @Test void testLogGamma1pPrecondition2() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.logGamma1p(1.51); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.logGamma1p(1.51)); } @Test void testLogGamma1pPrecondition2Field() { - assertThrows(MathIllegalArgumentException.class, () -> { - - Gamma.logGamma1p(new Binary64(1.51)); - }); + assertThrows(MathIllegalArgumentException.class, () -> Gamma.logGamma1p(new Binary64(1.51))); } /** diff --git a/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/FieldJacobiEllipticTest.java b/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/FieldJacobiEllipticTest.java index 725660e03..e3f14e60e 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/FieldJacobiEllipticTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/FieldJacobiEllipticTest.java @@ -271,37 +271,37 @@ private > FieldJacobiElliptic build(final F private > void doTestInverseCopolarN(final Field field) { final double m = 0.7; final FieldJacobiElliptic je = build(field, m); - doTestInverse(-0.80, 0.80, 100, field, u -> je.valuesN(u).sn(), x -> je.arcsn(x), x -> je.arcsn(x), 1.0e-14); - doTestInverse(-1.00, 1.00, 100, field, u -> je.valuesN(u).cn(), x -> je.arccn(x), x -> je.arccn(x), 1.0e-14); - doTestInverse( 0.55, 1.00, 100, field, u -> je.valuesN(u).dn(), x -> je.arcdn(x), x -> je.arcdn(x), 1.0e-14); + doTestInverse(-0.80, 0.80, 100, field, u -> je.valuesN(u).sn(), je::arcsn, je::arcsn, 1.0e-14); + doTestInverse(-1.00, 1.00, 100, field, u -> je.valuesN(u).cn(), je::arccn, je::arccn, 1.0e-14); + doTestInverse( 0.55, 1.00, 100, field, u -> je.valuesN(u).dn(), je::arcdn, je::arcdn, 1.0e-14); } private > void doTestInverseCopolarS(final Field field) { final double m = 0.7; final FieldJacobiElliptic je = build(field, m); - doTestInverse(-2.00, 2.00, 100, field, u -> je.valuesS(u).cs(), x -> je.arccs(x), x -> je.arccs(x), 1.0e-14); - doTestInverse( 0.55, 2.00, 100, field, u -> je.valuesS(u).ds(), x -> je.arcds(x), x -> je.arcds(x), 1.0e-14); - doTestInverse(-2.00, -0.55, 100, field, u -> je.valuesS(u).ds(), x -> je.arcds(x), x -> je.arcds(x), 1.0e-14); - doTestInverse( 1.00, 2.00, 100, field, u -> je.valuesS(u).ns(), x -> je.arcns(x), x -> je.arcns(x), 1.0e-11); - doTestInverse(-2.00, -1.00, 100, field, u -> je.valuesS(u).ns(), x -> je.arcns(x), x -> je.arcns(x), 1.0e-11); + doTestInverse(-2.00, 2.00, 100, field, u -> je.valuesS(u).cs(), je::arccs, je::arccs, 1.0e-14); + doTestInverse( 0.55, 2.00, 100, field, u -> je.valuesS(u).ds(), je::arcds, je::arcds, 1.0e-14); + doTestInverse(-2.00, -0.55, 100, field, u -> je.valuesS(u).ds(), je::arcds, je::arcds, 1.0e-14); + doTestInverse( 1.00, 2.00, 100, field, u -> je.valuesS(u).ns(), je::arcns, je::arcns, 1.0e-11); + doTestInverse(-2.00, -1.00, 100, field, u -> je.valuesS(u).ns(), je::arcns, je::arcns, 1.0e-11); } private > void doTestInverseCopolarC(final Field field) { final double m = 0.7; final FieldJacobiElliptic je = build(field, m); - doTestInverse( 1.00, 2.00, 100, field, u -> je.valuesC(u).dc(), x -> je.arcdc(x), x -> je.arcdc(x), 1.0e-14); - doTestInverse(-2.00, -1.00, 100, field, u -> je.valuesC(u).dc(), x -> je.arcdc(x), x -> je.arcdc(x), 1.0e-14); - doTestInverse( 1.00, 2.00, 100, field, u -> je.valuesC(u).nc(), x -> je.arcnc(x), x -> je.arcnc(x), 1.0e-14); - doTestInverse(-2.00, -1.00, 100, field, u -> je.valuesC(u).nc(), x -> je.arcnc(x), x -> je.arcnc(x), 1.0e-14); - doTestInverse(-2.00, 2.00, 100, field, u -> je.valuesC(u).sc(), x -> je.arcsc(x), x -> je.arcsc(x), 1.0e-14); + doTestInverse( 1.00, 2.00, 100, field, u -> je.valuesC(u).dc(), je::arcdc, je::arcdc, 1.0e-14); + doTestInverse(-2.00, -1.00, 100, field, u -> je.valuesC(u).dc(), je::arcdc, je::arcdc, 1.0e-14); + doTestInverse( 1.00, 2.00, 100, field, u -> je.valuesC(u).nc(), je::arcnc, je::arcnc, 1.0e-14); + doTestInverse(-2.00, -1.00, 100, field, u -> je.valuesC(u).nc(), je::arcnc, je::arcnc, 1.0e-14); + doTestInverse(-2.00, 2.00, 100, field, u -> je.valuesC(u).sc(), je::arcsc, je::arcsc, 1.0e-14); } private > void doTestInverseCopolarD(final Field field) { final double m = 0.7; final FieldJacobiElliptic je = build(field, m); - doTestInverse( 1.00, 1.80, 100, field, u -> je.valuesD(u).nd(), x -> je.arcnd(x), x -> je.arcnd(x), 1.0e-14); - doTestInverse(-1.80, 1.80, 100, field, u -> je.valuesD(u).sd(), x -> je.arcsd(x), x -> je.arcsd(x), 1.0e-14); - doTestInverse(-1.00, 1.00, 100, field, u -> je.valuesD(u).cd(), x -> je.arccd(x), x -> je.arccd(x), 1.0e-14); + doTestInverse( 1.00, 1.80, 100, field, u -> je.valuesD(u).nd(), je::arcnd, je::arcnd, 1.0e-14); + doTestInverse(-1.80, 1.80, 100, field, u -> je.valuesD(u).sd(), je::arcsd, je::arcsd, 1.0e-14); + doTestInverse(-1.00, 1.00, 100, field, u -> je.valuesD(u).cd(), je::arccd, je::arccd, 1.0e-14); } private > void doTestInverse(final double xMin, final double xMax, final int n, diff --git a/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/JacobiEllipticTest.java b/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/JacobiEllipticTest.java index fc8447164..4fabefd49 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/JacobiEllipticTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/special/elliptic/jacobi/JacobiEllipticTest.java @@ -140,40 +140,40 @@ void testAllFunctions() { void testInverseCopolarN() { final double m = 0.7; final JacobiElliptic je = JacobiEllipticBuilder.build(m); - doTestInverse(-0.80, 0.80, 100, u -> je.valuesN(u).sn(), x -> je.arcsn(x), 1.0e-14); - doTestInverse(-1.00, 1.00, 100, u -> je.valuesN(u).cn(), x -> je.arccn(x), 1.0e-14); - doTestInverse( 0.55, 1.00, 100, u -> je.valuesN(u).dn(), x -> je.arcdn(x), 1.0e-14); + doTestInverse(-0.80, 0.80, 100, u -> je.valuesN(u).sn(), je::arcsn, 1.0e-14); + doTestInverse(-1.00, 1.00, 100, u -> je.valuesN(u).cn(), je::arccn, 1.0e-14); + doTestInverse( 0.55, 1.00, 100, u -> je.valuesN(u).dn(), je::arcdn, 1.0e-14); } @Test void testInverseCopolarS() { final double m = 0.7; final JacobiElliptic je = JacobiEllipticBuilder.build(m); - doTestInverse(-2.00, 2.00, 100, u -> je.valuesS(u).cs(), x -> je.arccs(x), 1.0e-14); - doTestInverse( 0.55, 2.00, 100, u -> je.valuesS(u).ds(), x -> je.arcds(x), 1.0e-14); - doTestInverse(-2.00, -0.55, 100, u -> je.valuesS(u).ds(), x -> je.arcds(x), 1.0e-14); - doTestInverse( 1.00, 2.00, 100, u -> je.valuesS(u).ns(), x -> je.arcns(x), 1.0e-11); - doTestInverse(-2.00, -1.00, 100, u -> je.valuesS(u).ns(), x -> je.arcns(x), 1.0e-11); + doTestInverse(-2.00, 2.00, 100, u -> je.valuesS(u).cs(), je::arccs, 1.0e-14); + doTestInverse( 0.55, 2.00, 100, u -> je.valuesS(u).ds(), je::arcds, 1.0e-14); + doTestInverse(-2.00, -0.55, 100, u -> je.valuesS(u).ds(), je::arcds, 1.0e-14); + doTestInverse( 1.00, 2.00, 100, u -> je.valuesS(u).ns(), je::arcns, 1.0e-11); + doTestInverse(-2.00, -1.00, 100, u -> je.valuesS(u).ns(), je::arcns, 1.0e-11); } @Test void testInverseCopolarC() { final double m = 0.7; final JacobiElliptic je = JacobiEllipticBuilder.build(m); - doTestInverse( 1.00, 2.00, 100, u -> je.valuesC(u).dc(), x -> je.arcdc(x), 1.0e-14); - doTestInverse(-2.00, -1.00, 100, u -> je.valuesC(u).dc(), x -> je.arcdc(x), 1.0e-14); - doTestInverse( 1.00, 2.00, 100, u -> je.valuesC(u).nc(), x -> je.arcnc(x), 1.0e-14); - doTestInverse(-2.00, -1.00, 100, u -> je.valuesC(u).nc(), x -> je.arcnc(x), 1.0e-14); - doTestInverse(-2.00, 2.00, 100, u -> je.valuesC(u).sc(), x -> je.arcsc(x), 1.0e-14); + doTestInverse( 1.00, 2.00, 100, u -> je.valuesC(u).dc(), je::arcdc, 1.0e-14); + doTestInverse(-2.00, -1.00, 100, u -> je.valuesC(u).dc(), je::arcdc, 1.0e-14); + doTestInverse( 1.00, 2.00, 100, u -> je.valuesC(u).nc(), je::arcnc, 1.0e-14); + doTestInverse(-2.00, -1.00, 100, u -> je.valuesC(u).nc(), je::arcnc, 1.0e-14); + doTestInverse(-2.00, 2.00, 100, u -> je.valuesC(u).sc(), je::arcsc, 1.0e-14); } @Test void testInverseCopolarD() { final double m = 0.7; final JacobiElliptic je = JacobiEllipticBuilder.build(m); - doTestInverse( 1.00, 1.80, 100, u -> je.valuesD(u).nd(), x -> je.arcnd(x), 1.0e-14); - doTestInverse(-1.80, 1.80, 100, u -> je.valuesD(u).sd(), x -> je.arcsd(x), 1.0e-14); - doTestInverse(-1.00, 1.00, 100, u -> je.valuesD(u).cd(), x -> je.arccd(x), 1.0e-14); + doTestInverse( 1.00, 1.80, 100, u -> je.valuesD(u).nd(), je::arcnd, 1.0e-14); + doTestInverse(-1.80, 1.80, 100, u -> je.valuesD(u).sd(), je::arcsd, 1.0e-14); + doTestInverse(-1.00, 1.00, 100, u -> je.valuesD(u).cd(), je::arccd, 1.0e-14); } private void doTestInverse(final double xMin, final double xMax, final int n, diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/ArithmeticUtilsTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/ArithmeticUtilsTest.java index 3cf8ad73c..28c295433 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/ArithmeticUtilsTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/ArithmeticUtilsTest.java @@ -465,9 +465,7 @@ void testPow() { @Test void testPowIntOverflow() { - assertThrows(MathRuntimeException.class, () -> { - ArithmeticUtils.pow(21, 8); - }); + assertThrows(MathRuntimeException.class, () -> ArithmeticUtils.pow(21, 8)); } @Test @@ -482,9 +480,7 @@ void testPowInt() { @Test void testPowNegativeIntOverflow() { - assertThrows(MathRuntimeException.class, () -> { - ArithmeticUtils.pow(-21, 8); - }); + assertThrows(MathRuntimeException.class, () -> ArithmeticUtils.pow(-21, 8)); } @Test @@ -517,9 +513,7 @@ void testPowOneInt() { @Test void testPowLongOverflow() { - assertThrows(MathRuntimeException.class, () -> { - ArithmeticUtils.pow(21, 15); - }); + assertThrows(MathRuntimeException.class, () -> ArithmeticUtils.pow(21, 15)); } @Test @@ -534,9 +528,7 @@ void testPowLong() { @Test void testPowNegativeLongOverflow() { - assertThrows(MathRuntimeException.class, () -> { - ArithmeticUtils.pow(-21L, 15); - }); + assertThrows(MathRuntimeException.class, () -> ArithmeticUtils.pow(-21L, 15)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/BigRealTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/BigRealTest.java index 6c6bf7d17..da70c0e8d 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/BigRealTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/BigRealTest.java @@ -146,9 +146,7 @@ void testReciprocal() { @Test void testReciprocalOfZero() { - assertThrows(MathRuntimeException.class, () -> { - BigReal.ZERO.reciprocal(); - }); + assertThrows(MathRuntimeException.class, BigReal.ZERO::reciprocal); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/CombinatoricsUtilsTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/CombinatoricsUtilsTest.java index db1301ff2..ac6a79787 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/CombinatoricsUtilsTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/CombinatoricsUtilsTest.java @@ -311,23 +311,17 @@ void testStirlingS2() { @Test void testStirlingS2NegativeN() { - assertThrows(MathIllegalArgumentException.class, () -> { - CombinatoricsUtils.stirlingS2(3, -1); - }); + assertThrows(MathIllegalArgumentException.class, () -> CombinatoricsUtils.stirlingS2(3, -1)); } @Test void testStirlingS2LargeK() { - assertThrows(MathIllegalArgumentException.class, () -> { - CombinatoricsUtils.stirlingS2(3, 4); - }); + assertThrows(MathIllegalArgumentException.class, () -> CombinatoricsUtils.stirlingS2(3, 4)); } @Test void testStirlingS2Overflow() { - assertThrows(MathRuntimeException.class, () -> { - CombinatoricsUtils.stirlingS2(26, 9); - }); + assertThrows(MathRuntimeException.class, () -> CombinatoricsUtils.stirlingS2(26, 9)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/FactorialLogTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/FactorialLogTest.java index 2741e102a..368359fb3 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/FactorialLogTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/FactorialLogTest.java @@ -35,9 +35,7 @@ class FactorialLogTest { @Test void testPrecondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - CombinatoricsUtils.FactorialLog.create().withCache(-1); - }); + assertThrows(MathIllegalArgumentException.class, () -> CombinatoricsUtils.FactorialLog.create().withCache(-1)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/FastMathTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/FastMathTest.java index 16437caf8..8e2ed5f0c 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/FastMathTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/FastMathTest.java @@ -2287,16 +2287,12 @@ void testDivideExactLong() { @Test void testToIntExactTooLow() { - assertThrows(MathRuntimeException.class, () -> { - FastMath.toIntExact(-1L + Integer.MIN_VALUE); - }); + assertThrows(MathRuntimeException.class, () -> FastMath.toIntExact(-1L + Integer.MIN_VALUE)); } @Test void testToIntExactTooHigh() { - assertThrows(MathRuntimeException.class, () -> { - FastMath.toIntExact(+1L + Integer.MAX_VALUE); - }); + assertThrows(MathRuntimeException.class, () -> FastMath.toIntExact(+1L + Integer.MAX_VALUE)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/JulierUnscentedTransformTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/JulierUnscentedTransformTest.java index 3d31a96b8..36f86e1d4 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/JulierUnscentedTransformTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/JulierUnscentedTransformTest.java @@ -30,9 +30,7 @@ class JulierUnscentedTransformTest { /** test state dimension equal to 0 */ @Test void testWrongStateDimension() { - assertThrows(MathIllegalArgumentException.class, () -> { - new JulierUnscentedTransform(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new JulierUnscentedTransform(0)); } /** test weight computation */ diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/MathArraysTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/MathArraysTest.java index eeafb8bf9..15807d168 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/MathArraysTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/MathArraysTest.java @@ -74,30 +74,22 @@ void testScaleInPlace() { @Test void testEbeAddPrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - MathArrays.ebeAdd(new double[3], new double[4]); - }); + assertThrows(MathIllegalArgumentException.class, () -> MathArrays.ebeAdd(new double[3], new double[4])); } @Test void testEbeSubtractPrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - MathArrays.ebeSubtract(new double[3], new double[4]); - }); + assertThrows(MathIllegalArgumentException.class, () -> MathArrays.ebeSubtract(new double[3], new double[4])); } @Test void testEbeMultiplyPrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - MathArrays.ebeMultiply(new double[3], new double[4]); - }); + assertThrows(MathIllegalArgumentException.class, () -> MathArrays.ebeMultiply(new double[3], new double[4])); } @Test void testEbeDividePrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - MathArrays.ebeDivide(new double[3], new double[4]); - }); + assertThrows(MathIllegalArgumentException.class, () -> MathArrays.ebeDivide(new double[3], new double[4])); } @Test @@ -495,10 +487,8 @@ void testCheckNotNaN() { @Test void testCheckEqualLength1() { - assertThrows(MathIllegalArgumentException.class, () -> { - MathArrays.checkEqualLength(new double[]{1, 2, 3}, - new double[]{1, 2, 3, 4}); - }); + assertThrows(MathIllegalArgumentException.class, () -> MathArrays.checkEqualLength(new double[]{1, 2, 3}, + new double[]{1, 2, 3, 4})); } @Test @@ -1339,9 +1329,7 @@ void testUniqueNaNValues() { @Test void testUniqueNullArgument() { - assertThrows(NullPointerException.class, () -> { - MathArrays.unique(null); - }); + assertThrows(NullPointerException.class, () -> MathArrays.unique(null)); } @Test diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/MerweUnscentedTransformTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/MerweUnscentedTransformTest.java index b06046077..74bf9e0e1 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/MerweUnscentedTransformTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/MerweUnscentedTransformTest.java @@ -30,9 +30,7 @@ class MerweUnscentedTransformTest { /** test state dimension equal to 0 */ @Test void testWrongStateDimension() { - assertThrows(MathIllegalArgumentException.class, () -> { - new MerweUnscentedTransform(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new MerweUnscentedTransform(0)); } /** test weight computation */ diff --git a/hipparchus-core/src/test/java/org/hipparchus/util/ResizableDoubleArrayTest.java b/hipparchus-core/src/test/java/org/hipparchus/util/ResizableDoubleArrayTest.java index 6df30fd8e..8c9bc2f83 100644 --- a/hipparchus-core/src/test/java/org/hipparchus/util/ResizableDoubleArrayTest.java +++ b/hipparchus-core/src/test/java/org/hipparchus/util/ResizableDoubleArrayTest.java @@ -513,9 +513,7 @@ void testSubstitute() { assertEquals(11, da.getNumElements(), "Number of elements should be 11"); - assertDoesNotThrow(() -> { - da.discardMostRecentElements(10); - }, "Trying to discard a negative number of element is not allowed"); + assertDoesNotThrow(() -> da.discardMostRecentElements(10), "Trying to discard a negative number of element is not allowed"); da.substituteMostRecentElement(24); diff --git a/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/extended/ExtendedKalmanFilterTest.java b/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/extended/ExtendedKalmanFilterTest.java index 88c5ad312..3b1d20021 100644 --- a/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/extended/ExtendedKalmanFilterTest.java +++ b/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/extended/ExtendedKalmanFilterTest.java @@ -65,7 +65,7 @@ void testConstant() { // sequentially process all measurements and check against the reference estimated state and covariance measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). forEach(estimate -> { for (Reference r : referenceData) { if (r.sameTime(estimate.getTime())) { @@ -144,7 +144,7 @@ private void doTestConstantAcceleration(String name) { // sequentially process all measurements and check against the reference estimate measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). forEach(estimate -> { for (Reference r : referenceData) { if (r.sameTime(estimate.getTime())) { @@ -262,7 +262,7 @@ private void doTestCannonball(final double[][] q, final String name, // sequentially process all measurements and check against the reference estimate measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). map(estimate -> { final ProcessEstimate p = filter.getPredicted(); final ProcessEstimate c = filter.getCorrected(); @@ -378,7 +378,7 @@ private void doTestWelshBishop(final long seed, // sequentially process all measurements and get only the last one ProcessEstimate finalEstimate = measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). reduce((first, second) -> second).get(); assertEquals(expected, finalEstimate.getState().getEntry(0), tolerance); diff --git a/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/linear/LinearKalmanFilterTest.java b/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/linear/LinearKalmanFilterTest.java index 4ca9716ef..d64e08b54 100644 --- a/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/linear/LinearKalmanFilterTest.java +++ b/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/linear/LinearKalmanFilterTest.java @@ -71,7 +71,7 @@ void testConstant() { // sequentially process all measurements and check against the reference estimated state and covariance measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). forEach(estimate -> { for (Reference r : referenceData) { if (r.sameTime(estimate.getTime())) { @@ -159,7 +159,7 @@ private void doTestConstantAcceleration(String name) { // sequentially process all measurements and check against the reference estimate measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). forEach(estimate -> { for (Reference r : referenceData) { if (r.sameTime(estimate.getTime())) { @@ -259,7 +259,7 @@ private void doTestCannonball(final double[][] qData, final String name, // sequentially process all measurements and check against the reference estimate measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). map(estimate -> { final ProcessEstimate p = filter.getPredicted(); final ProcessEstimate c = filter.getCorrected(); @@ -338,7 +338,7 @@ private void doTestWelshBishop(final long seed, // sequentially process all measurements and get only the last one final ProcessEstimate finalEstimate = measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). reduce((first, second) -> second).get(); assertEquals(expected, finalEstimate.getState().getEntry(0), tolerance); diff --git a/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/unscented/UnscentedKalmanFilterTest.java b/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/unscented/UnscentedKalmanFilterTest.java index 82561024b..918e638f8 100644 --- a/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/unscented/UnscentedKalmanFilterTest.java +++ b/hipparchus-filtering/src/test/java/org/hipparchus/filtering/kalman/unscented/UnscentedKalmanFilterTest.java @@ -107,7 +107,7 @@ void testConstant() { // sequentially process all measurements and check against the reference estimated state and covariance measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). forEach(estimate -> { for (Reference r : referenceData) { if (r.sameTime(estimate.getTime())) { @@ -207,7 +207,7 @@ private void doTestCannonball(final double[][] q, final String name, // sequentially process all measurements and check against the reference estimate measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). map(estimate -> { final ProcessEstimate p = filter.getPredicted(); final ProcessEstimate c = filter.getCorrected(); @@ -326,7 +326,7 @@ private void doTestWelshBishop(final long seed, // sequentially process all measurements and get only the last one ProcessEstimate finalEstimate = measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). reduce((first, second) -> second).get(); assertEquals(expected, finalEstimate.getState().getEntry(0), tolerance); @@ -396,7 +396,7 @@ private void doTestRadar() { // sequentially process all measurements and check against the reference estimate measurements. - map(measurement -> filter.estimationStep(measurement)). + map(filter::estimationStep). forEach(estimate -> { for (Reference r : referenceData) { if (r.sameTime(estimate.getTime())) { diff --git a/hipparchus-fitting/src/test/java/org/hipparchus/fitting/GaussianCurveFitterTest.java b/hipparchus-fitting/src/test/java/org/hipparchus/fitting/GaussianCurveFitterTest.java index af0f1fa7f..2c5ffc059 100644 --- a/hipparchus-fitting/src/test/java/org/hipparchus/fitting/GaussianCurveFitterTest.java +++ b/hipparchus-fitting/src/test/java/org/hipparchus/fitting/GaussianCurveFitterTest.java @@ -243,9 +243,7 @@ void testWithStartPoint() { */ @Test void testFit02() { - assertThrows(MathIllegalArgumentException.class, () -> { - GaussianCurveFitter.create().fit(new WeightedObservedPoints().toList()); - }); + assertThrows(MathIllegalArgumentException.class, () -> GaussianCurveFitter.create().fit(new WeightedObservedPoints().toList())); } /** diff --git a/hipparchus-fitting/src/test/java/org/hipparchus/fitting/HarmonicCurveFitterTest.java b/hipparchus-fitting/src/test/java/org/hipparchus/fitting/HarmonicCurveFitterTest.java index f6def71c4..11406d242 100644 --- a/hipparchus-fitting/src/test/java/org/hipparchus/fitting/HarmonicCurveFitterTest.java +++ b/hipparchus-fitting/src/test/java/org/hipparchus/fitting/HarmonicCurveFitterTest.java @@ -42,9 +42,7 @@ class HarmonicCurveFitterTest { */ @Test void testPreconditions1() { - assertThrows(MathIllegalArgumentException.class, () -> { - HarmonicCurveFitter.create().fit(new WeightedObservedPoints().toList()); - }); + assertThrows(MathIllegalArgumentException.class, () -> HarmonicCurveFitter.create().fit(new WeightedObservedPoints().toList())); } @Test diff --git a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/Euclidean1DTest.java b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/Euclidean1DTest.java index b7a087503..a0550abd9 100644 --- a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/Euclidean1DTest.java +++ b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/Euclidean1DTest.java @@ -38,9 +38,7 @@ void testDimension() { @Test void testSubSpace() { - assertThrows(Euclidean1D.NoSubSpaceException.class, () -> { - Euclidean1D.getInstance().getSubSpace(); - }); + assertThrows(Euclidean1D.NoSubSpaceException.class, () -> Euclidean1D.getInstance().getSubSpace()); } @Test diff --git a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/IntervalTest.java b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/IntervalTest.java index 3fbab2c80..3800b291c 100644 --- a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/IntervalTest.java +++ b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/oned/IntervalTest.java @@ -91,8 +91,6 @@ void testSinglePoint() { // MATH-1256 @Test void testStrictOrdering() { - assertThrows(MathIllegalArgumentException.class, () -> { - new Interval(0, -1); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Interval(0, -1)); } } diff --git a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/threed/Vector3DTest.java b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/threed/Vector3DTest.java index 69f15ae89..a27a25564 100644 --- a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/threed/Vector3DTest.java +++ b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/euclidean/threed/Vector3DTest.java @@ -174,9 +174,7 @@ void testToString() { @Test void testWrongDimension() throws MathIllegalArgumentException { - assertThrows(MathIllegalArgumentException.class, () -> { - new Vector3D(new double[]{2, 5}); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Vector3D(new double[]{2, 5})); } @Test diff --git a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/ArcTest.java b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/ArcTest.java index 997381e30..5750885c3 100644 --- a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/ArcTest.java +++ b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/ArcTest.java @@ -52,16 +52,12 @@ void testArc() { @Test void testWrongInterval() { - assertThrows(MathIllegalArgumentException.class, () -> { - new Arc(1.2, 0.0, 1.0e-10); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Arc(1.2, 0.0, 1.0e-10)); } @Test void testTooSmallTolerance() { - assertThrows(MathIllegalArgumentException.class, () -> { - new Arc(0.0, 1.0, 0.9 * Sphere1D.SMALLEST_TOLERANCE); - }); + assertThrows(MathIllegalArgumentException.class, () -> new Arc(0.0, 1.0, 0.9 * Sphere1D.SMALLEST_TOLERANCE)); } @Test diff --git a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/LimitAngleTest.java b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/LimitAngleTest.java index 75ad496a5..6b55a1a79 100644 --- a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/LimitAngleTest.java +++ b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/LimitAngleTest.java @@ -47,9 +47,7 @@ void testReversedLimit() { @Test void testTooSmallTolerance() { - assertThrows(MathIllegalArgumentException.class, () -> { - new LimitAngle(new S1Point(1.0), false, 0.9 * Sphere1D.SMALLEST_TOLERANCE); - }); + assertThrows(MathIllegalArgumentException.class, () -> new LimitAngle(new S1Point(1.0), false, 0.9 * Sphere1D.SMALLEST_TOLERANCE)); } } diff --git a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/Sphere1Test.java b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/Sphere1Test.java index 86c42062c..b128a2396 100644 --- a/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/Sphere1Test.java +++ b/hipparchus-geometry/src/test/java/org/hipparchus/geometry/spherical/oned/Sphere1Test.java @@ -38,9 +38,7 @@ void testDimension() { @Test void testSubSpace() { - assertThrows(Sphere1D.NoSubSpaceException.class, () -> { - Sphere1D.getInstance().getSubSpace(); - }); + assertThrows(Sphere1D.NoSubSpaceException.class, () -> Sphere1D.getInstance().getSubSpace()); } @Test diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldDenseOutputModelTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldDenseOutputModelTest.java index fe6742886..ea8192d1b 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldDenseOutputModelTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldDenseOutputModelTest.java @@ -119,9 +119,7 @@ public T[] computeDerivatives(T t, T[] y) { public int getDimension() { return 2; } - public void init(T t0, T[] y0, T finalTime) { - } - }; + }; // integrate backward from π to 0; FieldDenseOutputModel cm1 = new FieldDenseOutputModel(); @@ -212,8 +210,7 @@ private > FieldODEStateInterpolator buildIn public int getDimension() { return s0.getPrimaryStateDimension(); } - public void init(T t0, T[] y0, T finalTime) { - } + public T[] computeDerivatives(T t, T[] y) { return y; } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldExpandableODETest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldExpandableODETest.java index f62f5b71a..d0fa80bb4 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldExpandableODETest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/FieldExpandableODETest.java @@ -211,9 +211,7 @@ private > void doTestMap(final Field field) @Test void testExtractDimensionMismatch() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestExtractDimensionMismatch(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestExtractDimensionMismatch(Binary64Field.getInstance())); } private > void doTestExtractDimensionMismatch(final Field field) @@ -229,9 +227,7 @@ private > void doTestExtractDimensionMismatch( @Test void testInsertTooShortComplete() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestInsertTooShortComplete(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestInsertTooShortComplete(Binary64Field.getInstance())); } private > void doTestInsertTooShortComplete(final Field field) @@ -248,9 +244,7 @@ private > void doTestInsertTooShortComplete(fi @Test void testInsertWrongEquationData() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestInsertWrongEquationData(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestInsertWrongEquationData(Binary64Field.getInstance())); } private > void doTestInsertWrongEquationData(final Field field) @@ -267,9 +261,7 @@ private > void doTestInsertWrongEquationData(f @Test void testNegativeIndex() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestNegativeIndex(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestNegativeIndex(Binary64Field.getInstance())); } private > void doTestNegativeIndex(final Field field) @@ -283,9 +275,7 @@ private > void doTestNegativeIndex(final Field @Test void testTooLargeIndex() { - assertThrows(MathIllegalArgumentException.class, () -> { - doTestTooLargeIndex(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalArgumentException.class, () -> doTestTooLargeIndex(Binary64Field.getInstance())); } private > void doTestTooLargeIndex(final Field field) diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/TestFieldProblem4.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/TestFieldProblem4.java index 3df3d4284..72b7e0ba8 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/TestFieldProblem4.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/TestFieldProblem4.java @@ -208,11 +208,6 @@ public Action eventOccurred(FieldODEStateAndDerivative state, return Action.STOP; } - public FieldODEState resetState(FieldODEEventDetector detector, - FieldODEStateAndDerivative state) { - return state; - } - } } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/CloseEventsTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/CloseEventsTest.java index 5e637f91a..9d3a7f377 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/CloseEventsTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/CloseEventsTest.java @@ -2137,13 +2137,9 @@ public List getEvents() { @Override public ODEEventHandler getHandler() { - return new ODEEventHandler() { - @Override - public Action eventOccurred(ODEStateAndDerivative state, - ODEEventDetector detector, boolean increasing) { - events.add(new Event(state, detector, increasing)); - return action; - } + return (state, detector, increasing) -> { + events.add(new Event(state, detector, increasing)); + return action; }; } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/DetectorBasedEventStateTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/DetectorBasedEventStateTest.java index 678440cad..290642765 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/DetectorBasedEventStateTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/DetectorBasedEventStateTest.java @@ -98,9 +98,7 @@ void testDoEventThrowsIfTimeMismatch() throws NoSuchFieldException, IllegalAcces pendingEventTime.set(eventState, 1.0); final ODEStateAndDerivative state = new ODEStateAndDerivative(1.0001, new double[]{0.0}, new double[]{0.0}); // Action & verify - Assertions.assertThrows(org.hipparchus.exception.MathRuntimeException.class, () -> { - eventState.doEvent(state); - }); + Assertions.assertThrows(org.hipparchus.exception.MathRuntimeException.class, () -> eventState.doEvent(state)); } @Test diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldCloseEventsTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldCloseEventsTest.java index dd6576b53..31e436e34 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldCloseEventsTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldCloseEventsTest.java @@ -2174,14 +2174,9 @@ public List getEvents() { @Override public FieldODEEventHandler getHandler() { - return new FieldODEEventHandler() { - @Override - public Action eventOccurred(FieldODEStateAndDerivative state, - FieldODEEventDetector detector, - boolean increasing) { - events.add(new Event(state, detector, increasing)); - return action; - } + return (state, detector, increasing) -> { + events.add(new Event(state, detector, increasing)); + return action; }; } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldDetectorBasedEventStateTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldDetectorBasedEventStateTest.java index 4c8b8d2ed..53dc433c8 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldDetectorBasedEventStateTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/events/FieldDetectorBasedEventStateTest.java @@ -89,9 +89,7 @@ void testDoEventThrowsIfTimeMismatch() throws NoSuchFieldException, IllegalAcces final Binary64[] array = MathArrays.buildArray(field, 1); final FieldODEStateAndDerivative state = new FieldODEStateAndDerivative<>(zero.add(1.0001), array, array); // Action & verify - Assertions.assertThrows(org.hipparchus.exception.MathRuntimeException.class, () -> { - eventState.doEvent(state); - }); + Assertions.assertThrows(org.hipparchus.exception.MathRuntimeException.class, () -> eventState.doEvent(state)); } @ParameterizedTest diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java index f5c95f8a0..441fde2f4 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthFieldIntegratorTest.java @@ -49,9 +49,7 @@ void testNbPoints() { @Test public void testMinStep() { - assertThrows(MathIllegalArgumentException.class, () -> { - doDimensionCheck(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalArgumentException.class, () -> doDimensionCheck(Binary64Field.getInstance())); } @Test @@ -64,9 +62,7 @@ public void testIncreasingTolerance() { @Test public void exceedMaxEvaluations() { - assertThrows(MathIllegalStateException.class, () -> { - doExceedMaxEvaluations(Binary64Field.getInstance(), 650); - }); + assertThrows(MathIllegalStateException.class, () -> doExceedMaxEvaluations(Binary64Field.getInstance(), 650)); } @Test @@ -86,9 +82,7 @@ public void testSecondaryEquations() { @Test public void testStartFailure() { - assertThrows(MathIllegalStateException.class, () -> { - doTestStartFailure(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalStateException.class, () -> doTestStartFailure(Binary64Field.getInstance())); } } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthIntegratorTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthIntegratorTest.java index 846c617a1..23ab8b0d5 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthIntegratorTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsBashforthIntegratorTest.java @@ -46,9 +46,7 @@ void testNbPoints() { @Test public void testMinStep() { - assertThrows(MathIllegalArgumentException.class, () -> { - doDimensionCheck(); - }); + assertThrows(MathIllegalArgumentException.class, this::doDimensionCheck); } @Test @@ -61,9 +59,7 @@ public void testIncreasingTolerance() { @Test public void exceedMaxEvaluations() { - assertThrows(MathIllegalStateException.class, () -> { - doExceedMaxEvaluations(650); - }); + assertThrows(MathIllegalStateException.class, () -> doExceedMaxEvaluations(650)); } @Test @@ -78,9 +74,7 @@ public void polynomial() { @Test public void testStartFailure() { - assertThrows(MathIllegalStateException.class, () -> { - doTestStartFailure(); - }); + assertThrows(MathIllegalStateException.class, this::doTestStartFailure); } @Test diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java index d47424aec..c270b7e63 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsFieldIntegratorAbstractTest.java @@ -355,26 +355,23 @@ public T[] computeDerivatives(T t, T[] primary, T[] primaryDot, T[] secondary) { FieldODEIntegrator integrator = createIntegrator(field, 6, 0.001, 1.0, 1.0e-12, 1.0e-12); final double[] max = new double[2]; - integrator.addStepHandler(new FieldODEStepHandler() { - @Override - public void handleStep(FieldODEStateInterpolator interpolator) { - for (int i = 0; i <= 10; ++i) { - T tPrev = interpolator.getPreviousState().getTime(); - T tCurr = interpolator.getCurrentState().getTime(); - T t = tPrev.multiply(10 - i).add(tCurr.multiply(i)).divide(10); - FieldODEStateAndDerivative state = interpolator.getInterpolatedState(t); - assertEquals(2, state.getPrimaryStateDimension()); - assertEquals(1, state.getNumberOfSecondaryStates()); - assertEquals(2, state.getSecondaryStateDimension(0)); - assertEquals(1, state.getSecondaryStateDimension(1)); - assertEquals(3, state.getCompleteStateDimension()); - max[0] = FastMath.max(max[0], - t.sin().subtract(state.getPrimaryState()[0]).norm()); - max[0] = FastMath.max(max[0], - t.cos().subtract(state.getPrimaryState()[1]).norm()); - max[1] = FastMath.max(max[1], - field.getOne().subtract(t).subtract(state.getSecondaryState(1)[0]).norm()); - } + integrator.addStepHandler(interpolator -> { + for (int i = 0; i <= 10; ++i) { + T tPrev = interpolator.getPreviousState().getTime(); + T tCurr = interpolator.getCurrentState().getTime(); + T t = tPrev.multiply(10 - i).add(tCurr.multiply(i)).divide(10); + FieldODEStateAndDerivative state = interpolator.getInterpolatedState(t); + assertEquals(2, state.getPrimaryStateDimension()); + assertEquals(1, state.getNumberOfSecondaryStates()); + assertEquals(2, state.getSecondaryStateDimension(0)); + assertEquals(1, state.getSecondaryStateDimension(1)); + assertEquals(3, state.getCompleteStateDimension()); + max[0] = FastMath.max(max[0], + t.sin().subtract(state.getPrimaryState()[0]).norm()); + max[0] = FastMath.max(max[0], + t.cos().subtract(state.getPrimaryState()[1]).norm()); + max[1] = FastMath.max(max[1], + field.getOne().subtract(t).subtract(state.getSecondaryState(1)[0]).norm()); } }); diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsIntegratorAbstractTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsIntegratorAbstractTest.java index 8e3d40d48..b375e429a 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsIntegratorAbstractTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsIntegratorAbstractTest.java @@ -315,26 +315,23 @@ public double[] computeDerivatives(double t, double[] primary, double[] primaryD ODEIntegrator integrator = createIntegrator(6, 0.001, 1.0, 1.0e-12, 1.0e-12); final double[] max = new double[2]; - integrator.addStepHandler(new ODEStepHandler() { - @Override - public void handleStep(ODEStateInterpolator interpolator) { - for (int i = 0; i <= 10; ++i) { - double tPrev = interpolator.getPreviousState().getTime(); - double tCurr = interpolator.getCurrentState().getTime(); - double t = (tPrev * (10 - i) + tCurr * i) / 10; - ODEStateAndDerivative state = interpolator.getInterpolatedState(t); - assertEquals(2, state.getPrimaryStateDimension()); - assertEquals(1, state.getNumberOfSecondaryStates()); - assertEquals(2, state.getSecondaryStateDimension(0)); - assertEquals(1, state.getSecondaryStateDimension(1)); - assertEquals(3, state.getCompleteStateDimension()); - max[0] = FastMath.max(max[0], - FastMath.abs(FastMath.sin(t) - state.getPrimaryState()[0])); - max[0] = FastMath.max(max[0], - FastMath.abs(FastMath.cos(t) - state.getPrimaryState()[1])); - max[1] = FastMath.max(max[1], - FastMath.abs(1 - t - state.getSecondaryState(1)[0])); - } + integrator.addStepHandler(interpolator -> { + for (int i = 0; i <= 10; ++i) { + double tPrev = interpolator.getPreviousState().getTime(); + double tCurr = interpolator.getCurrentState().getTime(); + double t = (tPrev * (10 - i) + tCurr * i) / 10; + ODEStateAndDerivative state = interpolator.getInterpolatedState(t); + assertEquals(2, state.getPrimaryStateDimension()); + assertEquals(1, state.getNumberOfSecondaryStates()); + assertEquals(2, state.getSecondaryStateDimension(0)); + assertEquals(1, state.getSecondaryStateDimension(1)); + assertEquals(3, state.getCompleteStateDimension()); + max[0] = FastMath.max(max[0], + FastMath.abs(FastMath.sin(t) - state.getPrimaryState()[0])); + max[0] = FastMath.max(max[0], + FastMath.abs(FastMath.cos(t) - state.getPrimaryState()[1])); + max[1] = FastMath.max(max[1], + FastMath.abs(1 - t - state.getSecondaryState(1)[0])); } }); diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java index 3d739e78f..ac9d92933 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonFieldIntegratorTest.java @@ -49,9 +49,7 @@ void testNbPoints() { @Test public void testMinStep() { - assertThrows(MathIllegalArgumentException.class, () -> { - doDimensionCheck(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalArgumentException.class, () -> doDimensionCheck(Binary64Field.getInstance())); } @Test @@ -64,9 +62,7 @@ public void testIncreasingTolerance() { @Test public void exceedMaxEvaluations() { - assertThrows(MathIllegalStateException.class, () -> { - doExceedMaxEvaluations(Binary64Field.getInstance(), 650); - }); + assertThrows(MathIllegalStateException.class, () -> doExceedMaxEvaluations(Binary64Field.getInstance(), 650)); } @Test @@ -86,9 +82,7 @@ public void testSecondaryEquations() { @Test public void testStartFailure() { - assertThrows(MathIllegalStateException.class, () -> { - doTestStartFailure(Binary64Field.getInstance()); - }); + assertThrows(MathIllegalStateException.class, () -> doTestStartFailure(Binary64Field.getInstance())); } } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonIntegratorTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonIntegratorTest.java index 6c280566f..db508b7a3 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonIntegratorTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/AdamsMoultonIntegratorTest.java @@ -46,9 +46,7 @@ void testNbPoints() { @Test public void testMinStep() { - assertThrows(MathIllegalArgumentException.class, () -> { - doDimensionCheck(); - }); + assertThrows(MathIllegalArgumentException.class, this::doDimensionCheck); } @Test @@ -61,9 +59,7 @@ public void testIncreasingTolerance() { @Test public void exceedMaxEvaluations() { - assertThrows(MathIllegalStateException.class, () -> { - doExceedMaxEvaluations(650); - }); + assertThrows(MathIllegalStateException.class, () -> doExceedMaxEvaluations(650)); } @Test @@ -83,9 +79,7 @@ public void testSecondaryEquations() { @Test public void testStartFailure() { - assertThrows(MathIllegalStateException.class, () -> { - doTestStartFailure(); - }); + assertThrows(MathIllegalStateException.class, this::doTestStartFailure); } } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java index c711b7900..08ad4062c 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaFieldIntegratorAbstractTest.java @@ -143,9 +143,6 @@ public int getDimension() { return 1; } - public void init(T t0, T[] y0, T t) { - } - public T[] computeDerivatives(T t, T[] y) { if (t.getReal() < -0.5) { throw new LocalException(); @@ -199,10 +196,8 @@ protected > void doTestMinStep(final Field TestFieldProblemHandler handler = new TestFieldProblemHandler(pb, integ); integ.addStepHandler(handler); - assertThrows(MathIllegalArgumentException.class, () -> { - integ.integrate(new FieldExpandableODE(pb), pb.getInitialState(), - pb.getFinalTime()); - }); + assertThrows(MathIllegalArgumentException.class, () -> integ.integrate(new FieldExpandableODE(pb), pb.getInitialState(), + pb.getFinalTime())); } @Test @@ -478,9 +473,7 @@ public T g(FieldODEStateAndDerivative state) { } }); - assertThrows(LocalException.class, ()->{ - integ.integrate(new FieldExpandableODE(pb), pb.getInitialState(), pb.getFinalTime()); - }); + assertThrows(LocalException.class, ()-> integ.integrate(new FieldExpandableODE(pb), pb.getInitialState(), pb.getFinalTime())); } @Test @@ -925,26 +918,23 @@ public T[] computeDerivatives(T t, T[] primary, T[] primaryDot, T[] secondary) { FieldODEIntegrator integrator = createIntegrator(field, 0.001, 1.0, 1.0e-12, 1.0e-12); final double[] max = new double[2]; - integrator.addStepHandler(new FieldODEStepHandler() { - @Override - public void handleStep(FieldODEStateInterpolator interpolator) { - for (int i = 0; i <= 10; ++i) { - T tPrev = interpolator.getPreviousState().getTime(); - T tCurr = interpolator.getCurrentState().getTime(); - T t = tPrev.multiply(10 - i).add(tCurr.multiply(i)).divide(10); - FieldODEStateAndDerivative state = interpolator.getInterpolatedState(t); - assertEquals(2, state.getPrimaryStateDimension()); - assertEquals(1, state.getNumberOfSecondaryStates()); - assertEquals(2, state.getSecondaryStateDimension(0)); - assertEquals(1, state.getSecondaryStateDimension(1)); - assertEquals(3, state.getCompleteStateDimension()); - max[0] = FastMath.max(max[0], - t.sin().subtract(state.getPrimaryState()[0]).norm()); - max[0] = FastMath.max(max[0], - t.cos().subtract(state.getPrimaryState()[1]).norm()); - max[1] = FastMath.max(max[1], - field.getOne().subtract(t).subtract(state.getSecondaryState(1)[0]).norm()); - } + integrator.addStepHandler(interpolator -> { + for (int i = 0; i <= 10; ++i) { + T tPrev = interpolator.getPreviousState().getTime(); + T tCurr = interpolator.getCurrentState().getTime(); + T t = tPrev.multiply(10 - i).add(tCurr.multiply(i)).divide(10); + FieldODEStateAndDerivative state = interpolator.getInterpolatedState(t); + assertEquals(2, state.getPrimaryStateDimension()); + assertEquals(1, state.getNumberOfSecondaryStates()); + assertEquals(2, state.getSecondaryStateDimension(0)); + assertEquals(1, state.getSecondaryStateDimension(1)); + assertEquals(3, state.getCompleteStateDimension()); + max[0] = FastMath.max(max[0], + t.sin().subtract(state.getPrimaryState()[0]).norm()); + max[0] = FastMath.max(max[0], + t.cos().subtract(state.getPrimaryState()[1]).norm()); + max[1] = FastMath.max(max[1], + field.getOne().subtract(t).subtract(state.getSecondaryState(1)[0]).norm()); } }); diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaIntegratorAbstractTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaIntegratorAbstractTest.java index ff766cf1c..b43eec298 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaIntegratorAbstractTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaIntegratorAbstractTest.java @@ -1163,26 +1163,23 @@ public double[] computeDerivatives(double t, double[] primary, double[] primaryD ODEIntegrator integrator = createIntegrator(0.001, 1.0, 1.0e-12, 1.0e-12); final double[] max = new double[2]; - integrator.addStepHandler(new ODEStepHandler() { - @Override - public void handleStep(ODEStateInterpolator interpolator) { - for (int i = 0; i <= 10; ++i) { - double tPrev = interpolator.getPreviousState().getTime(); - double tCurr = interpolator.getCurrentState().getTime(); - double t = (tPrev * (10 - i) + tCurr * i) / 10; - ODEStateAndDerivative state = interpolator.getInterpolatedState(t); - assertEquals(2, state.getPrimaryStateDimension()); - assertEquals(1, state.getNumberOfSecondaryStates()); - assertEquals(2, state.getSecondaryStateDimension(0)); - assertEquals(1, state.getSecondaryStateDimension(1)); - assertEquals(3, state.getCompleteStateDimension()); - max[0] = FastMath.max(max[0], - FastMath.abs(FastMath.sin(t) - state.getPrimaryState()[0])); - max[0] = FastMath.max(max[0], - FastMath.abs(FastMath.cos(t) - state.getPrimaryState()[1])); - max[1] = FastMath.max(max[1], - FastMath.abs(1 - t - state.getSecondaryState(1)[0])); - } + integrator.addStepHandler(interpolator -> { + for (int i = 0; i <= 10; ++i) { + double tPrev = interpolator.getPreviousState().getTime(); + double tCurr = interpolator.getCurrentState().getTime(); + double t = (tPrev * (10 - i) + tCurr * i) / 10; + ODEStateAndDerivative state = interpolator.getInterpolatedState(t); + assertEquals(2, state.getPrimaryStateDimension()); + assertEquals(1, state.getNumberOfSecondaryStates()); + assertEquals(2, state.getSecondaryStateDimension(0)); + assertEquals(1, state.getSecondaryStateDimension(1)); + assertEquals(3, state.getCompleteStateDimension()); + max[0] = FastMath.max(max[0], + FastMath.abs(FastMath.sin(t) - state.getPrimaryState()[0])); + max[0] = FastMath.max(max[0], + FastMath.abs(FastMath.cos(t) - state.getPrimaryState()[1])); + max[1] = FastMath.max(max[1], + FastMath.abs(1 - t - state.getSecondaryState(1)[0])); } }); diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/FieldODEStateInterpolatorAbstractTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/FieldODEStateInterpolatorAbstractTest.java index 48a67561b..c0b944a58 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/FieldODEStateInterpolatorAbstractTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/FieldODEStateInterpolatorAbstractTest.java @@ -375,8 +375,7 @@ protected SinCos(final Field field) { public int getDimension() { return 2; } - public void init(final T t0, final T[] y0, final T finalTime) { - } + public T[] computeDerivatives(final T t, final T[] y) { T[] yDot = MathArrays.buildArray(field, 2); yDot[0] = y[1]; diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java index 5d249a718..9755eccc2 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaFieldIntegratorAbstractTest.java @@ -432,13 +432,11 @@ protected > void doTestStepSize(final Field final T finalTime = field.getZero().add(5.0); final T step = field.getZero().add(1.23456); FixedStepRungeKuttaFieldIntegrator integ = createIntegrator(field, step); - integ.addStepHandler(new FieldODEStepHandler() { - public void handleStep(FieldODEStateInterpolator interpolator) { - if (interpolator.getCurrentState().getTime().subtract(finalTime).getReal() < -0.001) { - assertEquals(step.getReal(), - interpolator.getCurrentState().getTime().subtract(interpolator.getPreviousState().getTime()).getReal(), - epsilon); - } + integ.addStepHandler(interpolator -> { + if (interpolator.getCurrentState().getTime().subtract(finalTime).getReal() < -0.001) { + assertEquals(step.getReal(), + interpolator.getCurrentState().getTime().subtract(interpolator.getPreviousState().getTime()).getReal(), + epsilon); } }); integ.integrate(new FieldExpandableODE(new FieldOrdinaryDifferentialEquation() { @@ -644,26 +642,23 @@ public T[] computeDerivatives(T t, T[] primary, T[] primaryDot, T[] secondary) { FieldODEIntegrator integrator = createIntegrator(field, field.getZero().add(0.001)); final double[] max = new double[2]; - integrator.addStepHandler(new FieldODEStepHandler() { - @Override - public void handleStep(FieldODEStateInterpolator interpolator) { - for (int i = 0; i <= 10; ++i) { - T tPrev = interpolator.getPreviousState().getTime(); - T tCurr = interpolator.getCurrentState().getTime(); - T t = tPrev.multiply(10 - i).add(tCurr.multiply(i)).divide(10); - FieldODEStateAndDerivative state = interpolator.getInterpolatedState(t); - assertEquals(2, state.getPrimaryStateDimension()); - assertEquals(1, state.getNumberOfSecondaryStates()); - assertEquals(2, state.getSecondaryStateDimension(0)); - assertEquals(1, state.getSecondaryStateDimension(1)); - assertEquals(3, state.getCompleteStateDimension()); - max[0] = FastMath.max(max[0], - t.sin().subtract(state.getPrimaryState()[0]).norm()); - max[0] = FastMath.max(max[0], - t.cos().subtract(state.getPrimaryState()[1]).norm()); - max[1] = FastMath.max(max[1], - field.getOne().subtract(t).subtract(state.getSecondaryState(1)[0]).norm()); - } + integrator.addStepHandler(interpolator -> { + for (int i = 0; i <= 10; ++i) { + T tPrev = interpolator.getPreviousState().getTime(); + T tCurr = interpolator.getCurrentState().getTime(); + T t = tPrev.multiply(10 - i).add(tCurr.multiply(i)).divide(10); + FieldODEStateAndDerivative state = interpolator.getInterpolatedState(t); + assertEquals(2, state.getPrimaryStateDimension()); + assertEquals(1, state.getNumberOfSecondaryStates()); + assertEquals(2, state.getSecondaryStateDimension(0)); + assertEquals(1, state.getSecondaryStateDimension(1)); + assertEquals(3, state.getCompleteStateDimension()); + max[0] = FastMath.max(max[0], + t.sin().subtract(state.getPrimaryState()[0]).norm()); + max[0] = FastMath.max(max[0], + t.cos().subtract(state.getPrimaryState()[1]).norm()); + max[1] = FastMath.max(max[1], + field.getOne().subtract(t).subtract(state.getSecondaryState(1)[0]).norm()); } }); diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaIntegratorAbstractTest.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaIntegratorAbstractTest.java index 0fd97eadb..2f94f279b 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaIntegratorAbstractTest.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/RungeKuttaIntegratorAbstractTest.java @@ -347,13 +347,11 @@ protected void doTestStepSize(final double epsilon) final double finalTime = 5.0; final double step = 1.23456; FixedStepRungeKuttaIntegrator integ = createIntegrator(step); - integ.addStepHandler(new ODEStepHandler() { - public void handleStep(ODEStateInterpolator interpolator) { - if (interpolator.getCurrentState().getTime() < finalTime - 0.001) { - assertEquals(step, - interpolator.getCurrentState().getTime() - interpolator.getPreviousState().getTime(), - epsilon); - } + integ.addStepHandler(interpolator -> { + if (interpolator.getCurrentState().getTime() < finalTime - 0.001) { + assertEquals(step, + interpolator.getCurrentState().getTime() - interpolator.getPreviousState().getTime(), + epsilon); } }); integ.integrate(new ExpandableODE(new OrdinaryDifferentialEquation() { @@ -495,26 +493,23 @@ public double[] computeDerivatives(double t, double[] primary, double[] primaryD ODEIntegrator integrator = createIntegrator(0.001); final double[] max = new double[2]; - integrator.addStepHandler(new ODEStepHandler() { - @Override - public void handleStep(ODEStateInterpolator interpolator) { - for (int i = 0; i <= 10; ++i) { - double tPrev = interpolator.getPreviousState().getTime(); - double tCurr = interpolator.getCurrentState().getTime(); - double t = (tPrev * (10 - i) + tCurr * i) / 10; - ODEStateAndDerivative state = interpolator.getInterpolatedState(t); - assertEquals(2, state.getPrimaryStateDimension()); - assertEquals(1, state.getNumberOfSecondaryStates()); - assertEquals(2, state.getSecondaryStateDimension(0)); - assertEquals(1, state.getSecondaryStateDimension(1)); - assertEquals(3, state.getCompleteStateDimension()); - max[0] = FastMath.max(max[0], - FastMath.abs(FastMath.sin(t) - state.getPrimaryState()[0])); - max[0] = FastMath.max(max[0], - FastMath.abs(FastMath.cos(t) - state.getPrimaryState()[1])); - max[1] = FastMath.max(max[1], - FastMath.abs(1 - t - state.getSecondaryState(1)[0])); - } + integrator.addStepHandler(interpolator -> { + for (int i = 0; i <= 10; ++i) { + double tPrev = interpolator.getPreviousState().getTime(); + double tCurr = interpolator.getCurrentState().getTime(); + double t = (tPrev * (10 - i) + tCurr * i) / 10; + ODEStateAndDerivative state = interpolator.getInterpolatedState(t); + assertEquals(2, state.getPrimaryStateDimension()); + assertEquals(1, state.getNumberOfSecondaryStates()); + assertEquals(2, state.getSecondaryStateDimension(0)); + assertEquals(1, state.getSecondaryStateDimension(1)); + assertEquals(3, state.getCompleteStateDimension()); + max[0] = FastMath.max(max[0], + FastMath.abs(FastMath.sin(t) - state.getPrimaryState()[0])); + max[0] = FastMath.max(max[0], + FastMath.abs(FastMath.cos(t) - state.getPrimaryState()[1])); + max[1] = FastMath.max(max[1], + FastMath.abs(1 - t - state.getSecondaryState(1)[0])); } }); diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepFieldProblem.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepFieldProblem.java index d4812de95..20753eceb 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepFieldProblem.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepFieldProblem.java @@ -90,9 +90,6 @@ public void setRate(T rate) { this.rate = rate; } - public void init(T t0, T[] y0, T t) { - } - public void init(FieldODEStateAndDerivative state0, T t) { } diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepProblem.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepProblem.java index f131b3654..013953444 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepProblem.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/nonstiff/StepProblem.java @@ -80,9 +80,6 @@ public void setRate(double rate) { this.rate = rate; } - public void init(double t0, double[] y0, double t) { - } - private static class LocalHandler implements ODEEventHandler { public Action eventOccurred(ODEStateAndDerivative state, ODEEventDetector detector, boolean increasing) { final StepProblem sp = (StepProblem) detector; diff --git a/hipparchus-ode/src/test/java/org/hipparchus/ode/sampling/StepInterpolatorTestUtils.java b/hipparchus-ode/src/test/java/org/hipparchus/ode/sampling/StepInterpolatorTestUtils.java index f1dd67363..77fcb2f82 100644 --- a/hipparchus-ode/src/test/java/org/hipparchus/ode/sampling/StepInterpolatorTestUtils.java +++ b/hipparchus-ode/src/test/java/org/hipparchus/ode/sampling/StepInterpolatorTestUtils.java @@ -41,37 +41,33 @@ public static void checkDerivativesConsistency(final ODEIntegrator integrator, final double finiteDifferencesRatio, final double threshold) throws MathIllegalArgumentException, MathIllegalStateException { - integrator.addStepHandler(new ODEStepHandler() { + integrator.addStepHandler(interpolator -> { - public void handleStep(ODEStateInterpolator interpolator) { + final double dt = interpolator.getCurrentState().getTime() - interpolator.getPreviousState().getTime(); + final double h = finiteDifferencesRatio * dt; + final double t = interpolator.getCurrentState().getTime() - 0.3 * dt; - final double dt = interpolator.getCurrentState().getTime() - interpolator.getPreviousState().getTime(); - final double h = finiteDifferencesRatio * dt; - final double t = interpolator.getCurrentState().getTime() - 0.3 * dt; - - if (FastMath.abs(h) < 10 * FastMath.ulp(t)) { - return; - } - - final double[] yM4h = interpolator.getInterpolatedState(t - 4 * h).getPrimaryState(); - final double[] yM3h = interpolator.getInterpolatedState(t - 3 * h).getPrimaryState(); - final double[] yM2h = interpolator.getInterpolatedState(t - 2 * h).getPrimaryState(); - final double[] yM1h = interpolator.getInterpolatedState(t - h).getPrimaryState(); - final double[] yP1h = interpolator.getInterpolatedState(t + h).getPrimaryState(); - final double[] yP2h = interpolator.getInterpolatedState(t + 2 * h).getPrimaryState(); - final double[] yP3h = interpolator.getInterpolatedState(t + 3 * h).getPrimaryState(); - final double[] yP4h = interpolator.getInterpolatedState(t + 4 * h).getPrimaryState(); - - final double[] yDot = interpolator.getInterpolatedState(t).getPrimaryDerivative(); - - for (int i = 0; i < yDot.length; ++i) { - final double approYDot = ( -3 * (yP4h[i] - yM4h[i]) + - 32 * (yP3h[i] - yM3h[i]) + - -168 * (yP2h[i] - yM2h[i]) + - 672 * (yP1h[i] - yM1h[i])) / (840 * h); - assertEquals(approYDot, yDot[i], threshold, "" + (approYDot - yDot[i])); - } + if (FastMath.abs(h) < 10 * FastMath.ulp(t)) { + return; + } + final double[] yM4h = interpolator.getInterpolatedState(t - 4 * h).getPrimaryState(); + final double[] yM3h = interpolator.getInterpolatedState(t - 3 * h).getPrimaryState(); + final double[] yM2h = interpolator.getInterpolatedState(t - 2 * h).getPrimaryState(); + final double[] yM1h = interpolator.getInterpolatedState(t - h).getPrimaryState(); + final double[] yP1h = interpolator.getInterpolatedState(t + h).getPrimaryState(); + final double[] yP2h = interpolator.getInterpolatedState(t + 2 * h).getPrimaryState(); + final double[] yP3h = interpolator.getInterpolatedState(t + 3 * h).getPrimaryState(); + final double[] yP4h = interpolator.getInterpolatedState(t + 4 * h).getPrimaryState(); + + final double[] yDot = interpolator.getInterpolatedState(t).getPrimaryDerivative(); + + for (int i = 0; i < yDot.length; ++i) { + final double approYDot = ( -3 * (yP4h[i] - yM4h[i]) + + 32 * (yP3h[i] - yM3h[i]) + + -168 * (yP2h[i] - yM2h[i]) + + 672 * (yP1h[i] - yM1h[i])) / (840 * h); + assertEquals(approYDot, yDot[i], threshold, "" + (approYDot - yDot[i])); } }); @@ -83,37 +79,33 @@ public void handleStep(ODEStateInterpolator interpolator) { public static > void checkDerivativesConsistency(final FieldODEIntegrator integrator, final TestFieldProblemAbstract problem, final double threshold) { - integrator.addStepHandler(new FieldODEStepHandler() { + integrator.addStepHandler(interpolator -> { - public void handleStep(FieldODEStateInterpolator interpolator) { + final T h = interpolator.getCurrentState().getTime().subtract(interpolator.getPreviousState().getTime()).multiply(0.001); + final T t = interpolator.getCurrentState().getTime().subtract(h.multiply(300)); - final T h = interpolator.getCurrentState().getTime().subtract(interpolator.getPreviousState().getTime()).multiply(0.001); - final T t = interpolator.getCurrentState().getTime().subtract(h.multiply(300)); - - if (h.abs().subtract(FastMath.ulp(t.getReal()) * 10).getReal() < 0) { - return; - } - - final T[] yM4h = interpolator.getInterpolatedState(t.add(h.multiply(-4))).getPrimaryState(); - final T[] yM3h = interpolator.getInterpolatedState(t.add(h.multiply(-3))).getPrimaryState(); - final T[] yM2h = interpolator.getInterpolatedState(t.add(h.multiply(-2))).getPrimaryState(); - final T[] yM1h = interpolator.getInterpolatedState(t.add(h.multiply(-1))).getPrimaryState(); - final T[] yP1h = interpolator.getInterpolatedState(t.add(h.multiply( 1))).getPrimaryState(); - final T[] yP2h = interpolator.getInterpolatedState(t.add(h.multiply( 2))).getPrimaryState(); - final T[] yP3h = interpolator.getInterpolatedState(t.add(h.multiply( 3))).getPrimaryState(); - final T[] yP4h = interpolator.getInterpolatedState(t.add(h.multiply( 4))).getPrimaryState(); - - final T[] yDot = interpolator.getInterpolatedState(t).getPrimaryDerivative(); - - for (int i = 0; i < yDot.length; ++i) { - final T approYDot = yP4h[i].subtract(yM4h[i]).multiply( -3). - add(yP3h[i].subtract(yM3h[i]).multiply( 32)). - add(yP2h[i].subtract(yM2h[i]).multiply(-168)). - add(yP1h[i].subtract(yM1h[i]).multiply( 672)). - divide(h.multiply(840)); - assertEquals(approYDot.getReal(), yDot[i].getReal(), threshold); - } + if (h.abs().subtract(FastMath.ulp(t.getReal()) * 10).getReal() < 0) { + return; + } + final T[] yM4h = interpolator.getInterpolatedState(t.add(h.multiply(-4))).getPrimaryState(); + final T[] yM3h = interpolator.getInterpolatedState(t.add(h.multiply(-3))).getPrimaryState(); + final T[] yM2h = interpolator.getInterpolatedState(t.add(h.multiply(-2))).getPrimaryState(); + final T[] yM1h = interpolator.getInterpolatedState(t.add(h.multiply(-1))).getPrimaryState(); + final T[] yP1h = interpolator.getInterpolatedState(t.add(h.multiply( 1))).getPrimaryState(); + final T[] yP2h = interpolator.getInterpolatedState(t.add(h.multiply( 2))).getPrimaryState(); + final T[] yP3h = interpolator.getInterpolatedState(t.add(h.multiply( 3))).getPrimaryState(); + final T[] yP4h = interpolator.getInterpolatedState(t.add(h.multiply( 4))).getPrimaryState(); + + final T[] yDot = interpolator.getInterpolatedState(t).getPrimaryDerivative(); + + for (int i = 0; i < yDot.length; ++i) { + final T approYDot = yP4h[i].subtract(yM4h[i]).multiply( -3). + add(yP3h[i].subtract(yM3h[i]).multiply( 32)). + add(yP2h[i].subtract(yM2h[i]).multiply(-168)). + add(yP1h[i].subtract(yM1h[i]).multiply( 672)). + divide(h.multiply(840)); + assertEquals(approYDot.getReal(), yDot[i].getReal(), threshold); } }); diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/SimplePointCheckerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/SimplePointCheckerTest.java index caebfaafc..ff5809417 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/SimplePointCheckerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/SimplePointCheckerTest.java @@ -31,9 +31,7 @@ class SimplePointCheckerTest { @Test void testIterationCheckPrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - new SimplePointChecker(1e-1, 1e-2, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new SimplePointChecker(1e-1, 1e-2, 0)); } @Test diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleValueCheckerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleValueCheckerTest.java index 906f865ff..4ce9ef752 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleValueCheckerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleValueCheckerTest.java @@ -31,9 +31,7 @@ class SimpleValueCheckerTest { @Test void testIterationCheckPrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - new SimpleValueChecker(1e-1, 1e-2, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new SimpleValueChecker(1e-1, 1e-2, 0)); } @Test diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleVectorValueCheckerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleVectorValueCheckerTest.java index a99ee93c9..cd3947ae7 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleVectorValueCheckerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/SimpleVectorValueCheckerTest.java @@ -31,9 +31,7 @@ class SimpleVectorValueCheckerTest { @Test void testIterationCheckPrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - new SimpleVectorValueChecker(1e-1, 1e-2, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new SimpleVectorValueChecker(1e-1, 1e-2, 0)); } @Test diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/CircleScalar.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/CircleScalar.java index 793fe9286..970736686 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/CircleScalar.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/CircleScalar.java @@ -53,38 +53,34 @@ public double getRadius(Vector2D center) { } public ObjectiveFunction getObjectiveFunction() { - return new ObjectiveFunction(new MultivariateFunction() { - public double value(double[] params) { - Vector2D center = new Vector2D(params[0], params[1]); - double radius = getRadius(center); - double sum = 0; - for (Vector2D point : points) { - double di = point.distance(center) - radius; - sum += di * di; - } - return sum; - } - }); + return new ObjectiveFunction(params -> { + Vector2D center = new Vector2D(params[0], params[1]); + double radius = getRadius(center); + double sum = 0; + for (Vector2D point : points) { + double di = point.distance(center) - radius; + sum += di * di; + } + return sum; + }); } public ObjectiveFunctionGradient getObjectiveFunctionGradient() { - return new ObjectiveFunctionGradient(new MultivariateVectorFunction() { - public double[] value(double[] params) { - Vector2D center = new Vector2D(params[0], params[1]); - double radius = getRadius(center); - // gradient of the sum of squared residuals - double dJdX = 0; - double dJdY = 0; - for (Vector2D pk : points) { - double dk = pk.distance(center); - dJdX += (center.getX() - pk.getX()) * (dk - radius) / dk; - dJdY += (center.getY() - pk.getY()) * (dk - radius) / dk; - } - dJdX *= 2; - dJdY *= 2; + return new ObjectiveFunctionGradient(params -> { + Vector2D center = new Vector2D(params[0], params[1]); + double radius = getRadius(center); + // gradient of the sum of squared residuals + double dJdX = 0; + double dJdY = 0; + for (Vector2D pk : points) { + double dk = pk.distance(center); + dJdX += (center.getX() - pk.getX()) * (dk - radius) / dk; + dJdY += (center.getY() - pk.getY()) * (dk - radius) / dk; + } + dJdX *= 2; + dJdY *= 2; - return new double[] { dJdX, dJdY }; - } - }); + return new double[] { dJdX, dJdY }; + }); } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizerTest.java index 1f54e6a4a..771a675b1 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/gradient/NonLinearConjugateGradientOptimizerTest.java @@ -228,18 +228,16 @@ void testTwoSets() { }, new double[] { 2, -9, 2, 2, 1 + epsilon * epsilon, 2}); final Preconditioner preconditioner - = new Preconditioner() { - public double[] precondition(double[] point, double[] r) { - double[] d = r.clone(); - d[0] /= 72.0; - d[1] /= 30.0; - d[2] /= 314.0; - d[3] /= 260.0; - d[4] /= 2 * (1 + epsilon * epsilon); - d[5] /= 4.0; - return d; - } - }; + = (point, r) -> { + double[] d = r.clone(); + d[0] /= 72.0; + d[1] /= 30.0; + d[2] /= 314.0; + d[3] /= 260.0; + d[4] /= 2 * (1 + epsilon * epsilon); + d[5] /= 4.0; + return d; + }; NonLinearConjugateGradientOptimizer optimizer = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, @@ -455,33 +453,29 @@ public LinearProblem(double[][] factors, } public ObjectiveFunction getObjectiveFunction() { - return new ObjectiveFunction(new MultivariateFunction() { - public double value(double[] point) { - double[] y = factors.operate(point); - double sum = 0; - for (int i = 0; i < y.length; ++i) { - double ri = y[i] - target[i]; - sum += ri * ri; - } - return sum; - } - }); + return new ObjectiveFunction(point -> { + double[] y = factors.operate(point); + double sum = 0; + for (int i = 0; i < y.length; ++i) { + double ri = y[i] - target[i]; + sum += ri * ri; + } + return sum; + }); } public ObjectiveFunctionGradient getObjectiveFunctionGradient() { - return new ObjectiveFunctionGradient(new MultivariateVectorFunction() { - public double[] value(double[] point) { - double[] r = factors.operate(point); - for (int i = 0; i < r.length; ++i) { - r[i] -= target[i]; - } - double[] p = factors.transpose().operate(r); - for (int i = 0; i < p.length; ++i) { - p[i] *= 2; - } - return p; - } - }); + return new ObjectiveFunctionGradient(point -> { + double[] r = factors.operate(point); + for (int i = 0; i < r.length; ++i) { + r[i] -= target[i]; + } + double[] p = factors.transpose().operate(r); + for (int i = 0; i < p.length; ++i) { + p[i] *= 2; + } + return p; + }); } } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java index ae0c00050..5a0100db3 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java @@ -381,13 +381,11 @@ void testMath864() { final CMAESOptimizer optimizer = new CMAESOptimizer(30000, 0, true, 10, 0, new MersenneTwister(), false, null); - final MultivariateFunction fitnessFunction = new MultivariateFunction() { - public double value(double[] parameters) { - final double target = 1; - final double error = target - parameters[0]; - return error * error; - } - }; + final MultivariateFunction fitnessFunction = parameters -> { + final double target = 1; + final double error = target - parameters[0]; + return error * error; + }; final double[] start = { 0 }; final double[] lower = { -1e6 }; @@ -412,13 +410,11 @@ void testFitAccuracyDependsOnBoundary() { final CMAESOptimizer optimizer = new CMAESOptimizer(30000, 0, true, 10, 0, new MersenneTwister(), false, null); - final MultivariateFunction fitnessFunction = new MultivariateFunction() { - public double value(double[] parameters) { - final double target = 11.1; - final double error = target - parameters[0]; - return error * error; - } - }; + final MultivariateFunction fitnessFunction = parameters -> { + final double target = 11.1; + final double error = target - parameters[0]; + return error * error; + }; final double[] start = { 1 }; diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/PowellOptimizerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/PowellOptimizerTest.java index 0290eabce..0bc6de93b 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/PowellOptimizerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/PowellOptimizerTest.java @@ -87,13 +87,11 @@ void testSumSinc() { @Test void testQuadratic() { - final MultivariateFunction func = new MultivariateFunction() { - public double value(double[] x) { - final double a = x[0] - 1; - final double b = x[1] - 1; - return a * a + b * b + 1; - } - }; + final MultivariateFunction func = x -> { + final double a = x[0] - 1; + final double b = x[1] - 1; + return a * a + b * b + 1; + }; int dim = 2; final double[] minPoint = new double[dim]; @@ -118,13 +116,11 @@ public double value(double[] x) { @Test void testMaximizeQuadratic() { - final MultivariateFunction func = new MultivariateFunction() { - public double value(double[] x) { - final double a = x[0] - 1; - final double b = x[1] - 1; - return -a * a - b * b + 1; - } - }; + final MultivariateFunction func = x -> { + final double a = x[0] - 1; + final double b = x[1] - 1; + return -a * a - b * b + 1; + }; int dim = 2; final double[] maxPoint = new double[dim]; @@ -156,13 +152,11 @@ public double value(double[] x) { */ @Test void testRelativeToleranceOnScaledValues() { - final MultivariateFunction func = new MultivariateFunction() { - public double value(double[] x) { - final double a = x[0] - 1; - final double b = x[1] - 1; - return a * a * FastMath.sqrt(FastMath.abs(a)) + b * b + 1; - } - }; + final MultivariateFunction func = x -> { + final double a = x[0] - 1; + final double b = x[1] - 1; + return a * a * FastMath.sqrt(FastMath.abs(a)) + b * b + 1; + }; int dim = 2; final double[] minPoint = new double[dim]; @@ -191,11 +185,7 @@ public double value(double[] x) { final int funcEvaluations = optim.getEvaluations(); final double scale = 1e10; - final MultivariateFunction funcScaled = new MultivariateFunction() { - public double value(double[] x) { - return scale * func.value(x); - } - }; + final MultivariateFunction funcScaled = x -> scale * func.value(x); final PointValuePair funcScaledResult = optim.optimize(new MaxEval(maxEval), new ObjectiveFunction(funcScaled), diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerMultiDirectionalTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerMultiDirectionalTest.java index 4a53c44d9..19ed31a5e 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerMultiDirectionalTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerMultiDirectionalTest.java @@ -142,14 +142,12 @@ void testMaximize2() { @Test void testRosenbrock() { MultivariateFunction rosenbrock - = new MultivariateFunction() { - public double value(double[] x) { - ++count; - double a = x[1] - x[0] * x[0]; - double b = 1.0 - x[0]; - return 100 * a * a + b * b; - } - }; + = x -> { + ++count; + double a = x[1] - x[0] * x[0]; + double b = 1.0 - x[0]; + return 100 * a * a + b * b; + }; count = 0; SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3); @@ -172,16 +170,14 @@ public double value(double[] x) { @Test void testPowell() { MultivariateFunction powell - = new MultivariateFunction() { - public double value(double[] x) { - ++count; - double a = x[0] + 10 * x[1]; - double b = x[2] - x[3]; - double c = x[1] - 2 * x[2]; - double d = x[0] - x[3]; - return a * a + 5 * b * b + c * c * c * c + 10 * d * d * d * d; - } - }; + = x -> { + ++count; + double a = x[0] + 10 * x[1]; + double b = x[2] - x[3]; + double c = x[1] - 2 * x[2]; + double d = x[0] - x[3]; + return a * a + 5 * b * b + c * c * c * c + 10 * d * d * d * d; + }; count = 0; SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3); diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerNelderMeadTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerNelderMeadTest.java index 72a5ce040..897278a62 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerNelderMeadTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/scalar/noderiv/SimplexOptimizerNelderMeadTest.java @@ -187,11 +187,7 @@ void testLeastSquares1() { { 1, 0 }, { 0, 1 } }, false); - LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() { - public double[] value(double[] variables) { - return factors.operate(variables); - } - }, new double[] { 2.0, -3.0 }); + LeastSquaresConverter ls = new LeastSquaresConverter(variables -> factors.operate(variables), new double[] { 2.0, -3.0 }); SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6); PointValuePair optimum = optimizer.optimize(new MaxEval(200), @@ -213,11 +209,7 @@ void testLeastSquares2() { { 1, 0 }, { 0, 1 } }, false); - LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() { - public double[] value(double[] variables) { - return factors.operate(variables); - } - }, new double[] { 2, -3 }, new double[] { 10, 0.1 }); + LeastSquaresConverter ls = new LeastSquaresConverter(variables -> factors.operate(variables), new double[] { 2, -3 }, new double[] { 10, 0.1 }); SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6); PointValuePair optimum = optimizer.optimize(new MaxEval(200), @@ -239,11 +231,7 @@ void testLeastSquares3() { { 1, 0 }, { 0, 1 } }, false); - LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() { - public double[] value(double[] variables) { - return factors.operate(variables); - } - }, new double[] { 2, -3 }, new Array2DRowRealMatrix(new double [][] { + LeastSquaresConverter ls = new LeastSquaresConverter(variables -> factors.operate(variables), new double[] { 2, -3 }, new Array2DRowRealMatrix(new double [][] { { 1, 1.2 }, { 1.2, 2 } })); SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6); diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java index e87a117c5..1579812e0 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractLeastSquaresOptimizerAbstractTest.java @@ -135,22 +135,18 @@ public void testGetIterations() { .target(new double[]{1}) .weight(new DiagonalMatrix(new double[]{1})) .start(new double[]{3}) - .model(new MultivariateJacobianFunction() { - public Pair value(final RealVector point) { - return new Pair( - new ArrayRealVector( - new double[]{ - FastMath.pow(point.getEntry(0), 4) - }, - false), - new Array2DRowRealMatrix( - new double[][]{ - {0.25 * FastMath.pow(point.getEntry(0), 3)} - }, - false) - ); - } - }) + .model(point -> new Pair( + new ArrayRealVector( + new double[]{ + FastMath.pow(point.getEntry(0), 4) + }, + false), + new Array2DRowRealMatrix( + new double[][]{ + {0.25 * FastMath.pow(point.getEntry(0), 3)} + }, + false) + )) .build(); Optimum optimum = optimizer.optimize(lsp); @@ -249,9 +245,7 @@ public void testNonInvertible() throws Exception { optimizer.optimize(problem.getBuilder().build()); customFail(optimizer); - } catch (MathIllegalArgumentException miae) { - // expected - } catch (MathIllegalStateException mise) { + } catch (MathIllegalArgumentException | MathIllegalStateException miae) { // expected } } @@ -555,16 +549,14 @@ public void testPointCopy() { final boolean[] checked = {false}; final LeastSquaresBuilder builder = problem.getBuilder() - .checker(new ConvergenceChecker() { - public boolean converged(int iteration, Evaluation previous, Evaluation current) { - assertThat( - previous.getPoint(), - not(sameInstance(current.getPoint()))); - assertArrayEquals(new double[3], previous.getPoint().toArray(), 0); - assertArrayEquals(new double[] {1, 2, 3}, current.getPoint().toArray(), TOl); - checked[0] = true; - return true; - } + .checker((iteration, previous, current) -> { + assertThat( + previous.getPoint(), + not(sameInstance(current.getPoint()))); + assertArrayEquals(new double[3], previous.getPoint().toArray(), 0); + assertArrayEquals(new double[] {1, 2, 3}, current.getPoint().toArray(), TOl); + checked[0] = true; + return true; }); optimizer.optimize(builder.build()); @@ -585,19 +577,11 @@ public double[] getTarget() { } public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(double[] params) { - return factors.operate(params); - } - }; + return params -> factors.operate(params); } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] params) { - return factors.getData(); - } - }; + return params -> factors.getData(); } public LeastSquaresBuilder getBuilder() { diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractSequentialLeastSquaresOptimizerAbstractTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractSequentialLeastSquaresOptimizerAbstractTest.java index 0f08f330c..0ba9e8626 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractSequentialLeastSquaresOptimizerAbstractTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/AbstractSequentialLeastSquaresOptimizerAbstractTest.java @@ -131,22 +131,18 @@ public void testGetIterations() { .target(new double[]{1}) .weight(new DiagonalMatrix(new double[]{1})) .start(new double[]{3}) - .model(new MultivariateJacobianFunction() { - public Pair value(final RealVector point) { - return new Pair( - new ArrayRealVector( - new double[]{ - FastMath.pow(point.getEntry(0), 4) - }, - false), - new Array2DRowRealMatrix( - new double[][]{ - {0.25 * FastMath.pow(point.getEntry(0), 3)} - }, - false) - ); - } - }) + .model(point -> new Pair( + new ArrayRealVector( + new double[]{ + FastMath.pow(point.getEntry(0), 4) + }, + false), + new Array2DRowRealMatrix( + new double[][]{ + {0.25 * FastMath.pow(point.getEntry(0), 3)} + }, + false) + )) .build(); defineOptimizer(null); @@ -254,9 +250,7 @@ public void testNonInvertible() throws Exception { optimizer.optimize(problem.getBuilder().build()); customFail(optimizer); - } catch (MathIllegalArgumentException miae) { - // expected - } catch (MathIllegalStateException mise) { + } catch (MathIllegalArgumentException | MathIllegalStateException miae) { // expected } } @@ -506,16 +500,14 @@ public void testPointCopy() { final boolean[] checked = {false}; final LeastSquaresBuilder builder = problem.getBuilder() - .checker(new ConvergenceChecker() { - public boolean converged(int iteration, Evaluation previous, Evaluation current) { - assertThat( - previous.getPoint(), - not(sameInstance(current.getPoint()))); - assertArrayEquals(new double[3], previous.getPoint().toArray(), 0); - assertArrayEquals(new double[] {1, 2, 3}, current.getPoint().toArray(), TOl); - checked[0] = true; - return true; - } + .checker((iteration, previous, current) -> { + assertThat( + previous.getPoint(), + not(sameInstance(current.getPoint()))); + assertArrayEquals(new double[3], previous.getPoint().toArray(), 0); + assertArrayEquals(new double[] {1, 2, 3}, current.getPoint().toArray(), TOl); + checked[0] = true; + return true; }); defineOptimizer(null); optimizer.optimize(builder.build()); @@ -563,19 +555,11 @@ public double[] getTarget() { } public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(double[] params) { - return factors.operate(params); - } - }; + return params -> factors.operate(params); } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] params) { - return factors.getData(); - } - }; + return params -> factors.getData(); } public LeastSquaresBuilder getBuilder() { diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleProblem.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleProblem.java index 1c8e9b40e..f7d7f339c 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleProblem.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleProblem.java @@ -107,56 +107,50 @@ public double[] weight() { } public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(double[] params) { - final double cx = params[0]; - final double cy = params[1]; - final double r = params[2]; - - final double[] model = new double[points.size() * 2]; - - final double deltaTheta = MathUtils.TWO_PI / resolution; - for (int i = 0; i < points.size(); i++) { - final double[] p = points.get(i); - final double px = p[0]; - final double py = p[1]; - - double bestX = 0; - double bestY = 0; - double dMin = Double.POSITIVE_INFINITY; - - // Find the angle for which the circle passes closest to the - // current point (using a resolution of 100 points along the - // circumference). - for (double theta = 0; theta <= MathUtils.TWO_PI; theta += deltaTheta) { - final double currentX = cx + r * FastMath.cos(theta); - final double currentY = cy + r * FastMath.sin(theta); - final double dX = currentX - px; - final double dY = currentY - py; - final double d = dX * dX + dY * dY; - if (d < dMin) { - dMin = d; - bestX = currentX; - bestY = currentY; - } + return params -> { + final double cx = params[0]; + final double cy = params[1]; + final double r = params[2]; + + final double[] model = new double[points.size() * 2]; + + final double deltaTheta = MathUtils.TWO_PI / resolution; + for (int i = 0; i < points.size(); i++) { + final double[] p = points.get(i); + final double px = p[0]; + final double py = p[1]; + + double bestX = 0; + double bestY = 0; + double dMin = Double.POSITIVE_INFINITY; + + // Find the angle for which the circle passes closest to the + // current point (using a resolution of 100 points along the + // circumference). + for (double theta = 0; theta <= MathUtils.TWO_PI; theta += deltaTheta) { + final double currentX = cx + r * FastMath.cos(theta); + final double currentY = cy + r * FastMath.sin(theta); + final double dX = currentX - px; + final double dY = currentY - py; + final double d = dX * dX + dY * dY; + if (d < dMin) { + dMin = d; + bestX = currentX; + bestY = currentY; } - - final int index = i * 2; - model[index] = bestX; - model[index + 1] = bestY; } - return model; + final int index = i * 2; + model[index] = bestX; + model[index + 1] = bestY; } + + return model; }; } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] point) { - return jacobian(point); - } - }; + return point -> jacobian(point); } private double[][] jacobian(double[] params) { diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleVectorial.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleVectorial.java index 5f37e06bc..679569e6e 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleVectorial.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/CircleVectorial.java @@ -54,47 +54,43 @@ public double getRadius(Vector2D center) { } public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(double[] params) { - Vector2D center = new Vector2D(params[0], params[1]); - double radius = getRadius(center); - double[] residuals = new double[points.size()]; - for (int i = 0; i < residuals.length; i++) { - residuals[i] = points.get(i).distance(center) - radius; - } - - return residuals; + return params -> { + Vector2D center = new Vector2D(params[0], params[1]); + double radius = getRadius(center); + double[] residuals = new double[points.size()]; + for (int i = 0; i < residuals.length; i++) { + residuals[i] = points.get(i).distance(center) - radius; } + + return residuals; }; } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] params) { - final int n = points.size(); - final Vector2D center = new Vector2D(params[0], params[1]); - - double dRdX = 0; - double dRdY = 0; - for (Vector2D pk : points) { - double dk = pk.distance(center); - dRdX += (center.getX() - pk.getX()) / dk; - dRdY += (center.getY() - pk.getY()) / dk; - } - dRdX /= n; - dRdY /= n; + return params -> { + final int n = points.size(); + final Vector2D center = new Vector2D(params[0], params[1]); - // Jacobian of the radius residuals. - double[][] jacobian = new double[n][2]; - for (int i = 0; i < n; i++) { - final Vector2D pi = points.get(i); - final double di = pi.distance(center); - jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX; - jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY; - } + double dRdX = 0; + double dRdY = 0; + for (Vector2D pk : points) { + double dk = pk.distance(center); + dRdX += (center.getX() - pk.getX()) / dk; + dRdY += (center.getY() - pk.getY()) / dk; + } + dRdX /= n; + dRdY /= n; - return jacobian; + // Jacobian of the radius residuals. + double[][] jacobian = new double[n][2]; + for (int i = 0; i < n; i++) { + final Vector2D pi = points.get(i); + final double di = pi.distance(center); + jacobian[i][0] = (center.getX() - pi.getX()) / di - dRdX; + jacobian[i][1] = (center.getY() - pi.getY()) / di - dRdY; } + + return jacobian; }; } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/EvaluationTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/EvaluationTest.java index a6e2cafe6..3a184d1c0 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/EvaluationTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/EvaluationTest.java @@ -72,14 +72,10 @@ void testComputeResiduals() { RealVector point = new ArrayRealVector(2); Evaluation evaluation = new LeastSquaresBuilder() .target(new ArrayRealVector(new double[]{3,-1})) - .model(new MultivariateJacobianFunction() { - public Pair value(RealVector point) { - return new Pair( - new ArrayRealVector(new double[]{1, 2}), - MatrixUtils.createRealIdentityMatrix(2) - ); - } - }) + .model(point1 -> new Pair( + new ArrayRealVector(new double[]{1, 2}), + MatrixUtils.createRealIdentityMatrix(2) + )) .weight(MatrixUtils.createRealIdentityMatrix(2)) .build() .evaluate(point); @@ -96,14 +92,10 @@ void testComputeCovariance() throws IOException { //setup RealVector point = new ArrayRealVector(2); Evaluation evaluation = new LeastSquaresBuilder() - .model(new MultivariateJacobianFunction() { - public Pair value(RealVector point) { - return new Pair( - new ArrayRealVector(2), - MatrixUtils.createRealDiagonalMatrix(new double[]{1, 1e-2}) - ); - } - }) + .model(point1 -> new Pair( + new ArrayRealVector(2), + MatrixUtils.createRealDiagonalMatrix(new double[]{1, 1e-2}) + )) .weight(MatrixUtils.createRealDiagonalMatrix(new double[]{1, 1})) .target(new ArrayRealVector(2)) .build() @@ -132,17 +124,15 @@ void testComputeValueAndJacobian() { final RealVector point = new ArrayRealVector(new double[]{1, 2}); Evaluation evaluation = new LeastSquaresBuilder() .weight(new DiagonalMatrix(new double[]{16, 4})) - .model(new MultivariateJacobianFunction() { - public Pair value(RealVector actualPoint) { - //verify correct values passed in - assertArrayEquals( - point.toArray(), actualPoint.toArray(), Precision.EPSILON); - //return values - return new Pair( - new ArrayRealVector(new double[]{3, 4}), - MatrixUtils.createRealMatrix(new double[][]{{5, 6}, {7, 8}}) - ); - } + .model(actualPoint -> { + //verify correct values passed in + assertArrayEquals( + point.toArray(), actualPoint.toArray(), Precision.EPSILON); + //return values + return new Pair( + new ArrayRealVector(new double[]{3, 4}), + MatrixUtils.createRealMatrix(new double[][]{{5, 6}, {7, 8}}) + ); }) .target(new double[2]) .build() @@ -259,11 +249,7 @@ void testLazyEvaluationPrecondition() { // "ValueAndJacobianFunction" is required but we implement only // "MultivariateJacobianFunction". - final MultivariateJacobianFunction m1 = new MultivariateJacobianFunction() { - public Pair value(RealVector notUsed) { - return new Pair(null, null); - } - }; + final MultivariateJacobianFunction m1 = notUsed -> new Pair(null, null); try { // Should throw. @@ -312,19 +298,15 @@ void testDirectEvaluation() { /** Used for testing direct vs lazy evaluation. */ private MultivariateVectorFunction dummyModel() { - return new MultivariateVectorFunction() { - public double[] value(double[] p) { - throw new RuntimeException("dummyModel"); - } + return p -> { + throw new RuntimeException("dummyModel"); }; } /** Used for testing direct vs lazy evaluation. */ private MultivariateMatrixFunction dummyJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] p) { - throw new RuntimeException("dummyJacobian"); - } + return p -> { + throw new RuntimeException("dummyJacobian"); }; } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/GaussNewtonOptimizerWithQRNormalTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/GaussNewtonOptimizerWithQRNormalTest.java index 00097d1c1..61ac6287f 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/GaussNewtonOptimizerWithQRNormalTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/GaussNewtonOptimizerWithQRNormalTest.java @@ -123,10 +123,8 @@ public void testHahn1() throws IOException { @Override @Test public void testMoreEstimatedParametersSimple() { - assertThrows(MathIllegalStateException.class, () -> { - // reduced numerical stability when forming the normal equations - super.testMoreEstimatedParametersSimple(); - }); + // reduced numerical stability when forming the normal equations + assertThrows(MathIllegalStateException.class, super::testMoreEstimatedParametersSimple); } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/LevenbergMarquardtOptimizerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/LevenbergMarquardtOptimizerTest.java index c07f0306b..35f95e033 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/LevenbergMarquardtOptimizerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/LevenbergMarquardtOptimizerTest.java @@ -153,9 +153,7 @@ private void checkEstimate(CircleVectorial circle, assertFalse(shouldFail); //TODO check it got the right answer - } catch (MathIllegalArgumentException ee) { - assertTrue(shouldFail); - } catch (MathIllegalStateException ee) { + } catch (MathIllegalArgumentException | MathIllegalStateException ee) { assertTrue(shouldFail); } } @@ -327,12 +325,10 @@ void testParameterValidator() { // Build a new problem with a validator that amounts to cheating. final ParameterValidator cheatValidator - = new ParameterValidator() { - public RealVector validate(RealVector params) { - // Cheat: return the optimum found previously. - return optimum.getPoint(); - } - }; + = params -> { + // Cheat: return the optimum found previously. + return optimum.getPoint(); + }; final Optimum cheatOptimum = optimizer.optimize(builder(circle).maxIterations(50).start(init).parameterValidator(cheatValidator).build()); @@ -346,11 +342,7 @@ void testEvaluationCount() { //setup LeastSquaresProblem lsp = new LinearProblem(new double[][] {{1}}, new double[] {1}) .getBuilder() - .checker(new ConvergenceChecker() { - public boolean converged(int iteration, Evaluation previous, Evaluation current) { - return true; - } - }) + .checker((iteration, previous, current) -> true) .build(); //action @@ -377,40 +369,36 @@ public void addPoint(double t, double c) { } public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(double[] params) { - double[] values = new double[time.size()]; - for (int i = 0; i < values.length; ++i) { - final double t = time.get(i); - values[i] = params[0] + - params[1] * FastMath.exp(-t / params[3]) + - params[2] * FastMath.exp(-t / params[4]); - } - return values; + return params -> { + double[] values = new double[time.size()]; + for (int i = 0; i < values.length; ++i) { + final double t = time.get(i); + values[i] = params[0] + + params[1] * FastMath.exp(-t / params[3]) + + params[2] * FastMath.exp(-t / params[4]); } + return values; }; } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] params) { - double[][] jacobian = new double[time.size()][5]; - - for (int i = 0; i < jacobian.length; ++i) { - final double t = time.get(i); - jacobian[i][0] = 1; - - final double p3 = params[3]; - final double p4 = params[4]; - final double tOp3 = t / p3; - final double tOp4 = t / p4; - jacobian[i][1] = FastMath.exp(-tOp3); - jacobian[i][2] = FastMath.exp(-tOp4); - jacobian[i][3] = params[1] * FastMath.exp(-tOp3) * tOp3 / p3; - jacobian[i][4] = params[2] * FastMath.exp(-tOp4) * tOp4 / p4; - } - return jacobian; + return params -> { + double[][] jacobian = new double[time.size()][5]; + + for (int i = 0; i < jacobian.length; ++i) { + final double t = time.get(i); + jacobian[i][0] = 1; + + final double p3 = params[3]; + final double p4 = params[4]; + final double tOp3 = t / p3; + final double tOp4 = t / p4; + jacobian[i][1] = FastMath.exp(-tOp3); + jacobian[i][2] = FastMath.exp(-tOp4); + jacobian[i][3] = params[1] * FastMath.exp(-tOp3) * tOp3 / p3; + jacobian[i][4] = params[2] * FastMath.exp(-tOp4) * tOp4 / p4; } + return jacobian; }; } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/MinpackTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/MinpackTest.java index c04b4f65e..62719bf45 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/MinpackTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/MinpackTest.java @@ -599,19 +599,11 @@ public void checkTheoreticalMinParams(double[] params) { } public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(double[] point) { - return computeValue(point); - } - }; + return point -> computeValue(point); } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] point) { - return computeJacobian(point); - } - }; + return point -> computeJacobian(point); } public abstract double[][] computeJacobian(double[] variables); diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/SequentialGaussNewtonOptimizerWithQRNormalTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/SequentialGaussNewtonOptimizerWithQRNormalTest.java index 808b810b4..646a727d0 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/SequentialGaussNewtonOptimizerWithQRNormalTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/SequentialGaussNewtonOptimizerWithQRNormalTest.java @@ -113,10 +113,8 @@ public void testHahn1() throws IOException { @Override @Test public void testMoreEstimatedParametersSimple() { - assertThrows(MathIllegalStateException.class, () -> { - // reduced numerical stability when forming the normal equations - super.testMoreEstimatedParametersSimple(); - }); + // reduced numerical stability when forming the normal equations + assertThrows(MathIllegalStateException.class, super::testMoreEstimatedParametersSimple); } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StatisticalReferenceDataset.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StatisticalReferenceDataset.java index 807a6b5f0..50aeb65cf 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StatisticalReferenceDataset.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StatisticalReferenceDataset.java @@ -148,29 +148,24 @@ public StatisticalReferenceDataset(final BufferedReader in) class LeastSquaresProblem { public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(final double[] a) { - final int n = getNumObservations(); - final double[] yhat = new double[n]; - for (int i = 0; i < n; i++) { - yhat[i] = getModelValue(getX(i), a); - } - return yhat; + return a -> { + final int n = getNumObservations(); + final double[] yhat = new double[n]; + for (int i = 0; i < n; i++) { + yhat[i] = getModelValue(getX(i), a); } + return yhat; }; } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(final double[] a) - throws IllegalArgumentException { - final int n = getNumObservations(); - final double[][] j = new double[n][]; - for (int i = 0; i < n; i++) { - j[i] = getModelDerivatives(getX(i), a); - } - return j; + return a -> { + final int n = getNumObservations(); + final double[][] j = new double[n][]; + for (int i = 0; i < n; i++) { + j[i] = getModelDerivatives(getX(i), a); } + return j; }; } } diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StraightLineProblem.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StraightLineProblem.java index f8aeea49a..b0b00e065 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StraightLineProblem.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/nonlinear/vector/leastsquares/StraightLineProblem.java @@ -101,27 +101,21 @@ public double[] weight() { } public MultivariateVectorFunction getModelFunction() { - return new MultivariateVectorFunction() { - public double[] value(double[] params) { - final Model line = new Model(params[0], params[1]); + return params -> { + final Model line = new Model(params[0], params[1]); - final double[] model = new double[points.size()]; - for (int i = 0; i < points.size(); i++) { - final double[] p = points.get(i); - model[i] = line.value(p[0]); - } - - return model; + final double[] model = new double[points.size()]; + for (int i = 0; i < points.size(); i++) { + final double[] p = points.get(i); + model[i] = line.value(p[0]); } + + return model; }; } public MultivariateMatrixFunction getModelFunctionJacobian() { - return new MultivariateMatrixFunction() { - public double[][] value(double[] point) { - return jacobian(point); - } - }; + return point -> jacobian(point); } /** diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BracketFinderTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BracketFinderTest.java index 43dfaa450..d5d880a4a 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BracketFinderTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BracketFinderTest.java @@ -78,11 +78,7 @@ public double value(double x) { @Test void testMinimumIsOnIntervalBoundary() { - final UnivariateFunction func = new UnivariateFunction() { - public double value(double x) { - return x * x; - } - }; + final UnivariateFunction func = x -> x * x; final BracketFinder bFind = new BracketFinder(); @@ -97,11 +93,7 @@ public double value(double x) { @Test void testIntervalBoundsOrdering() { - final UnivariateFunction func = new UnivariateFunction() { - public double value(double x) { - return x * x; - } - }; + final UnivariateFunction func = x -> x * x; final BracketFinder bFind = new BracketFinder(); diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BrentOptimizerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BrentOptimizerTest.java index 41920b9c0..2883169f6 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BrentOptimizerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/BrentOptimizerTest.java @@ -91,18 +91,15 @@ void testSinMinWithValueChecker() { void testBoundaries() { final double lower = -1.0; final double upper = +1.0; - UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - if (x < lower) { - throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_SMALL, - x, lower); - } else if (x > upper) { - throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE, - x, upper); - } else { - return x; - } + UnivariateFunction f = x -> { + if (x < lower) { + throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_SMALL, + x, lower); + } else if (x > upper) { + throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE, + x, upper); + } else { + return x; } }; UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-14); @@ -219,17 +216,14 @@ void testMinEndpoints() { @Test void testMath832() { - final UnivariateFunction f = new UnivariateFunction() { - @Override - public double value(double x) { - final double sqrtX = FastMath.sqrt(x); - final double a = 1e2 * sqrtX; - final double b = 1e6 / x; - final double c = 1e4 / sqrtX; + final UnivariateFunction f = x -> { + final double sqrtX = FastMath.sqrt(x); + final double a = 1e2 * sqrtX; + final double b = 1e6 / x; + final double c = 1e4 / sqrtX; - return a + b + c; - } - }; + return a + b + c; + }; UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-8); final double result = optimizer.optimize(new MaxEval(1483), diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/MultiStartUnivariateOptimizerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/MultiStartUnivariateOptimizerTest.java index c0124d3a2..6793e6fd6 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/MultiStartUnivariateOptimizerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/MultiStartUnivariateOptimizerTest.java @@ -114,14 +114,12 @@ void testQuinticMin() { @Test void testBadFunction() { - UnivariateFunction f = new UnivariateFunction() { - public double value(double x) { - if (x < 0) { - throw new LocalException(); - } - return 0; - } - }; + UnivariateFunction f = x -> { + if (x < 0) { + throw new LocalException(); + } + return 0; + }; UnivariateOptimizer underlying = new BrentOptimizer(1e-9, 1e-14); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(4312000053L); diff --git a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/SimpleUnivariateValueCheckerTest.java b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/SimpleUnivariateValueCheckerTest.java index 0c7c958d9..9ffaaef0d 100644 --- a/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/SimpleUnivariateValueCheckerTest.java +++ b/hipparchus-optim/src/test/java/org/hipparchus/optim/univariate/SimpleUnivariateValueCheckerTest.java @@ -31,9 +31,7 @@ class SimpleUnivariateValueCheckerTest { @Test void testIterationCheckPrecondition() { - assertThrows(MathIllegalArgumentException.class, () -> { - new SimpleUnivariateValueChecker(1e-1, 1e-2, 0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new SimpleUnivariateValueChecker(1e-1, 1e-2, 0)); } @Test diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/data/CertifiedDataAbstractTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/data/CertifiedDataAbstractTest.java index 979ffca69..acb861ae0 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/data/CertifiedDataAbstractTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/data/CertifiedDataAbstractTest.java @@ -155,10 +155,8 @@ protected Double getProperty(Object bean, String name) { } } catch (NoSuchMethodException nsme) { // ignored - } catch (InvocationTargetException ite) { + } catch (InvocationTargetException | IllegalAccessException ite) { fail(ite.getMessage()); - } catch (IllegalAccessException iae) { - fail(iae.getMessage()); } return null; } diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/PSquarePercentileTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/PSquarePercentileTest.java index 0bbd68fa6..d819fd7d1 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/PSquarePercentileTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/PSquarePercentileTest.java @@ -181,18 +181,14 @@ void testMiscellaniousFunctionsInMarkers() { @Test void testMarkersOORLow() { - assertThrows(MathIllegalArgumentException.class, () -> { - PSquarePercentile.newMarkers( - Arrays.asList(new Double[]{0.02, 1.18, 9.15, 21.91, 38.62}), 0.5).estimate(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> PSquarePercentile.newMarkers( + Arrays.asList(new Double[]{0.02, 1.18, 9.15, 21.91, 38.62}), 0.5).estimate(0)); } @Test void testMarkersOORHigh() { - assertThrows(MathIllegalArgumentException.class, () -> { - PSquarePercentile.newMarkers( - Arrays.asList(new Double[]{0.02, 1.18, 9.15, 21.91, 38.62}), 0.5).estimate(5); - }); + assertThrows(MathIllegalArgumentException.class, () -> PSquarePercentile.newMarkers( + Arrays.asList(new Double[]{0.02, 1.18, 9.15, 21.91, 38.62}), 0.5).estimate(5)); } @Test @@ -396,9 +392,7 @@ void testPercentile() { @Test void testInitial() { - assertThrows(MathIllegalArgumentException.class, () -> { - PSquarePercentile.newMarkers(new ArrayList(), 0.5); - }); + assertThrows(MathIllegalArgumentException.class, () -> PSquarePercentile.newMarkers(new ArrayList(), 0.5)); } @Test diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/RandomPercentileTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/RandomPercentileTest.java index 9d8a7bea8..9ca1c6257 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/RandomPercentileTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/descriptive/rank/RandomPercentileTest.java @@ -679,16 +679,12 @@ void testMaxValuesRetained() { @Test void testMaxValuesRetained0Epsilon() { - assertThrows(MathIllegalArgumentException.class, () -> { - RandomPercentile.maxValuesRetained(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> RandomPercentile.maxValuesRetained(0)); } @Test void testMaxValuesRetained1Epsilon() { - assertThrows(MathIllegalArgumentException.class, () -> { - RandomPercentile.maxValuesRetained(1); - }); + assertThrows(MathIllegalArgumentException.class, () -> RandomPercentile.maxValuesRetained(1)); } diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/fitting/EmpiricalDistributionTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/fitting/EmpiricalDistributionTest.java index 94a4d7f8f..03aa82521 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/fitting/EmpiricalDistributionTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/fitting/EmpiricalDistributionTest.java @@ -97,9 +97,7 @@ public void setUp() { // MATH-1279 @Test void testPrecondition1() { - assertThrows(MathIllegalArgumentException.class, () -> { - new EmpiricalDistribution(0); - }); + assertThrows(MathIllegalArgumentException.class, () -> new EmpiricalDistribution(0)); } /** @@ -251,23 +249,17 @@ void testSerialization() { @Test void testLoadNullDoubleArray() { - assertThrows(NullArgumentException.class, () -> { - new EmpiricalDistribution().load((double[]) null); - }); + assertThrows(NullArgumentException.class, () -> new EmpiricalDistribution().load((double[]) null)); } @Test void testLoadNullURL() throws Exception { - assertThrows(NullArgumentException.class, () -> { - new EmpiricalDistribution().load((URL) null); - }); + assertThrows(NullArgumentException.class, () -> new EmpiricalDistribution().load((URL) null)); } @Test void testLoadNullFile() throws Exception { - assertThrows(NullArgumentException.class, () -> { - new EmpiricalDistribution().load((File) null); - }); + assertThrows(NullArgumentException.class, () -> new EmpiricalDistribution().load((File) null)); } /** @@ -419,12 +411,7 @@ public void testDensityIntegrals() { final double tol = 1.0e-9; final BaseAbstractUnivariateIntegrator integrator = new IterativeLegendreGaussIntegrator(5, 1.0e-12, 1.0e-10); - final UnivariateFunction d = new UnivariateFunction() { - @Override - public double value(double x) { - return distribution.density(x); - } - }; + final UnivariateFunction d = x -> distribution.density(x); final double[] lower = {0, 5, 1000, 5001, 9995}; final double[] upper = {5, 12, 1030, 5010, 10000}; for (int i = 1; i < 5; i++) { diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/inference/WilcoxonSignedRankTestTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/inference/WilcoxonSignedRankTestTest.java index d6886ab49..5e922dcfe 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/inference/WilcoxonSignedRankTestTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/inference/WilcoxonSignedRankTestTest.java @@ -271,13 +271,11 @@ void testWilcoxonSignedRankInputValidation() { @Test void testBadInputAllTies() { - assertThrows(MathIllegalArgumentException.class, () -> { - testStatistic.wilcoxonSignedRankTest(new double[]{ - 1.0, 2.0, 3.0 - }, new double[]{ - 1.0, 2.0, 3.0 - }, true); - }); + assertThrows(MathIllegalArgumentException.class, () -> testStatistic.wilcoxonSignedRankTest(new double[]{ + 1.0, 2.0, 3.0 + }, new double[]{ + 1.0, 2.0, 3.0 + }, true)); } @Test diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/interval/BinomialProportionAbstractTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/interval/BinomialProportionAbstractTest.java index 6f1b51363..160e9c5b9 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/interval/BinomialProportionAbstractTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/interval/BinomialProportionAbstractTest.java @@ -66,36 +66,26 @@ public void setUp() { @Test public void testZeroConfidencelevel() { - assertThrows(MathIllegalArgumentException.class, () -> { - testMethod.calculate(trials, probabilityOfSuccess, 0d); - }); + assertThrows(MathIllegalArgumentException.class, () -> testMethod.calculate(trials, probabilityOfSuccess, 0d)); } @Test public void testOneConfidencelevel() { - assertThrows(MathIllegalArgumentException.class, () -> { - testMethod.calculate(trials, probabilityOfSuccess, 1d); - }); + assertThrows(MathIllegalArgumentException.class, () -> testMethod.calculate(trials, probabilityOfSuccess, 1d)); } @Test public void testZeroTrials() { - assertThrows(MathIllegalArgumentException.class, () -> { - testMethod.calculate(0, 0, confidenceLevel); - }); + assertThrows(MathIllegalArgumentException.class, () -> testMethod.calculate(0, 0, confidenceLevel)); } @Test public void testNegativeSuccesses() { - assertThrows(MathIllegalArgumentException.class, () -> { - testMethod.calculate(trials, -1, confidenceLevel); - }); + assertThrows(MathIllegalArgumentException.class, () -> testMethod.calculate(trials, -1, confidenceLevel)); } @Test public void testSuccessesExceedingTrials() { - assertThrows(MathIllegalArgumentException.class, () -> { - testMethod.calculate(trials, trials + 1, confidenceLevel); - }); + assertThrows(MathIllegalArgumentException.class, () -> testMethod.calculate(trials, trials + 1, confidenceLevel)); } } diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/GLSMultipleLinearRegressionTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/GLSMultipleLinearRegressionTest.java index 3bbd7ef57..fc12e6f45 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/GLSMultipleLinearRegressionTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/GLSMultipleLinearRegressionTest.java @@ -86,16 +86,12 @@ public void setUp(){ @Test void cannotAddXSampleData() { - assertThrows(NullArgumentException.class, () -> { - createRegression().newSampleData(new double[]{}, null, null); - }); + assertThrows(NullArgumentException.class, () -> createRegression().newSampleData(new double[]{}, null, null)); } @Test void cannotAddNullYSampleData() { - assertThrows(NullArgumentException.class, () -> { - createRegression().newSampleData(null, new double[][]{}, null); - }); + assertThrows(NullArgumentException.class, () -> createRegression().newSampleData(null, new double[][]{}, null)); } @Test @@ -110,9 +106,7 @@ void cannotAddSampleDataWithSizeMismatch() { @Test void cannotAddNullCovarianceData() { - assertThrows(MathIllegalArgumentException.class, () -> { - createRegression().newSampleData(new double[]{}, new double[][]{}, null); - }); + assertThrows(MathIllegalArgumentException.class, () -> createRegression().newSampleData(new double[]{}, new double[][]{}, null)); } @Test diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MillerUpdatingRegressionTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MillerUpdatingRegressionTest.java index d9fbb94db..9b67cbfc6 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MillerUpdatingRegressionTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MillerUpdatingRegressionTest.java @@ -113,9 +113,7 @@ void testNegativeTestAddObs() { fail("Should throw MathIllegalArgumentException"); } MillerUpdatingRegression finalInstance = instance; - assertDoesNotThrow(() -> { - finalInstance.addObservation(new double[]{ 1.0, 1.0, 1.0}, 0.0); - }, "Should throw MathIllegalArgumentException"); + assertDoesNotThrow(() -> finalInstance.addObservation(new double[]{ 1.0, 1.0, 1.0}, 0.0), "Should throw MathIllegalArgumentException"); //now we try it without an intercept instance = new MillerUpdatingRegression(3, false); @@ -134,9 +132,7 @@ void testNegativeTestAddObs() { fail("Should throw MathIllegalArgumentException [NOINTERCEPT]"); } MillerUpdatingRegression finalInstance1 = instance; - assertDoesNotThrow(() -> { - finalInstance1.addObservation(new double[]{ 1.0, 1.0, 1.0}, 0.0); - }, "Should throw MathIllegalArgumentException [NOINTERCEPT]"); + assertDoesNotThrow(() -> finalInstance1.addObservation(new double[]{ 1.0, 1.0, 1.0}, 0.0), "Should throw MathIllegalArgumentException [NOINTERCEPT]"); } @Test diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MultipleLinearRegressionAbstractTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MultipleLinearRegressionAbstractTest.java index 25b6c993c..8d7859ac1 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MultipleLinearRegressionAbstractTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/MultipleLinearRegressionAbstractTest.java @@ -139,16 +139,12 @@ public void testNewSampleInsufficientData() { @Test public void testXSampleDataNull() { - assertThrows(NullArgumentException.class, () -> { - createRegression().newXSampleData(null); - }); + assertThrows(NullArgumentException.class, () -> createRegression().newXSampleData(null)); } @Test public void testYSampleDataNull() { - assertThrows(NullArgumentException.class, () -> { - createRegression().newYSampleData(null); - }); + assertThrows(NullArgumentException.class, () -> createRegression().newYSampleData(null)); } } diff --git a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/OLSMultipleLinearRegressionTest.java b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/OLSMultipleLinearRegressionTest.java index c12deba2c..4ec0534f8 100644 --- a/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/OLSMultipleLinearRegressionTest.java +++ b/hipparchus-stat/src/test/java/org/hipparchus/stat/regression/OLSMultipleLinearRegressionTest.java @@ -512,16 +512,12 @@ void testNewSample2() { @Test void testNewSampleDataYNull() { - assertThrows(NullArgumentException.class, () -> { - createRegression().newSampleData(null, new double[][]{}); - }); + assertThrows(NullArgumentException.class, () -> createRegression().newSampleData(null, new double[][]{})); } @Test void testNewSampleDataXNull() { - assertThrows(NullArgumentException.class, () -> { - createRegression().newSampleData(new double[]{}, null); - }); + assertThrows(NullArgumentException.class, () -> createRegression().newSampleData(new double[]{}, null)); } /*