diff options
Diffstat (limited to 'stdlib/source/test/lux/data/maybe.lux')
-rw-r--r-- | stdlib/source/test/lux/data/maybe.lux | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/stdlib/source/test/lux/data/maybe.lux b/stdlib/source/test/lux/data/maybe.lux index a10e0154e..24114f6c0 100644 --- a/stdlib/source/test/lux/data/maybe.lux +++ b/stdlib/source/test/lux/data/maybe.lux @@ -6,6 +6,7 @@ {[0 #spec] [/ ["$." equivalence] + ["$." monoid] ["$." functor] ["$." apply] ["$." monad]]}] @@ -13,58 +14,64 @@ ["." io ("#@." monad)] pipe] [data - ["." text - ["%" format (#+ format)]] + ["." text] [number - ["n" nat]]] + ["n" nat]] + [collection + ["." list]]] [math - ["r" random (#+ Random)]]] + ["." random (#+ Random)]]] {1 ["." / ("#@." monoid monad)]}) -(def: #export maybe - (All [a] (-> (Random a) (Random (Maybe a)))) - (:: r.functor map (|>> #.Some))) - (def: #export test Test - (<| (_.context (%.name (name-of .Maybe))) - ($_ _.and - ($equivalence.spec (/.equivalence n.equivalence) (..maybe r.nat)) - ($functor.spec /@wrap /.equivalence /.functor) - ($apply.spec /@wrap /.equivalence /.apply) - ($monad.spec /@wrap /.equivalence /.monad) - - (do r.monad - [left r.nat - right r.nat - #let [expected (n.+ left right)]] - (let [lift (/.lift io.monad)] - (_.test "Can add maybe functionality to any monad." - (|> (io.run (do (/.with io.monad) - [a (lift (io@wrap left)) - b (wrap right)] - (wrap (n.+ a b)))) - (case> (#.Some actual) - (n.= expected actual) + (<| (_.covering /._) + (_.with-cover [.Maybe] + ($_ _.and + (_.with-cover [/.equivalence] + ($equivalence.spec (/.equivalence n.equivalence) (random.maybe random.nat))) + (_.with-cover [/.monoid] + ($monoid.spec (/.equivalence n.equivalence) /.monoid (random.maybe random.nat))) + (_.with-cover [/.functor] + ($functor.spec /@wrap /.equivalence /.functor)) + (_.with-cover [/.apply] + ($apply.spec /@wrap /.equivalence /.apply)) + (_.with-cover [/.monad] + ($monad.spec /@wrap /.equivalence /.monad)) + + (do random.monad + [left random.nat + right random.nat + #let [expected (n.+ left right)]] + (let [lift (/.lift io.monad)] + (_.cover [/.with /.lift] + (|> (io.run (do (/.with io.monad) + [a (lift (io@wrap left)) + b (wrap right)] + (wrap (n.+ a b)))) + (case> (#.Some actual) + (n.= expected actual) - _ - false))))) - (let [(^open "/@.") (/.equivalence text.equivalence) - (^open "/@.") /.monoid] - (_.test "Monoid respects Maybe." - (and (/@= #.None /@identity) - (/@= (#.Some "yolo") (/@compose (#.Some "yolo") (#.Some "lol"))) - (/@= (#.Some "yolo") (/@compose (#.Some "yolo") #.None)) - (/@= (#.Some "lol") (/@compose #.None (#.Some "lol"))) - (/@= #.None (: (Maybe Text) (/@compose #.None #.None)))))) - (do r.monad - [default r.nat - value r.nat] - (_.test "Can have defaults for Maybe values." - (and (is? default (/.default default - #.None)) + _ + false))))) + (do random.monad + [default random.nat + value random.nat] + (_.cover [/.default] + (and (is? default (/.default default + #.None)) - (is? value (/.default default - (#.Some value)))))) - ))) + (is? value (/.default default + (#.Some value)))))) + (do random.monad + [value random.nat] + (_.cover [/.assume] + (is? value (/.assume (#.Some value))))) + (do random.monad + [value random.nat] + (_.cover [/.to-list] + (:: (list.equivalence n.equivalence) = + (list value) + (/.to-list (#.Some value))))) + )))) |