6
6
7
7
package gov .nasa .worldwind .geom ;
8
8
9
- import org .junit .Test ;
9
+ import org .junit .* ;
10
10
import org .junit .runner .RunWith ;
11
11
import org .junit .runners .JUnit4 ;
12
12
13
+ import java .util .Random ;
14
+
13
15
import static org .junit .Assert .*;
14
16
15
17
@ RunWith (JUnit4 .class )
16
18
public class MatrixTest
17
19
{
18
20
private static final double EQUALITY_TOLERANCE = 1.0e-9 ;
19
21
private static final double NEAR_SINGULAR_EQUALITY_TOLERANCE = 1.0e-6 ;
22
+ private static final long RANDOM_SEED = 6124946250748012048L ;
23
+
24
+ private Random random ;
25
+
26
+ @ Before
27
+ public void setUp () throws Exception
28
+ {
29
+ // Use a random initialized with a constant seed to ensure that subsequent test executes get the same
30
+ // pseudorandom values. Using Math.random may results in tests failing unpredictably, and prevents debugging
31
+ // since the random seed is not known.
32
+ random = new Random (RANDOM_SEED );
33
+ }
20
34
21
35
//**************************************************************//
22
36
//******************** Test Matrix Inversion *****************//
@@ -40,10 +54,10 @@ public void testInverseOfTransform()
40
54
public void testInverseOfRandom ()
41
55
{
42
56
Matrix m = new Matrix (
43
- Math . random (), Math . random (), Math . random (), Math . random (),
44
- Math . random (), Math . random (), Math . random (), Math . random (),
45
- Math . random (), Math . random (), Math . random (), Math . random (),
46
- Math . random (), Math . random (), Math . random (), Math . random ());
57
+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble (),
58
+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble (),
59
+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble (),
60
+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble ());
47
61
48
62
Matrix mInv = m .getInverse ();
49
63
assertNotNull ("Matrix inverse is null" , mInv );
@@ -56,9 +70,12 @@ public void testInverseOfRandom()
56
70
public void testInverseOfSingular ()
57
71
{
58
72
// Create a singular matrix, where the fourth row is a linear combination of first three.
59
- double m11 = Math .random (), m12 = Math .random (), m13 = Math .random (), m14 = Math .random ();
60
- double m21 = Math .random (), m22 = Math .random (), m23 = Math .random (), m24 = Math .random ();
61
- double m31 = Math .random (), m32 = Math .random (), m33 = Math .random (), m34 = Math .random ();
73
+ double m11 = random .nextDouble (), m12 = random .nextDouble (), m13 = random .nextDouble (), m14
74
+ = random .nextDouble ();
75
+ double m21 = random .nextDouble (), m22 = random .nextDouble (), m23 = random .nextDouble (), m24
76
+ = random .nextDouble ();
77
+ double m31 = random .nextDouble (), m32 = random .nextDouble (), m33 = random .nextDouble (), m34
78
+ = random .nextDouble ();
62
79
double f1 = 1.4 , f2 = -4.02 , f3 = 0.3 ;
63
80
double m41 = f1 * m11 + f2 * m21 + f3 * m31 ;
64
81
double m42 = f1 * m12 + f2 * m22 + f3 * m32 ;
@@ -79,10 +96,10 @@ public void testInverseOfSingular()
79
96
public void testInverseOfZeroRow ()
80
97
{
81
98
Matrix m = new Matrix (
82
- Math . random (), Math . random (), Math . random (), Math . random (),
99
+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble (),
83
100
0 , 0 , 0 , 0 ,
84
- Math . random (), Math . random (), Math . random (), Math . random (),
85
- Math . random (), Math . random (), Math . random (), Math . random ());
101
+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble (),
102
+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble ());
86
103
87
104
Matrix mInv = m .getInverse ();
88
105
assertNull ("Singular matrix should not have an inverse" , mInv );
@@ -92,9 +109,12 @@ public void testInverseOfZeroRow()
92
109
public void testInverseOfNearSingular ()
93
110
{
94
111
// Create a singular matrix, where the fourth row is a linear combination of first three.
95
- double m11 = Math .random (), m12 = Math .random (), m13 = Math .random (), m14 = Math .random ();
96
- double m21 = Math .random (), m22 = Math .random (), m23 = Math .random (), m24 = Math .random ();
97
- double m31 = Math .random (), m32 = Math .random (), m33 = Math .random (), m34 = Math .random ();
112
+ double m11 = random .nextDouble (), m12 = random .nextDouble (), m13 = random .nextDouble (), m14
113
+ = random .nextDouble ();
114
+ double m21 = random .nextDouble (), m22 = random .nextDouble (), m23 = random .nextDouble (), m24
115
+ = random .nextDouble ();
116
+ double m31 = random .nextDouble (), m32 = random .nextDouble (), m33 = random .nextDouble (), m34
117
+ = random .nextDouble ();
98
118
double f1 = 1.4 , f2 = -4.02 , f3 = 0.3 ;
99
119
double m41 = f1 * m11 + f2 * m21 + f3 * m31 ;
100
120
double m42 = f1 * m12 + f2 * m22 + f3 * m32 ;
0 commit comments