aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/test/test/lux/math/random.lux54
-rw-r--r--stdlib/test/tests.lux3
2 files changed, 56 insertions, 1 deletions
diff --git a/stdlib/test/test/lux/math/random.lux b/stdlib/test/test/lux/math/random.lux
new file mode 100644
index 000000000..ae33ab98f
--- /dev/null
+++ b/stdlib/test/test/lux/math/random.lux
@@ -0,0 +1,54 @@
+(;module:
+ lux
+ (lux [io]
+ (control [monad #+ do Monad])
+ (data [number]
+ (coll [list]
+ [vector]
+ [array]
+ [queue]
+ [stack]
+ [set]
+ [dict]))
+ (math ["r" random]))
+ lux/test)
+
+(context: "Random."
+ #seed +1504643924987
+ [size (|> r;nat (:: @ map (n.% +100)))
+ _list (r;list size r;nat)
+ _vector (r;vector size r;nat)
+ _array (r;array size r;nat)
+ _queue (r;queue size r;nat)
+ _stack (r;stack size r;nat)
+ _set (r;set number;Hash<Nat> size r;nat)
+ _dict (r;dict number;Hash<Nat> size r;nat r;nat)
+ top r;nat
+ filtered (|> r;nat (r;filter (n.<= top)))
+ shuffle-seed r;nat
+ #let [sorted (|> _vector vector;to-list (list;sort n.<))
+ shuffled (|> sorted vector;from-list (r;shuffle shuffle-seed))
+ re-sorted (|> shuffled vector;to-list (list;sort n.<))]]
+ ($_ seq
+ (test "Can produce lists."
+ (n.= size (list;size _list)))
+ (test "Can produce vectors."
+ (n.= size (vector;size _vector)))
+ (test "Can produce arrays."
+ (n.= size (array;size _array)))
+ (test "Can produce queues."
+ (n.= size (queue;size _queue)))
+ (test "Can produce stacks."
+ (n.= size (stack;size _stack)))
+ (test "Can produce sets."
+ (n.= size (set;size _set)))
+ (test "Can produce dicts."
+ (n.= size (dict;size _dict)))
+ (test "Can filter values."
+ (n.<= top filtered))
+ (test "Can shuffle vectors."
+ (let [(^open "v/") (vector;Eq<Vector> number;Eq<Nat>)
+ sorted (vector;from-list sorted)]
+ (and (not (v/= sorted shuffled))
+ (v/= sorted (vector;from-list re-sorted)))))
+ ))
diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux
index 9b0f8ff11..598c488fd 100644
--- a/stdlib/test/tests.lux
+++ b/stdlib/test/tests.lux
@@ -60,7 +60,8 @@
["_;" lexer]
["_;" regex]))
["_;" math]
- (math (logic ["_;" continuous]
+ (math ["_;" random]
+ (logic ["_;" continuous]
["_;" fuzzy]))
(macro ["_;" code]
["_;" syntax]