blob: 517f087d1360374f4ee5eaf4c4470d996b28b7ad (
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
|
(;module:
lux
(lux [io]
(control [monad #+ do]
pipe)
(data [bool "B/" Eq<Bool>]
[product]
(coll [list]))
["r" math/random "r/" Monad<Random>]
test)
(luxc (lang ["la" analysis]
["ls" synthesis])
[synthesizer])
(.. common))
(context: "Variants"
(<| (times +100)
(do @
[size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2))))
tagA (|> r;nat (:: @ map (n.% size)))
memberA gen-primitive]
($_ seq
(test "Can synthesize variants."
(|> (synthesizer;synthesize (la;sum tagA size +0 memberA))
(case> (^ [_ (#;Form (list [_ (#;Nat tagS)] [_ (#;Bool last?S)] memberS))])
(and (n.= tagA tagS)
(B/= (n.= (n.dec size) tagA)
last?S)
(corresponds? memberA memberS))
_
false)))
))))
(context: "Tuples"
(<| (times +100)
(do @
[size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2))))
membersA (r;list size gen-primitive)]
($_ seq
(test "Can synthesize tuple."
(|> (synthesizer;synthesize (la;product membersA))
(case> [_ (#;Tuple membersS)]
(and (n.= size (list;size membersS))
(list;every? (product;uncurry corresponds?) (list;zip2 membersA membersS)))
_
false)))
))))
|