diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/abstract/enum.lux | 45 | ||||
-rw-r--r-- | stdlib/source/test/lux/control/try.lux | 89 |
2 files changed, 86 insertions, 48 deletions
diff --git a/stdlib/source/test/lux/abstract/enum.lux b/stdlib/source/test/lux/abstract/enum.lux index b67f846f5..b6a490358 100644 --- a/stdlib/source/test/lux/abstract/enum.lux +++ b/stdlib/source/test/lux/abstract/enum.lux @@ -1,7 +1,6 @@ (.module: [lux #* [data - ["%" text/format (#+ format)] ["." product] ["." maybe ("#@." functor)] [number @@ -26,35 +25,35 @@ [start end] [end start]) range (/.range n.enum start end)]] - (<| (_.context (%.name (name-of /.Enum))) + (<| (_.covering /._) ($_ _.and - (_.test (%.name (name-of /.range)) - (let [expected-size (|> end (n.- start) inc) - expected-start? (|> range list.head (maybe@map (n.= start)) (maybe.default false)) - expected-end? (|> range list.last (maybe@map (n.= end)) (maybe.default false)) - every-element-is-a-successor? (case range - (#.Cons head tail) - (|> (list@fold (function (_ next [verdict prev]) - [(and verdict - (n.= next (:: n.enum succ prev))) - next]) - [true head] - tail) - product.left) - - #.Nil - false)] - (and (n.= expected-size (list.size range)) - expected-start? - expected-end? - every-element-is-a-successor?))) + (_.cover [/.range] + (let [expected-size (|> end (n.- start) inc) + expected-start? (|> range list.head (maybe@map (n.= start)) (maybe.default false)) + expected-end? (|> range list.last (maybe@map (n.= end)) (maybe.default false)) + every-element-is-a-successor? (case range + (#.Cons head tail) + (|> (list@fold (function (_ next [verdict prev]) + [(and verdict + (n.= next (:: n.enum succ prev))) + next]) + [true head] + tail) + product.left) + + #.Nil + false)] + (and (n.= expected-size (list.size range)) + expected-start? + expected-end? + every-element-is-a-successor?))) ))))) (def: #export (spec (^open "/@.") gen-sample) (All [a] (-> (Enum a) (Random a) Test)) (do r.monad [sample gen-sample] - (<| (_.context (%.name (name-of /.Enum))) + (<| (_.with-cover [/.Enum]) ($_ _.and (_.test "Successor and predecessor are inverse functions." (and (/@= (|> sample /@succ /@pred) diff --git a/stdlib/source/test/lux/control/try.lux b/stdlib/source/test/lux/control/try.lux index 47e51b54b..08c19794d 100644 --- a/stdlib/source/test/lux/control/try.lux +++ b/stdlib/source/test/lux/control/try.lux @@ -13,11 +13,11 @@ pipe ["." io]] [data - ["%" text/format (#+ format)] + ["." text ("#@." equivalence)] [number ["n" nat]]] [math - ["r" random (#+ Random)]]] + ["." random (#+ Random)]]] {1 ["." / (#+ Try)]}) @@ -32,33 +32,72 @@ (def: #export (try element) (All [a] (-> (Random a) (Random (Try a)))) - ($_ r.or - (r.unicode 1) + ($_ random.or + (random.unicode 1) element)) (def: #export test Test - (<| (_.context (%.name (name-of /._))) + (<| (_.covering /._) + (_.with-cover [/.Try]) + (do random.monad + [expected random.nat + alternative (|> random.nat (random.filter (|>> (n.= expected) not))) + error (random.unicode 1) + #let [(^open "io@.") io.monad]]) ($_ _.and - ($equivalence.spec (/.equivalence n.equivalence) (..try r.nat)) - ($functor.spec ..injection ..comparison /.functor) - ($apply.spec ..injection ..comparison /.apply) - ($monad.spec ..injection ..comparison /.monad) - (do r.monad - [left r.nat - right r.nat - #let [expected (n.+ left right) - (^open "io@.") io.monad]] - (_.test "Can add try functionality to any monad." - (let [lift (/.lift io.monad)] - (|> (do (/.with io.monad) - [a (lift (io@wrap left)) - b (wrap right)] - (wrap (n.+ a b))) - io.run - (case> (#/.Success actual) - (n.= expected actual) + (_.with-cover [/.equivalence] + ($equivalence.spec (/.equivalence n.equivalence) (..try random.nat))) + (_.with-cover [/.functor] + ($functor.spec ..injection ..comparison /.functor)) + (_.with-cover [/.apply] + ($apply.spec ..injection ..comparison /.apply)) + (_.with-cover [/.monad] + ($monad.spec ..injection ..comparison /.monad)) - _ - false))))) + (_.cover [/.succeed] + (case (/.succeed expected) + (#/.Success actual) + (n.= expected actual) + + _ + false)) + (_.cover [/.fail] + (case (/.fail error) + (#/.Failure message) + (text@= error message) + + _ + false)) + (_.cover [/.assume] + (n.= expected + (/.assume (/.succeed expected)))) + (_.cover [/.maybe] + (case [(/.maybe (/.succeed expected)) + (/.maybe (/.fail error))] + [(#.Some actual) #.None] + (n.= expected actual) + + _ + false)) + (_.cover [/.default] + (and (n.= expected + (/.default alternative (/.succeed expected))) + (n.= alternative + (/.default alternative (: (Try Nat) + (/.fail error)))))) + + (_.cover [/.with /.lift] + (let [lift (/.lift io.monad)] + (|> (do (/.with io.monad) + [a (lift (io@wrap expected)) + b (wrap alternative)] + (wrap (n.+ a b))) + io.run + (case> (#/.Success result) + (n.= (n.+ expected alternative) + result) + + _ + false)))) ))) |