aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-01 16:55:24 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-01 16:55:24 -0400
commit6de2d68a700a137bbe55668e036c62280ece8bb5 (patch)
treeeb1e3cee37cd9b2f1458b9ceff0141bfbd7a91a9 /test
parenta32c3747568562251d6c390faf325bf3ed3946e6 (diff)
Moved RNG out of the compiler and into a standalone library
Diffstat (limited to 'test')
-rw-r--r--test/arrays.tm6
-rw-r--r--test/integers.tm12
-rw-r--r--test/rng.tm40
3 files changed, 9 insertions, 49 deletions
diff --git a/test/arrays.tm b/test/arrays.tm
index 2c9f472b..66819a74 100644
--- a/test/arrays.tm
+++ b/test/arrays.tm
@@ -101,7 +101,7 @@ func main():
>> ["A", "B", "C"]:sample(10, [1.0, 0.5, 0.0])
do:
- >> heap := @[random:int(1, 50) for _ in 10]
+ >> heap := @[(i * 1337) mod 37 for i in 10]
>> heap:heapify()
>> heap
sorted := @[:Int]
@@ -109,8 +109,8 @@ func main():
sorted:insert(heap:heap_pop() or stop)
>> sorted == sorted:sorted()
= yes
- for _ in 10:
- heap:heap_push(random:int(1, 50))
+ for i in 10:
+ heap:heap_push((i*13337) mod 37)
>> heap
sorted = @[:Int]
repeat:
diff --git a/test/integers.tm b/test/integers.tm
index c8fd5c9b..04256c88 100644
--- a/test/integers.tm
+++ b/test/integers.tm
@@ -85,12 +85,12 @@ func main():
= 10000000000000000000000
do:
- for in 20:
- >> n := random:int(-999999, 999999)
- >> d := random:int(-999, 999)
- !! n=$n, d=$d:
- >> (n/d)*d + (n mod d) == n
- = yes
+ interesting_numerators := [-999999, -100, -23, -1, 0, 1, 23, 100, 999999]
+ interesting_denominators := [-99, -20, -17, -1, 1, 17, 20, 99]
+ for n in interesting_numerators:
+ for d in interesting_denominators:
+ >> (n/d)*d + (n mod d) == n
+ = yes
>> 0:next_prime()
= 2
diff --git a/test/rng.tm b/test/rng.tm
deleted file mode 100644
index 1814d583..00000000
--- a/test/rng.tm
+++ /dev/null
@@ -1,40 +0,0 @@
-# Random Number Generator tests
-
-func main():
- !! Default RNG:
- >> random:int64()
-
- >> original_rng := RNG.new([:Byte])
- >> copy := original_rng:copy()
-
- for rng in [original_rng, copy]:
- !! RNG: $rng
- >> rng:int(1, 1000)
- = 921
- >> rng:int64(1, 1000)
- = Int64(324)
- >> rng:int32(1, 1000)
- = Int32(586)
- >> rng:int16(1, 1000)
- = Int16(453)
- >> rng:int8(1, 100)
- = Int8(53)
- >> rng:byte()
- = Byte(0xDC)
- >> rng:bytes(10)
- = [:Byte, 0xA0, 0x5A, 0x10, 0x3F, 0x6C, 0xD1, 0x35, 0xC2, 0x87, 0x8C]
- >> rng:bool(p=0.8)
- = yes
- >> rng:num()
- = 0.03492503353647658
- >> rng:num32(1, 1000)
- = Num32(761.05908)
-
- !! Random array methods:
- >> nums := [10*i for i in 10]
- >> nums:shuffled(rng=rng)
- = [30, 50, 100, 20, 90, 10, 80, 40, 70, 60]
- >> nums:random(rng=rng)
- = 70
- >> nums:sample(10, weights=[1.0/Num(i) for i in nums.length], rng=rng)
- = [10, 20, 10, 10, 30, 70, 10, 40, 60, 80]