diff options
| author | Eduardo Julian | 2020-10-07 17:00:57 -0400 | 
|---|---|---|
| committer | Eduardo Julian | 2020-10-07 17:00:57 -0400 | 
| commit | ce7614f00a134cb61b4a6f88cfea33461a7bf478 (patch) | |
| tree | fcd6fd7206ceef50db7687c6d4d8b71ff581d41b /stdlib/source/spec | |
| parent | de673c2adf9fdf848f8fff977a6cddc036cbfa9e (diff) | |
Test imports for circular dependencies.
Diffstat (limited to 'stdlib/source/spec')
| -rw-r--r-- | stdlib/source/spec/lux/abstract/comonad.lux | 61 | 
1 files changed, 61 insertions, 0 deletions
diff --git a/stdlib/source/spec/lux/abstract/comonad.lux b/stdlib/source/spec/lux/abstract/comonad.lux new file mode 100644 index 000000000..3dfda0bbf --- /dev/null +++ b/stdlib/source/spec/lux/abstract/comonad.lux @@ -0,0 +1,61 @@ +(.module: +  [lux #* +   [abstract +    [monad (#+ do)]] +   [data +    [number +     ["n" nat]]] +   [math +    ["." random]] +   ["_" test (#+ Test)]] +  {1 +   ["." / (#+ CoMonad)]} +  [// +   [functor (#+ Injection Comparison)]]) + +(def: (left-identity injection (^open "_@.")) +  (All [f] (-> (Injection f) (CoMonad f) Test)) +  (do {@ random.monad} +    [sample random.nat +     morphism (:: @ map (function (_ diff) +                          (|>> _@unwrap (n.+ diff))) +                  random.nat) +     #let [start (injection sample)]] +    (_.test "Left identity." +            (n.= (morphism start) +                 (|> start _@split (_@map morphism) _@unwrap))))) + +(def: (right-identity injection comparison (^open "_@.")) +  (All [f] (-> (Injection f) (Comparison f) (CoMonad f) Test)) +  (do random.monad +    [sample random.nat +     #let [start (injection sample) +           == (comparison n.=)]] +    (_.test "Right identity." +            (== start +                (|> start _@split (_@map _@unwrap)))))) + +(def: (associativity injection comparison (^open "_@.")) +  (All [f] (-> (Injection f) (Comparison f) (CoMonad f) Test)) +  (do {@ random.monad} +    [sample random.nat +     increase (:: @ map (function (_ diff) +                          (|>> _@unwrap (n.+ diff))) +                  random.nat) +     decrease (:: @ map (function (_ diff) +                          (|>> _@unwrap(n.- diff))) +                  random.nat) +     #let [start (injection sample) +           == (comparison n.=)]] +    (_.test "Associativity." +            (== (|> start _@split (_@map (|>> _@split (_@map increase) decrease))) +                (|> start _@split (_@map increase) _@split (_@map decrease)))))) + +(def: #export (spec injection comparison monad) +  (All [f] (-> (Injection f) (Comparison f) (CoMonad f) Test)) +  (<| (_.with-cover [/.CoMonad]) +      ($_ _.and +          (..left-identity injection monad) +          (..right-identity injection comparison monad) +          (..associativity injection comparison monad) +          )))  | 
