aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/monad.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/abstract/monad.lux')
-rw-r--r--stdlib/source/test/lux/abstract/monad.lux63
1 files changed, 62 insertions, 1 deletions
diff --git a/stdlib/source/test/lux/abstract/monad.lux b/stdlib/source/test/lux/abstract/monad.lux
index e35a07a2a..5cf985999 100644
--- a/stdlib/source/test/lux/abstract/monad.lux
+++ b/stdlib/source/test/lux/abstract/monad.lux
@@ -1,6 +1,9 @@
(.require
[library
[lux (.except)
+ [abstract
+ [functor
+ [\\test (.only Injection Comparison)]]]
[data
["[0]" identity (.only Identity)]
[collection
@@ -12,11 +15,65 @@
[test
["_" property (.only Test)]]]]
[\\library
- ["[0]" / (.only Monad do)]]
+ ["[0]" / (.only do)
+ ["[0]" free]]]
["[0]" /
["[1][0]" free]
["[1][0]" indexed]])
+(def (left_identity injection comparison (open "_//[0]"))
+ (All (_ !)
+ (-> (Injection !) (Comparison !) (/.Monad !)
+ Test))
+ (do [! random.monad]
+ [sample random.nat
+ morphism (of ! each (function (_ diff)
+ (|>> (n.+ diff) _//in))
+ random.nat)]
+ (_.test "Left identity."
+ ((comparison n.=)
+ (|> (injection sample) (_//each morphism) _//conjoint)
+ (morphism sample)))))
+
+(def (right_identity injection comparison (open "_//[0]"))
+ (All (_ !)
+ (-> (Injection !) (Comparison !) (/.Monad !)
+ Test))
+ (do random.monad
+ [sample random.nat]
+ (_.test "Right identity."
+ ((comparison n.=)
+ (|> (injection sample) (_//each _//in) _//conjoint)
+ (injection sample)))))
+
+(def (associativity injection comparison (open "_//[0]"))
+ (All (_ !)
+ (-> (Injection !) (Comparison !) (/.Monad !)
+ Test))
+ (do [! random.monad]
+ [sample random.nat
+ increase (of ! each (function (_ diff)
+ (|>> (n.+ diff) _//in))
+ random.nat)
+ decrease (of ! each (function (_ diff)
+ (|>> (n.- diff) _//in))
+ random.nat)]
+ (_.test "Associativity."
+ ((comparison n.=)
+ (|> (injection sample) (_//each increase) _//conjoint (_//each decrease) _//conjoint)
+ (|> (injection sample) (_//each (|>> increase (_//each decrease) _//conjoint)) _//conjoint)))))
+
+(def .public (spec injection comparison monad)
+ (All (_ !)
+ (-> (Injection !) (Comparison !) (/.Monad !)
+ Test))
+ (<| (_.for [/.Monad])
+ (all _.and
+ (..left_identity injection comparison monad)
+ (..right_identity injection comparison monad)
+ (..associativity injection comparison monad)
+ )))
+
(def .public test
Test
(do random.monad
@@ -67,5 +124,9 @@
(is (Identity Nat)))))
/free.test
+ (_.for [free.monad]
+ (..spec /free.injection /free.comparison (is (/.Monad (free.Free List))
+ (free.monad list.functor))))
+
/indexed.test
))))