aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/macro/poly/equivalence.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-02-05 19:09:31 -0400
committerEduardo Julian2019-02-05 19:09:31 -0400
commit47b97c128bde837fa803a605f3e011a3e9ddd71c (patch)
tree5e8a84d1b1812ec4a157d4049c778ec2e4e434c4 /stdlib/source/test/lux/macro/poly/equivalence.lux
parentbe5710d104e6ee085dcb9d871be0b80305e48f8b (diff)
Integrated tests into normal source code.
Diffstat (limited to 'stdlib/source/test/lux/macro/poly/equivalence.lux')
-rw-r--r--stdlib/source/test/lux/macro/poly/equivalence.lux71
1 files changed, 71 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/macro/poly/equivalence.lux b/stdlib/source/test/lux/macro/poly/equivalence.lux
new file mode 100644
index 000000000..3d943f6e6
--- /dev/null
+++ b/stdlib/source/test/lux/macro/poly/equivalence.lux
@@ -0,0 +1,71 @@
+(.module:
+ [lux #*
+ [control
+ [monad (#+ do Monad)]
+ [equivalence (#+ Equivalence)]]
+ [data
+ ["." bit]
+ ["." maybe]
+ [number ("int/." int-number)]
+ ["." text
+ format]
+ [collection
+ ["." list]]]
+ [math
+ ["r" random]]
+ ["." macro
+ [poly (#+ derived:)
+ ["&" equivalence]]]]
+ lux/test)
+
+(type: Variant
+ (#Case0 Bit)
+ (#Case1 Int)
+ (#Case2 Frac))
+
+(type: #rec Recursive
+ (#Number Frac)
+ (#Addition Frac Recursive))
+
+(type: Record
+ {#bit Bit
+ #int Int
+ #frac Frac
+ #text Text
+ #maybe (Maybe Int)
+ #list (List Int)
+ #variant Variant
+ #tuple [Int Frac Text]
+ #recursive Recursive})
+
+(def: gen-recursive
+ (r.Random Recursive)
+ (r.rec (function (_ gen-recursive)
+ (r.or r.frac
+ (r.and r.frac gen-recursive)))))
+
+(def: gen-record
+ (r.Random Record)
+ (do r.monad
+ [size (:: @ map (n/% 2) r.nat)
+ #let [gen-int (|> r.int (:: @ map (|>> int/abs (i/% +1_000_000))))]]
+ ($_ r.and
+ r.bit
+ gen-int
+ r.frac
+ (r.unicode size)
+ (r.maybe gen-int)
+ (r.list size gen-int)
+ ($_ r.or r.bit gen-int r.frac)
+ ($_ r.and gen-int r.frac (r.unicode size))
+ gen-recursive)))
+
+(derived: (&.Equivalence<?> Record))
+
+(context: "Equivalence polytypism"
+ (<| (times 100)
+ (do @
+ [sample gen-record
+ #let [(^open "&/.") ..equivalence]]
+ (test "Every instance equals itself."
+ (&/= sample sample)))))