blob: 441f422bb0fe45b86280cee88429412512df53d8 (
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> (#ls;Variant tagS 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> (#ls;Tuple membersS)
(and (n.= size (list;size membersS))
(list;every? (product;uncurry corresponds?) (list;zip2 membersA membersS)))
_
false)))
))))
|