aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-03 22:39:46 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-03 22:39:46 -0500
commitd0ebb66b30a723db9c0c6d9a57877b84e7dff386 (patch)
treebff16695a37274685d1b89a3ccb85cc9d65bc0c8 /test
parentfc9a6f1416be514e9d26b301d05e7e347560560b (diff)
Fix up test to use RNGs
Diffstat (limited to 'test')
-rw-r--r--test/arrays.tm30
-rw-r--r--test/integers.tm5
-rw-r--r--test/nums.tm2
3 files changed, 4 insertions, 33 deletions
diff --git a/test/arrays.tm b/test/arrays.tm
index 25d45582..7f1882ab 100644
--- a/test/arrays.tm
+++ b/test/arrays.tm
@@ -105,7 +105,7 @@ func main():
>> ["A", "B", "C"]:sample(10, [1.0, 0.5, 0.0])
do:
- >> heap := [Int.random(1, 50) for _ in 10]
+ >> heap := [random:int(1, 50) for _ in 10]
>> heap:heapify()
>> heap
sorted := [:Int]
@@ -114,7 +114,7 @@ func main():
>> sorted == sorted:sorted()
= yes
for _ in 10:
- heap:heap_push(Int.random(1, 50))
+ heap:heap_push(random:int(1, 50))
>> heap
sorted = [:Int]
while heap.length > 0:
@@ -172,29 +172,3 @@ func main():
= !Int
>> [4, 5, 6]:first(func(i:&Int): i:is_prime())
= 2?
-
- test_seeded_rng()
-
-# Inspired by: https://nullprogram.com/blog/2017/09/21/
-struct RNGxoroshiro128(s0=Int64.random(),s1=Int64.random()):
- func int_fn(rng:@RNGxoroshiro128 -> func(->Int64)):
- return func(-> Int64):
- s0 := rng.s0
- s1 := rng.s1
- result := s0:wrapping_plus(s1)
- s1 xor= s0
- rng.s0 = (s0 <<< 55) or (s0 >>> 9) xor s1 xor (s1 <<< 14)
- rng.s1 = (s1 <<< 36) or (s1 >>> 28)
- return result
-
-func test_seeded_rng():
- !! Seeded RNG:
- rng_state := RNGxoroshiro128(Int64.random(), Int64.random())
- rng1 := @rng_state:int_fn()
- rng2 := @rng_state:int_fn()
-
- nums := [i*10 for i in 20]
- >> nums:random(rng1) == nums:random(rng2)
- = yes
- >> nums:shuffled(rng1) == nums:shuffled(rng2)
- = yes
diff --git a/test/integers.tm b/test/integers.tm
index 9b5b6b4f..ad9c40d7 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -50,7 +50,6 @@ func main():
>> x:octal()
= "0o173"
- >> Int.random(1, 100)
>> Int64.min
= -9223372036854775808[64]
>> Int64.max
@@ -87,8 +86,8 @@ func main():
do:
for in 20:
- >> n := Int.random(-999999, 999999)
- >> d := Int.random(-999, 999)
+ >> n := random:int(-999999, 999999)
+ >> d := random:int(-999, 999)
!! n=$n, d=$d:
>> (n/d)*d + (n mod d) == n
= yes
diff --git a/test/nums.tm b/test/nums.tm
index 3d6b05dd..32c55f3b 100644
--- a/test/nums.tm
+++ b/test/nums.tm
@@ -17,8 +17,6 @@ func main():
>> Num.PI:format(precision=10)
= "3.1415926536"
- >> Num.random()
-
>> Num.INF
= inf
>> Num.INF:isinf()