13
13
14
14
class EulerMethodTest {
15
15
16
+ private static class EulerFullTestCase {
17
+ double xStart , xEnd , stepSize , yInitial ;
18
+ BiFunction <Double , Double , Double > equation ;
19
+ int expectedSize ;
20
+ double [] expectedFirstPoint , expectedLastPoint ;
21
+
22
+ EulerFullTestCase (double xStart , double xEnd , double stepSize , double yInitial , BiFunction <Double , Double , Double > equation , int expectedSize , double [] expectedFirstPoint , double [] expectedLastPoint ) {
23
+ this .xStart = xStart ;
24
+ this .xEnd = xEnd ;
25
+ this .stepSize = stepSize ;
26
+ this .yInitial = yInitial ;
27
+ this .equation = equation ;
28
+ this .expectedSize = expectedSize ;
29
+ this .expectedFirstPoint = expectedFirstPoint ;
30
+ this .expectedLastPoint = expectedLastPoint ;
31
+ }
32
+ }
33
+
16
34
@ ParameterizedTest
17
35
@ MethodSource ("eulerStepTestCases" )
18
36
void testEulerStep (double x , double h , double y , BiFunction <Double , Double , Double > equation , double expected ) {
@@ -37,17 +55,16 @@ static Stream<Arguments> eulerStepInvalidCases() {
37
55
38
56
@ ParameterizedTest
39
57
@ MethodSource ("eulerFullTestCases" )
40
- void testEulerFull (double xStart , double xEnd , double stepSize , double yInitial , BiFunction < Double , Double , Double > equation , int expectedSize , double [] expectedFirstPoint , double [] expectedLastPoint ) {
41
- ArrayList <double []> result = EulerMethod .eulerFull (xStart , xEnd , stepSize , yInitial , equation );
42
- assertEquals (expectedSize , result .size (), "Incorrect number of points in the result." );
43
- assertArrayEquals (expectedFirstPoint , result .get (0 ), 1e-9 , "Incorrect first point." );
44
- assertArrayEquals (expectedLastPoint , result .get (result .size () - 1 ), 1e-9 , "Incorrect last point." );
58
+ void testEulerFull (EulerFullTestCase testCase ) {
59
+ ArrayList <double []> result = EulerMethod .eulerFull (testCase . xStart , testCase . xEnd , testCase . stepSize , testCase . yInitial , testCase . equation );
60
+ assertEquals (testCase . expectedSize , result .size (), "Incorrect number of points in the result." );
61
+ assertArrayEquals (testCase . expectedFirstPoint , result .get (0 ), 1e-9 , "Incorrect first point." );
62
+ assertArrayEquals (testCase . expectedLastPoint , result .get (result .size () - 1 ), 1e-9 , "Incorrect last point." );
45
63
}
46
64
47
65
static Stream <Arguments > eulerFullTestCases () {
48
- return Stream .of (Arguments .of (0.0 , 1.0 , 0.5 , 0.0 , (BiFunction <Double , Double , Double >) ((x , y ) -> x ), 3 , new double [] {0.0 , 0.0 }, new double [] {1.0 , 0.25 }),
49
- Arguments .of (0.0 , 1.0 , 0.1 , 1.0 , (BiFunction <Double , Double , Double >) ((x , y ) -> y ), 12 , new double [] {0.0 , 1.0 }, new double [] {1.0999999999999999 , 2.8531167061100002 }),
50
- Arguments .of (0.0 , 0.1 , 0.1 , 1.0 , (BiFunction <Double , Double , Double >) ((x , y ) -> x + y ), 2 , new double [] {0.0 , 1.0 }, new double [] {0.1 , 1.1 }));
66
+ return Stream .of (Arguments .of (new EulerFullTestCase (0.0 , 1.0 , 0.5 , 0.0 , (x , y ) -> x , 3 , new double [] {0.0 , 0.0 }, new double [] {1.0 , 0.25 })),
67
+ Arguments .of (new EulerFullTestCase (0.0 , 1.0 , 0.1 , 1.0 , (x , y ) -> y , 12 , new double [] {0.0 , 1.0 }, new double [] {1.0999999999999999 , 2.8531167061100002 })), Arguments .of (new EulerFullTestCase (0.0 , 0.1 , 0.1 , 1.0 , (x , y ) -> x + y , 2 , new double [] {0.0 , 1.0 }, new double [] {0.1 , 1.1 })));
51
68
}
52
69
53
70
@ ParameterizedTest
0 commit comments