Unit test.

Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/144f88b5
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/144f88b5
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/144f88b5

Branch: refs/heads/master
Commit: 144f88b5f35ec333d329f7a827c297b72bf9a8c1
Parents: 00c1dee
Author: Gilles <er...@apache.org>
Authored: Mon Nov 21 14:46:50 2016 +0100
Committer: Gilles <er...@apache.org>
Committed: Mon Nov 21 14:46:50 2016 +0100

----------------------------------------------------------------------
 .../rng/sampling/PermutationSamplerTest.java    | 21 ++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/144f88b5/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
----------------------------------------------------------------------
diff --git 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
index bd32c05..c91218d 100644
--- 
a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
+++ 
b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/PermutationSamplerTest.java
@@ -39,7 +39,24 @@ public class PermutationSamplerTest {
     private final ChiSquareTest chiSquareTest = new ChiSquareTest();
 
     @Test
-    public void testSample() {
+    public void testSampleTrivial() {
+        final int n = 6;
+        final int k = 3;
+        final PermutationSampler sampler = new 
PermutationSampler(RandomSource.create(RandomSource.KISS),
+                                                                  6, 3);
+        final int[] random = sampler.sample();
+        SAMPLE: for (int s : random) {
+            for (int i = 0; i < n; i++) {
+                if (i == s) {
+                    continue SAMPLE;
+                }
+            }
+            Assert.fail("number " + s + " not in array");
+        }
+    }
+
+    @Test
+    public void testSampleChiSquareTest() {
         final int[][] p = { { 0, 1, 2 }, { 0, 2, 1 },
                             { 1, 0, 2 }, { 1, 2, 0 },
                             { 2, 0, 1 }, { 2, 1, 0 } };
@@ -55,7 +72,7 @@ public class PermutationSamplerTest {
             observed[findPerm(p, sampler.sample())]++;
         }
 
-        // Pass if we cannot reject null hypothesis that distributions are the 
same
+        // Pass if we cannot reject null hypothesis that distributions are the 
same.
         Assert.assertFalse(chiSquareTest.chiSquareTest(expected, observed, 
0.001));
     }
     

Reply via email to