aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/pipe.lux
blob: a61671c97e50d2ce51959ddd0864a8b83d8ec9cd (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(.module:
  [library
   [lux "*"
    ["_" test {"+" [Test]}]
    ["." debug]
    [abstract
     [monad {"+" [do]}]]
    [data
     ["." identity]
     ["." text ("#\." equivalence)
      ["%" format {"+" [format]}]]]
    [math
     ["." random]
     [number
      ["n" nat]]]]]
  [\\library
   ["." /]])

(def: .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [sample random.nat]
        ($_ _.and
            (do !
              [another random.nat]
              (_.cover [/.new>]
                       (n.= (++ another)
                            (|> sample
                                (n.* 3)
                                (n.+ 4)
                                (/.new> another [++])))))
            (_.cover [/.let>]
                     (n.= (n.+ sample sample)
                          (|> sample
                              (/.let> x [(n.+ x x)]))))
            (_.cover [/.cond>]
                     (text\= (cond (n.= 0 sample) "zero"
                                   (n.even? sample) "even"
                                   "odd")
                             (|> sample
                                 (/.cond> [(n.= 0)] [(/.new> "zero" [])]
                                          [n.even?] [(/.new> "even" [])]
                                          [(/.new> "odd" [])]))))
            (_.cover [/.if>]
                     (text\= (if (n.even? sample)
                               "even"
                               "odd")
                             (|> sample
                                 (/.if> [n.even?]
                                        [(/.new> "even" [])]
                                        [(/.new> "odd" [])]))))
            (_.cover [/.when>]
                     (n.= (if (n.even? sample)
                            (n.* 2 sample)
                            sample)
                          (|> sample
                              (/.when> [n.even?]
                                       [(n.* 2)]))))
            (_.cover [/.loop>]
                     (n.= (n.* 10 sample)
                          (|> sample
                              (/.loop> [(n.= (n.* 10 sample)) not]
                                       [(n.+ sample)]))))
            (_.cover [/.do>]
                     (n.= (++ (n.+ 4 (n.* 3 sample)))
                          (|> sample
                              (/.do> identity.monad
                                     [(n.* 3)]
                                     [(n.+ 4)]
                                     [++]))))
            (_.cover [/.exec>]
                     (n.= (n.* 10 sample)
                          (|> sample
                              (/.exec> [%.nat (format "sample = ") debug.log!])
                              (n.* 10))))
            (_.cover [/.tuple>]
                     (let [[left middle right] (|> sample
                                                   (/.tuple> [++]
                                                             [--]
                                                             [%.nat]))]
                       (and (n.= (++ sample) left)
                            (n.= (-- sample) middle)
                            (text\= (%.nat sample) right))))
            (_.cover [/.case>]
                     (text\= (case (n.% 10 sample)
                               0 "zero"
                               1 "one"
                               2 "two"
                               3 "three"
                               4 "four"
                               5 "five"
                               6 "six"
                               7 "seven"
                               8 "eight"
                               9 "nine"
                               _ "???")
                             (|> sample
                                 (n.% 10)
                                 (/.case> 0 "zero"
                                          1 "one"
                                          2 "two"
                                          3 "three"
                                          4 "four"
                                          5 "five"
                                          6 "six"
                                          7 "seven"
                                          8 "eight"
                                          9 "nine"
                                          _ "???"))))
            ))))