@@ -16,31 +16,43 @@ void setUp() {
16
16
}
17
17
18
18
@ Test
19
- void testConstructor () {
19
+ void testConstructorWithValidValues () {
20
20
assertEquals (3.0 , converter .convert (0.0 ), "Expected value when input is 0.0" );
21
21
assertEquals (5.0 , converter .convert (1.0 ), "Expected value when input is 1.0" );
22
- assertEquals (7.0 , converter .convert (2.0 ), "Expected value when input is 2.0" );
23
22
}
24
23
25
24
@ Test
26
- void testConvert () {
27
- assertEquals (3.0 , converter .convert (0.0 ), "Conversion at 0.0 should equal the intercept" );
28
- assertEquals (7.0 , converter .convert (2.0 ), "2.0 should convert to 7.0" );
29
- assertEquals (11.0 , converter .convert (4.0 ), "4.0 should convert to 11.0" );
25
+ void testConstructorWithInvalidValues () {
26
+ assertThrows (IllegalArgumentException .class ,
27
+ () -> new AffineConverter (Double .NaN , 3.0 ),
28
+ "Constructor should throw IllegalArgumentException for NaN slope" );
29
+ }
30
+
31
+ @ Test
32
+ void testConvertWithNegativeValues () {
33
+ assertEquals (-1.0 , converter .convert (-2.0 ), "Negative input should convert correctly" );
34
+ assertEquals (-3.0 , new AffineConverter (-1.0 , -1.0 ).convert (2.0 ),
35
+ "Slope and intercept can be negative" );
36
+ }
37
+
38
+ @ Test
39
+ void testConvertWithFloatingPointPrecision () {
40
+ double result = new AffineConverter (1.3333 , 0.6667 ).convert (3.0 );
41
+ assertEquals (4.6666 , result , 1e-4 , "Conversion should maintain floating-point precision" );
30
42
}
31
43
32
44
@ Test
33
45
void testInvert () {
34
46
AffineConverter inverted = converter .invert ();
35
- assertEquals (0.0 , inverted .convert (3.0 ), "Inverted converter should return 0.0 for input 3.0" );
36
- assertEquals (1.0 , inverted .convert (5.0 ), "Inverted converter should return 1.0 for input 5.0" );
37
- assertEquals (2.0 , inverted .convert (7.0 ), "Inverted converter should return 2.0 for input 7.0" );
47
+ assertEquals (0.0 , inverted .convert (3.0 ), "Inverted should return 0.0 for input 3.0" );
48
+ assertEquals (1.0 , inverted .convert (5.0 ), "Inverted should return 1.0 for input 5.0" );
38
49
}
39
50
40
51
@ Test
41
52
void testInvertWithZeroSlope () {
42
53
AffineConverter zeroSlopeConverter = new AffineConverter (0.0 , 3.0 );
43
- assertThrows (AssertionError .class , zeroSlopeConverter ::invert , "Invert should throw assertion error when slope is zero" );
54
+ assertThrows (AssertionError .class , zeroSlopeConverter ::invert ,
55
+ "Invert should throw AssertionError when slope is zero" );
44
56
}
45
57
46
58
@ Test
@@ -50,6 +62,31 @@ void testCompose() {
50
62
51
63
assertEquals (7.0 , composed .convert (0.0 ), "Expected composed conversion at 0.0" );
52
64
assertEquals (9.0 , composed .convert (1.0 ), "Expected composed conversion at 1.0" );
53
- assertEquals (11.0 , composed .convert (2.0 ), "Expected composed conversion at 2.0" );
65
+ }
66
+
67
+ @ Test
68
+ void testMultipleCompositions () {
69
+ AffineConverter c1 = new AffineConverter (2.0 , 1.0 );
70
+ AffineConverter c2 = new AffineConverter (3.0 , -2.0 );
71
+ AffineConverter c3 = c1 .compose (c2 ); // (2x + 1) ∘ (3x - 2) => 6x - 1
72
+
73
+ assertEquals (-3.0 , c3 .convert (0.0 ), "Composed transformation should return -3.0 at 0.0" );
74
+ assertEquals (3.0 , c3 .convert (1.0 ), "Composed transformation should return 3.0 at 1.0" );
75
+ }
76
+
77
+ @ Test
78
+ void testIdentityComposition () {
79
+ AffineConverter identity = new AffineConverter (1.0 , 0.0 );
80
+ AffineConverter composed = converter .compose (identity );
81
+
82
+ assertEquals (3.0 , composed .convert (0.0 ), "Identity composition should not change the transformation" );
83
+ assertEquals (7.0 , composed .convert (2.0 ), "Identity composition should behave like the original" );
84
+ }
85
+
86
+ @ Test
87
+ void testLargeInputs () {
88
+ double largeValue = 1e6 ;
89
+ assertEquals (2.0 * largeValue + 3.0 , converter .convert (largeValue ),
90
+ "Should handle large input values without overflow" );
54
91
}
55
92
}
0 commit comments