aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/function.lux
blob: fe8c69b0778bbc276e0bd8bb840d2f036869d2bf (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
76
77
78
79
80
81
82
83
(.require
 [library
  [lux (.except)
   [abstract
    [equivalence (.only Equivalence)]
    [monad (.only do)]
    [\\specification
     ["$[0]" monoid]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" /]]
 ["[0]" /
  ["[1][0]" contract]
  ["[1][0]" memo]
  ["[1][0]" mixin]
  ["[1][0]" mutual]
  ["[1][0]" inline]
  ["[1][0]" predicate]
  ["[1][0]" variadic]
  ["[1][0]" named]
  ["[1][0]" trampoline]
  ["[1][0]" polymorphism
   ["[1]/[0]" type]
   ["[1]/[0]" predicate]
   ["[1]/[0]" context]]])

(def .public test
  Test
  (do [! random.monad]
    [expected random.nat
     f0 (at ! each n.+ random.nat)
     f1 (at ! each n.* random.nat)
     dummy random.nat
     extra (|> random.nat (random.only (|>> (n.= expected) not)))]
    (<| (_.covering /._)
        (all _.and
             (let [equivalence (is (Equivalence (-> Nat Nat))
                                   (implementation
                                    (def (= left right)
                                      (n.= (left extra)
                                           (right extra)))))
                   generator (is (Random (-> Nat Nat))
                                 (at ! each n.- random.nat))]
               (_.for [/.monoid]
                      ($monoid.spec equivalence /.monoid generator)))
             
             (_.coverage [/.identity]
               (n.= expected
                    (/.identity expected)))
             (_.coverage [/.composite]
               (n.= (f0 (f1 expected))
                    ((/.composite f0 f1) expected)))
             (_.coverage [/.constant]
               (n.= expected
                    ((/.constant expected) dummy)))
             (_.coverage [/.flipped]
               (let [outcome ((/.flipped n.-) expected extra)]
                 (and (n.= (n.- extra expected)
                           outcome)
                      (not (n.= (n.- expected extra)
                                outcome)))))
             (_.coverage [/.on]
               (n.= (f0 extra)
                    (/.on extra f0)))

             /contract.test
             /memo.test
             /mixin.test
             /mutual.test
             /inline.test
             /predicate.test
             /variadic.test
             /named.test
             /trampoline.test
             /polymorphism/type.test
             /polymorphism/predicate.test
             /polymorphism/context.test
             ))))