33import org .junit .Test ;
44
55import static org .junit .Assert .assertEquals ;
6+ import static org .junit .Assert .assertTrue ;
67
78public class FourMatrixTest {
89
@@ -11,37 +12,41 @@ public class FourMatrixTest {
1112
1213 @ Test
1314 public void fromTwoMatrixWithFixedCoordinates () {
14- assertEquals (createMatrix (
15- row (1 , 0 , 0 , 0 ),
16- row (0 , 1 , 0 , 0 ),
17- row (0 , 0 , SQRT_3_PER_2 , -0.5 ),
18- row (0 , 0 , 0.5 , SQRT_3_PER_2 )),
15+ assertTrue (matricesAreEqual (
16+ createMatrix (
17+ row (1 , 0 , 0 , 0 ),
18+ row (0 , 1 , 0 , 0 ),
19+ row (0 , 0 , SQRT_3_PER_2 , -0.5 ),
20+ row (0 , 0 , 0.5 , SQRT_3_PER_2 )),
1921 FourMatrix .fromTwoMatrixWithFixedCoordinates (TwoMatrix .rotationBy (Math .PI / 6 ), 0 , 1 )
20- );
21-
22- assertEquals (createMatrix (
23- row (SQRT_2_PER_2 , 0 , 0 , -SQRT_2_PER_2 ),
24- row (0 , 1 , 0 , 0 ),
25- row (0 , 0 , 1 , 0 ),
26- row (SQRT_2_PER_2 , 0 , 0 , SQRT_2_PER_2 )),
22+ ));
23+
24+ assertTrue (matricesAreEqual (
25+ createMatrix (
26+ row (SQRT_2_PER_2 , 0 , 0 , -SQRT_2_PER_2 ),
27+ row (0 , 1 , 0 , 0 ),
28+ row (0 , 0 , 1 , 0 ),
29+ row (SQRT_2_PER_2 , 0 , 0 , SQRT_2_PER_2 )),
2730 FourMatrix .fromTwoMatrixWithFixedCoordinates (TwoMatrix .rotationBy (Math .PI / 4 ), 1 , 2 )
28- );
29-
30- assertEquals (createMatrix (
31- row (1 , 0 , 0 , 0 ),
32- row (0 , 0.5 , -SQRT_3_PER_2 , 0 ),
33- row (0 , SQRT_3_PER_2 , 0.5 , 0 ),
34- row (0 , 0 , 0 , 1 )),
31+ ));
32+
33+ assertTrue (matricesAreEqual (
34+ createMatrix (
35+ row (1 , 0 , 0 , 0 ),
36+ row (0 , 0.5 , -SQRT_3_PER_2 , 0 ),
37+ row (0 , SQRT_3_PER_2 , 0.5 , 0 ),
38+ row (0 , 0 , 0 , 1 )),
3539 FourMatrix .fromTwoMatrixWithFixedCoordinates (TwoMatrix .rotationBy (Math .PI / 3 ), 0 , 3 )
36- );
37-
38- assertEquals (createMatrix (
39- row (0 , -1 , 0 , 0 ),
40- row (1 , 0 , 0 , 0 ),
41- row (0 , 0 , 1 , 0 ),
42- row (0 , 0 , 0 , 1 )),
40+ ));
41+
42+ assertTrue (matricesAreEqual (
43+ createMatrix (
44+ row (0 , -1 , 0 , 0 ),
45+ row (1 , 0 , 0 , 0 ),
46+ row (0 , 0 , 1 , 0 ),
47+ row (0 , 0 , 0 , 1 )),
4348 FourMatrix .fromTwoMatrixWithFixedCoordinates (TwoMatrix .rotationBy (Math .PI / 2 ), 2 , 3 )
44- );
49+ )) ;
4550 }
4651
4752 private FourMatrix createMatrix (double []... rows ) {
@@ -52,6 +57,10 @@ private double[] row(double... elements) {
5257 return elements ;
5358 }
5459
60+ private boolean matricesAreEqual (FourMatrix first , FourMatrix second ) {
61+ return first .approximatelyEquals (second );
62+ }
63+
5564 @ Test
5665 public void times () {
5766 FourMatrix unitMatrix = createMatrix (
@@ -60,7 +69,7 @@ public void times() {
6069 row (0 , 0 , 1 , 0 ),
6170 row (0 , 0 , 0 , 1 ));
6271
63- assertEquals ( unitMatrix , unitMatrix .times (unitMatrix ));
72+ assertTrue ( matricesAreEqual ( unitMatrix , unitMatrix .times (unitMatrix ) ));
6473
6574 FourMatrix someMatrix = createMatrix (
6675 row (1 , 1 , 1 , 1 ),
@@ -74,16 +83,18 @@ public void times() {
7483 row (3 , 0 , 3 , 0 ),
7584 row (4 , 0 , 4 , 0 ));
7685
77- assertEquals ( someMatrix , someMatrix .times (unitMatrix ));
86+ assertTrue ( matricesAreEqual ( someMatrix , someMatrix .times (unitMatrix ) ));
7887
79- assertEquals ( someOtherMatrix , unitMatrix .times (someOtherMatrix ));
88+ assertTrue ( matricesAreEqual ( someOtherMatrix , unitMatrix .times (someOtherMatrix ) ));
8089
81- assertEquals (createMatrix (
82- row (7 , 3 , 7 , 3 ),
83- row (14 , 6 , 14 , 6 ),
84- row (21 , 9 , 21 , 9 ),
85- row (28 , 12 , 28 , 12 )),
86- someMatrix .times (someOtherMatrix ));
90+ assertTrue (matricesAreEqual (
91+ createMatrix (
92+ row (7 , 3 , 7 , 3 ),
93+ row (14 , 6 , 14 , 6 ),
94+ row (21 , 9 , 21 , 9 ),
95+ row (28 , 12 , 28 , 12 )),
96+ someMatrix .times (someOtherMatrix )
97+ ));
8798 }
8899
89100 @ Test
0 commit comments