diff options
Diffstat (limited to 'stdlib/source/test/lux/data/lazy.lux')
-rw-r--r-- | stdlib/source/test/lux/data/lazy.lux | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/stdlib/source/test/lux/data/lazy.lux b/stdlib/source/test/lux/data/lazy.lux index 5fe6464ff..957ce0c34 100644 --- a/stdlib/source/test/lux/data/lazy.lux +++ b/stdlib/source/test/lux/data/lazy.lux @@ -1,54 +1,55 @@ (.module: [lux #* + ["_" test (#+ Test)] [control - [monad (#+ do Monad)]] + [monad (#+ do)] + {[0 #test] + [/ + [".T" functor (#+ Injection Comparison)] + [".T" apply] + [".T" monad] + [".T" equivalence]]}] [data - ["&" lazy]] + text/format + [number + ["." nat]]] [math - ["r" random]]] - lux/test) + ["r" random (#+ Random)]]] + {1 + ["." / (#+ Lazy)]}) -(context: "Lazy." - (<| (times 100) - (do @ +(def: injection + (Injection Lazy) + (|>> /.freeze)) + +(def: comparison + (Comparison Lazy) + (function (_ ==) + (:: (/.equivalence ==) =))) + +(def: #export lazy + (All [a] (-> (Random a) (Random (Lazy a)))) + (:: r.functor map (|>> /.freeze))) + +(def: #export test + Test + (<| (_.context (%name (name-of /.Lazy))) + (do r.monad [left r.nat right r.nat - #let [lazy (&.freeze (n/* left right)) + #let [lazy (/.freeze (n/* left right)) expected (n/* left right)]] - ($_ seq - (test "Lazying does not alter the expected value." - (n/= expected - (&.thaw lazy))) - (test "Lazy values only evaluate once." - (and (not (is? expected - (&.thaw lazy))) - (is? (&.thaw lazy) - (&.thaw lazy)))) - )))) - -(context: "Functor, Apply, Monad." - (<| (times 100) - (do @ - [sample r.nat] - ($_ seq - (test "Functor map." - (|> (&.freeze sample) - (:: &.functor map inc) - &.thaw - (n/= (inc sample)))) - - (test "Monad." - (|> (do &.monad - [f (wrap inc) - a (wrap sample)] - (wrap (f a))) - &.thaw - (n/= (inc sample)))) - - (test "Apply apply." - (let [(^open "&;.") &.monad - (^open "&;.") &.apply] - (|> (&;apply (&;wrap inc) (&;wrap sample)) - &.thaw - (n/= (inc sample))))) + ($_ _.and + (_.test "Freezing does not alter the expected value." + (n/= expected + (/.thaw lazy))) + (_.test "Lazy values only evaluate once." + (and (not (is? expected + (/.thaw lazy))) + (is? (/.thaw lazy) + (/.thaw lazy)))) + (equivalenceT.test (/.equivalence nat.equivalence) (..lazy r.nat)) + (functorT.laws ..injection ..comparison /.functor) + (applyT.laws ..injection ..comparison /.apply) + (monadT.laws ..injection ..comparison /.monad) )))) |