diff options
Diffstat (limited to 'stdlib/source/test/lux/type/poly/equivalence.lux')
-rw-r--r-- | stdlib/source/test/lux/type/poly/equivalence.lux | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/type/poly/equivalence.lux b/stdlib/source/test/lux/type/poly/equivalence.lux new file mode 100644 index 000000000..14c763226 --- /dev/null +++ b/stdlib/source/test/lux/type/poly/equivalence.lux @@ -0,0 +1,83 @@ +(.module: + [library + [lux (#- Variant) + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + [equivalence (#+ Equivalence) + [\\poly + ["." /]]] + [\\specification + ["$." equivalence]]] + [control + ["." maybe]] + [data + ["." bit] + ["." text] + [collection + ["." list]]] + [math + ["." random (#+ Random)] + [number + ["n" nat] + ["i" int]]] + [type + [poly (#+ derived:)]]]]) + +(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 + (Random Recursive) + (random.rec (function (_ gen_recursive) + (random.or random.safe_frac + (random.and random.safe_frac + gen_recursive))))) + +(def: random + (Random Record) + (do {! random.monad} + [size (\ ! map (n.% 2) random.nat) + .let [gen_int (|> random.int (\ ! map (|>> i.abs (i.% +1,000,000))))]] + ($_ random.and + random.bit + gen_int + random.safe_frac + (random.unicode size) + (random.maybe gen_int) + (random.list size gen_int) + ($_ random.or + random.bit + gen_int + random.safe_frac) + ($_ random.and + gen_int + random.safe_frac + (random.unicode size)) + gen_recursive))) + +(derived: equivalence + (/.equivalence Record)) + +(def: .public test + Test + (<| (_.covering /._) + (_.for [/.equivalence] + ($equivalence.spec ..equivalence ..random)))) |