blob: 8280e000eed87e98f9d168692431b9268f522c43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
(.module:
[lux #*
["%" data/text/format (#+ format)]
["_" test (#+ Test)]
[math
["." random (#+ Random)]]
[abstract
[monad (#+ do)]
[equivalence (#+ Equivalence)
{[0 #poly]
["." /]}]]
[data
["." bit]
["." maybe]
[number
["n" nat]
["i" int]]
["." text]
[collection
["." list]]]
["." macro
[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.frac
(random.and random.frac gen-recursive)))))
(def: gen-record
(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.frac
(random.unicode size)
(random.maybe gen-int)
(random.list size gen-int)
($_ random.or random.bit gen-int random.frac)
($_ random.and gen-int random.frac (random.unicode size))
gen-recursive)))
(derived: equivalence (/.equivalence Record))
(def: #export test
Test
(<| (_.context (%.name (name-of /._)))
(do random.monad
[sample gen-record
#let [(^open "/@.") ..equivalence]]
(_.test "Every instance equals itself."
(/@= sample sample)))))
|