Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/14551#discussion_r74005725
--- Diff: core/src/test/scala/org/apache/spark/util/UtilsSuite.scala ---
@@ -874,4 +874,38 @@ class UtilsSuite extends SparkFunSuite with
ResetSystemProperties with Logging {
}
}
}
+
+ test("chi square test of randomizeInPlace") {
+ // Parameters
+ val arraySize = 10
+ val numTrials = 1000
+ val threshold = 0.05
+ val seed = 1L
+
+ // results[i][j]: how many times Utils.randomize moves an element from
position j to position i
+ val results: Array[Array[Long]] = Array.ofDim(arraySize, arraySize)
+
+ // This must be seeded because even a fair random process will fail
this test with
+ // probability equal to the value of `threshold`, which is
inconvenient for a unit test.
+ val rand = new java.util.Random(seed)
+ val range = 0 until arraySize
+
+ for {
+ _ <- 0 until numTrials
+ trial = Utils.randomizeInPlace(range.toArray, rand)
+ i <- range
+ } results(i)(trial(i)) += 1L
+
+ val chi = new org.apache.commons.math3.stat.inference.ChiSquareTest()
+
+ // We expect an even distribution; this array will be rescaled by
`chiSquareTest`
+ val expected: Array[Double] = Array.fill(arraySize * arraySize)(1.0)
+ val observed: Array[Long] = results.flatMap(x => x)
--- End diff --
`flatten`?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]