You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2016/03/21 00:53:33 UTC
[2/2] [math] Added unit test.
Added unit test.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/80814930
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/80814930
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/80814930
Branch: refs/heads/feature-MATH-1339
Commit: 808149305ba26224917e29aa0c0089701bd91936
Parents: 7a8dc00
Author: Gilles <er...@apache.org>
Authored: Sun Mar 13 03:05:54 2016 +0100
Committer: Gilles <er...@apache.org>
Committed: Mon Mar 21 00:36:55 2016 +0100
----------------------------------------------------------------------
.../apache/commons/math4/util/MathArraysTest.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/80814930/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
index a6cc764..e71a824 100644
--- a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
+++ b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
@@ -1107,6 +1107,23 @@ public class MathArraysTest {
}
@Test
+ public void testShuffleNoDuplicates() {
+ final int n = 100;
+ final int[] orig = MathArrays.natural(n);
+ MathArrays.shuffle(orig);
+
+ // Test that all (unique) entries exist in the shuffled array.
+ final int[] count = new int[n];
+ for (int i = 0; i < n; i++) {
+ count[orig[i]] += 1;
+ }
+
+ for (int i = 0; i < n; i++) {
+ Assert.assertEquals(1, count[i]);
+ }
+ }
+
+ @Test
public void testShuffleTail() {
final int[] orig = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
final int[] list = orig.clone();