Skip to content

Commit 298d46e

Browse files
committed
Fix tests for RandomChooser since Apache math3 has been updated
1 parent 806087d commit 298d46e

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

test/ubic/basecode/math/RandomChooserTest.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertTrue;
2323

24-
import java.util.ArrayList;
25-
import java.util.Collection;
26-
import java.util.HashSet;
27-
import java.util.List;
28-
import java.util.Set;
24+
import java.util.*;
2925

3026
import org.junit.Before;
3127
import org.junit.Test;
@@ -46,10 +42,10 @@ public void setUp() throws Exception {
4642
public void testChooseRandomDeck() {
4743
double[] e = new double[] { 0d, 1d, 2d, 3d, 4d, 5d, 6d, 7d };
4844
double[] result = RandomChooser.chooserandom( e, 4 );
49-
double[] expected = new double[] { 5.0, 7.0, 3.0, 0.0 };
45+
double[] expected = new double[] { 4.0, 2.0, 6.0, 1.0 };
5046
assertEquals( expected.length, result.length );
5147
for ( int i = 0; i < result.length; i++ ) {
52-
assertEquals( expected[i], result[i], 0.0001 );
48+
assertEquals( expected[i], result[i], 0 );
5349
}
5450

5551
// check uniformity; each number should appear approx 1000 times: 10000 trials * 0.01 * 10 = 1000.
@@ -68,14 +64,14 @@ public void testChooseRandomDeck() {
6864
}
6965

7066
/**
71-
* Test method for {@link ubic.basecode.math.RandomChooser#chooserandom(int[], boolean[], int, int)} .
67+
* Test method for {@link ubic.basecode.math.RandomChooser#chooserandom(int, int)}.
7268
*/
7369
@Test
7470
public void testChooserandomInt() {
7571
int[] result = RandomChooser.chooserandom( 100, 10 );
76-
int[] expected = { 26, 95, 75, 93, 72, 67, 59, 21, 22, 8 };
72+
int[] expected = { 82, 38, 97, 73, 44, 16, 66, 35, 31, 43 };
7773
for ( int i = 0; i < result.length; i++ ) {
78-
assertEquals( expected[i], result[i] );
74+
assertEquals( expected[i], result[i], 0 );
7975
}
8076

8177
// check uniformity; each number should appear approx 1000 times: 10000 trials * 0.01 * 10 = 1000.
@@ -94,13 +90,13 @@ public void testChooserandomInt() {
9490
}
9591

9692
@Test
97-
public void testChooserandomInts() throws Exception {
93+
public void testChooserandomInts() {
9894

9995
int[] deck = { 0, 1, 2, 3, 4, 5, 6, 7 };
100-
int[] expected = { 5, 7, 3, 0 };
96+
int[] expected = { 4, 2, 6, 1 };
10197
int[] result = RandomChooser.chooserandom( deck, 4 );
10298
for ( int i = 0; i < result.length; i++ ) {
103-
assertEquals( expected[i], result[i], 0.0001 );
99+
assertEquals( expected[i], result[i], 0 );
104100
}
105101

106102
// check uniformity; each number should appear approx 1000 times: 10000 trials * 0.01 * 10 = 1000.
@@ -119,7 +115,7 @@ public void testChooserandomInts() throws Exception {
119115
}
120116

121117
/**
122-
* Test method for {@link ubic.basecode.math.RandomChooser#chooserandomWrep(int[], int, int)} .
118+
* Test method for {@link ubic.basecode.math.RandomChooser#chooserandomWrep(int, int)}} .
123119
*/
124120
@Test
125121
public void testChooserandomWrep() {
@@ -151,10 +147,9 @@ public void testRandomSubset() {
151147
* Check correctness of the sampling algorithm for choosing subsets of size 2. The average value should come out
152148
* close to k/2.
153149
*
154-
* @throws Exception
155150
*/
156151
@Test
157-
public void testRepeat() throws Exception {
152+
public void testRepeat() {
158153
int k = 1000;
159154

160155
double total = 0.0;
@@ -172,10 +167,9 @@ public void testRepeat() throws Exception {
172167
* Check correctness of the sampling algorithm for choosing subsets of size 2. The average value should come out
173168
* very close to k/2.
174169
*
175-
* @throws Exception
176170
*/
177171
@Test
178-
public void testRepeatSubset() throws Exception {
172+
public void testRepeatSubset() {
179173
List<Integer> k = new ArrayList<>();
180174
int max = 1000;
181175
for ( int i = 0; i < max; i++ ) {

0 commit comments

Comments
 (0)