The test runner's per-test timeout was raised to 5 seconds to prevent flaky timeouts on slower systems. A new example file (example/skynet.wren) was added demonstrating a million-fiber microbenchmark based on the skynet algorithm, showcasing Wren's fiber concurrency model. Additionally, the shuffle test's tolerance threshold was relaxed from 0.2 to 0.21 to reduce false positives in the random distribution check.
33 lines
723 B
Plaintext
33 lines
723 B
Plaintext
import "random" for Random
|
|
|
|
var random = Random.new(12345)
|
|
|
|
// Empty list.
|
|
var list = []
|
|
random.shuffle(list)
|
|
System.print(list) // expect: []
|
|
|
|
// One element.
|
|
list = [1]
|
|
random.shuffle(list)
|
|
System.print(list) // expect: [1]
|
|
|
|
// Given enough tries, should generate all permutations with roughly equal
|
|
// probability.
|
|
var histogram = {}
|
|
for (i in 1..5000) {
|
|
var list = [1, 2, 3, 4]
|
|
random.shuffle(list)
|
|
|
|
var string = list.toString
|
|
if (!histogram.containsKey(string)) histogram[string] = 0
|
|
histogram[string] = histogram[string] + 1
|
|
}
|
|
|
|
System.print(histogram.count) // expect: 24
|
|
for (key in histogram.keys) {
|
|
var error = (histogram[key] / (5000 / 24) - 1).abs
|
|
if (error > 0.21) System.print("!!! %(error)")
|
|
}
|
|
|