From 5b0f8740f24a87c007df3d3eaa82c03d9dbd52e0 Mon Sep 17 00:00:00 2001 From: underscorediscovery Date: Sat, 18 Jul 2020 20:10:22 -0700 Subject: [PATCH] Revert "Extended test for Random.sample to cover both branches (#715)" This reverts commit f81cb5d23cbf3a6bb5b83511cf6a47dcf2f130e9. --- test/random/sample_one.wren | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/test/random/sample_one.wren b/test/random/sample_one.wren index a147c348..dd7fe9bb 100644 --- a/test/random/sample_one.wren +++ b/test/random/sample_one.wren @@ -6,22 +6,15 @@ var random = Random.new(12345) System.print(random.sample(["single"])) // expect: single // Should choose all elements with roughly equal probability. -var testProbability = Fn.new { |list| - var histogram = {} - for (entry in list) histogram[entry] = 0 - - for (i in 1..1000) { - 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)") - } +var list = ["a", "b", "c", "d", "e"] +var histogram = {"a": 0, "b": 0, "c": 0, "d": 0, "e": 0} +for (i in 1..1000) { + var sample = random.sample(list) + histogram[sample] = histogram[sample] + 1 } -// Depending on the size of the list a different algorithm is used, so test both branches. -testProbability.call(["a", "b", "c", "d", "e"]) // expect: 5 -testProbability.call([0, 1, 2, 3, 4, 5, 6]) // expect: 7 +System.print(histogram.count) // expect: 5 +for (key in histogram.keys) { + var error = (histogram[key] / (1000 / list.count) - 1).abs + if (error > 0.2) System.print("!!! %(error)") +}