blob: b779678af4deed69c794cbfc8d461dae0577b6bf (
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
|
(.module:
[library
[lux #*
["_" test (#+ Test)]
[abstract
[monad (#+ do)]
[\\specification
["$." equivalence]]]
[math
["." random]
[number
["n" nat]
["i" int]]]]]
[\\library
["." /]])
(def: .public test
Test
(<| (_.covering /._)
(_.for [.Tuple .And])
(do random.monad
[expected random.nat
shift random.nat
dummy (random.only (|>> (n.= expected) not)
random.nat)]
($_ _.and
(_.for [/.equivalence]
($equivalence.spec (/.equivalence n.equivalence i.equivalence)
(random.and random.nat random.int)))
(do random.monad
[left random.int
right random.nat]
(_.cover [/.hash]
(let [hash (/.hash i.hash n.hash)]
(n.= (n.+ (\ i.hash hash left)
(\ n.hash hash right))
(\ hash hash [left right])))))
(<| (_.cover [/.left])
(n.= expected (/.left [expected dummy])))
(<| (_.cover [/.right])
(n.= expected (/.right [dummy expected])))
(<| (_.cover [/.forked])
(let [[left right] ((/.forked (n.+ shift) (n.- shift)) expected)]
(and (n.= (n.+ shift expected)
left)
(n.= (n.- shift expected)
right))))
(do random.monad
[left random.nat
right random.nat]
($_ _.and
(<| (_.cover [/.swapped])
(let [pair [left right]]
(and (n.= (/.left pair)
(/.right (/.swapped pair)))
(n.= (/.right pair)
(/.left (/.swapped pair))))))
(<| (_.cover [/.uncurried])
(n.= (n.+ left right)
((/.uncurried n.+) [left right])))
(<| (_.cover [/.curried])
(n.= (n.+ left right)
((/.curried (/.uncurried n.+)) left right)))
(<| (_.cover [/.then])
(let [[left' right'] (/.then (n.+ shift) (n.- shift) [left right])]
(and (n.= (n.+ shift left) left')
(n.= (n.- shift right) right'))))))
))))
|