mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Revert "Extended test for Random.sample to cover both branches (#715)"
This reverts commit f81cb5d23c.
This commit is contained in:
@ -6,22 +6,15 @@ var random = Random.new(12345)
|
|||||||
System.print(random.sample(["single"])) // expect: single
|
System.print(random.sample(["single"])) // expect: single
|
||||||
|
|
||||||
// Should choose all elements with roughly equal probability.
|
// Should choose all elements with roughly equal probability.
|
||||||
var testProbability = Fn.new { |list|
|
var list = ["a", "b", "c", "d", "e"]
|
||||||
var histogram = {}
|
var histogram = {"a": 0, "b": 0, "c": 0, "d": 0, "e": 0}
|
||||||
for (entry in list) histogram[entry] = 0
|
for (i in 1..1000) {
|
||||||
|
var sample = random.sample(list)
|
||||||
for (i in 1..1000) {
|
histogram[sample] = histogram[sample] + 1
|
||||||
var sample = random.sample(list)
|
|
||||||
histogram[sample] = histogram[sample] + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
System.print(histogram.count)
|
|
||||||
for (key in histogram.keys) {
|
|
||||||
var error = (histogram[key] / (1000 / list.count) - 1).abs
|
|
||||||
if (error > 0.2) System.print("!!! %(error)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Depending on the size of the list a different algorithm is used, so test both branches.
|
System.print(histogram.count) // expect: 5
|
||||||
testProbability.call(["a", "b", "c", "d", "e"]) // expect: 5
|
for (key in histogram.keys) {
|
||||||
testProbability.call([0, 1, 2, 3, 4, 5, 6]) // expect: 7
|
var error = (histogram[key] / (1000 / list.count) - 1).abs
|
||||||
|
if (error > 0.2) System.print("!!! %(error)")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user