diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test/lux/data/lazy.lux | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/stdlib/test/test/lux/data/lazy.lux b/stdlib/test/test/lux/data/lazy.lux index bf395bcfa..926157a07 100644 --- a/stdlib/test/test/lux/data/lazy.lux +++ b/stdlib/test/test/lux/data/lazy.lux @@ -1,14 +1,14 @@ (;module: lux (lux [io] - (control ["M" monad #+ do Monad]) + (control [monad #+ do Monad]) (data ["&" lazy]) - ["R" math/random]) + ["r" math/random]) lux/test) (context: "Lazy." - [left R;nat - right R;nat + [left r;nat + right r;nat #let [lazy (&;freeze (n.* left right)) expected (n.* left right)]] ($_ seq @@ -17,7 +17,37 @@ (&;thaw lazy))) (test "Lazy values only evaluate once." (and (not (is expected - (: Nat (&;thaw lazy)))) + (&;thaw lazy))) (is (&;thaw lazy) (&;thaw lazy)))) )) + +(context: "Functor, Applicative, Monad." + [sample r;nat] + ($_ seq + (test "Functor map." + (|> (&;freeze sample) + (:: &;Functor<Lazy> map n.inc) + &;thaw + (n.= (n.inc sample)))) + + (test "Applicative wrap." + (|> sample + (:: &;Applicative<Lazy> wrap) + &;thaw + (n.= sample))) + + (test "Applicative apply." + (let [(^open "&/") &;Applicative<Lazy>] + (|> (&/apply (&/wrap n.inc) (&/wrap sample)) + &;thaw + (n.= (n.inc sample))))) + + (test "Monad." + (|> (do &;Monad<Lazy> + [f (wrap n.inc) + a (wrap sample)] + (wrap (f a))) + &;thaw + (n.= (n.inc sample)))) + )) |