aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-04-19 13:29:04 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-04-19 13:29:04 -0400
commit3b0dce04a08d864626f841383727fbdab339ec83 (patch)
treec466e7104ff75c76394fd4796cb0752b4f2c6a13 /test
parent072bd523b97aacaf8639dd89a49f0c1a16d1d405 (diff)
Add heapify(), heap_push(), and heap_pop()
Diffstat (limited to 'test')
-rw-r--r--test/arrays.tm19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/arrays.tm b/test/arrays.tm
index c8e34af4..be767fab 100644
--- a/test/arrays.tm
+++ b/test/arrays.tm
@@ -95,3 +95,22 @@ func main()
= [30, 10, -20]
>> ["A", "B", "C"]:sample(10, [1.0, 0.5, 0.0])
+
+ if yes
+ >> heap := [Int.random(max=50) for _ in 10]
+ >> heap:heapify()
+ >> heap
+ sorted := [:Int]
+ while #heap > 0
+ sorted:insert(heap:heap_pop())
+ >> sorted == sorted:sorted()
+ = yes
+ for _ in 10
+ heap:heap_push(Int.random(max=50))
+ >> heap
+ sorted = [:Int]
+ while #heap > 0
+ sorted:insert(heap:heap_pop())
+ >> sorted == sorted:sorted()
+ = yes
+