66
77package gov .nasa .worldwind .geom ;
88
9- import org .junit .Test ;
9+ import org .junit .* ;
1010import org .junit .runner .RunWith ;
1111import org .junit .runners .JUnit4 ;
1212
13+ import java .util .Random ;
14+
1315import static org .junit .Assert .*;
1416
1517@ RunWith (JUnit4 .class )
1618public class MatrixTest
1719{
1820 private static final double EQUALITY_TOLERANCE = 1.0e-9 ;
1921 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+ }
2034
2135 //**************************************************************//
2236 //******************** Test Matrix Inversion *****************//
@@ -40,10 +54,10 @@ public void testInverseOfTransform()
4054 public void testInverseOfRandom ()
4155 {
4256 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 ());
4761
4862 Matrix mInv = m .getInverse ();
4963 assertNotNull ("Matrix inverse is null" , mInv );
@@ -56,9 +70,12 @@ public void testInverseOfRandom()
5670 public void testInverseOfSingular ()
5771 {
5872 // 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 ();
6279 double f1 = 1.4 , f2 = -4.02 , f3 = 0.3 ;
6380 double m41 = f1 * m11 + f2 * m21 + f3 * m31 ;
6481 double m42 = f1 * m12 + f2 * m22 + f3 * m32 ;
@@ -79,10 +96,10 @@ public void testInverseOfSingular()
7996 public void testInverseOfZeroRow ()
8097 {
8198 Matrix m = new Matrix (
82- Math . random (), Math . random (), Math . random (), Math . random (),
99+ random . nextDouble (), random . nextDouble (), random . nextDouble (), random . nextDouble (),
83100 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 ());
86103
87104 Matrix mInv = m .getInverse ();
88105 assertNull ("Singular matrix should not have an inverse" , mInv );
@@ -92,9 +109,12 @@ public void testInverseOfZeroRow()
92109 public void testInverseOfNearSingular ()
93110 {
94111 // 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 ();
98118 double f1 = 1.4 , f2 = -4.02 , f3 = 0.3 ;
99119 double m41 = f1 * m11 + f2 * m21 + f3 * m31 ;
100120 double m42 = f1 * m12 + f2 * m22 + f3 * m32 ;
0 commit comments