aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/math.lux
blob: 3695f4be8488044ce1dfe2afeb332f65bdc30084 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
(.using
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [data
    ["[0]" bit (.open: "[1]#[0]" equivalence)]]
   [macro
    ["[0]" template]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]
     ["i" int]
     ["r" rev]
     ["f" frac]
     ["[0]" ratio (.only Ratio)]
     ["[0]" complex (.only Complex)]]]]]
 [\\library
  ["[0]" /]]
 ["[0]" /
  ["[1][0]" infix]
  ["[1][0]" modulus]
  ["[1][0]" modular]
  ["[1][0]" number]
  ["[1][0]" logic
   ["[1]/[0]" continuous]
   ["[1]/[0]" fuzzy]]])

(def: ratio/0
  Ratio
  [ratio.#numerator 0 ratio.#denominator 1])

(def: complex/0
  Complex
  [complex.#real +0.0 complex.#imaginary +0.0])

(def: .public test
  Test
  (<| (_.covering /._)
      (do random.monad
        [parameterN (random.only (|>> (n.= 0) not) random.nat)
         subjectN random.nat

         parameterI (random.only (|>> (i.= +0) not) random.int)
         subjectI random.int

         parameterR (random.only (|>> (r.= .0) not) random.rev)
         subjectR random.rev

         parameterF (random.only (|>> (f.= +0.0) not) random.safe_frac)
         subjectF random.safe_frac

         parameter/ (random.only (|>> (ratio.= ratio/0) not) random.ratio)
         subject/ random.ratio

         parameterC (random.only (|>> (complex.= complex/0) not) random.complex)
         subjectC random.complex])
      (`` (all _.and
               (~~ (with_template [</> <scenarios>']
                     [(_.coverage [</>]
                        (with_expansions [<scenarios> (template.spliced <scenarios>')]
                          (`` (and (~~ (with_template [<=> <//> <parameter> <subject>]
                                         [(<=> (<//> <parameter> <subject>)
                                               (</> <parameter> <subject>))]
                                         
                                         <scenarios>))))))]

                     [/.+ [[n.= n.+ parameterN subjectN]
                           [i.= i.+ parameterI subjectI]
                           [r.= r.+ parameterR subjectR]
                           [f.= f.+ parameterF subjectF]
                           [ratio.= ratio.+ parameter/ subject/]
                           [complex.= complex.+ parameterC subjectC]]]
                     [/.- [[n.= n.- parameterN subjectN]
                           [i.= i.- parameterI subjectI]
                           [r.= r.- parameterR subjectR]
                           [f.= f.- parameterF subjectF]
                           [ratio.= ratio.- parameter/ subject/]
                           [complex.= complex.- parameterC subjectC]]]
                     [/.* [[n.= n.* parameterN subjectN]
                           [i.= i.* parameterI subjectI]
                           [r.= r.* parameterR subjectR]
                           [f.= f.* parameterF subjectF]
                           [ratio.= ratio.* parameter/ subject/]
                           [complex.= complex.* parameterC subjectC]]]
                     [/./ [[n.= n./ parameterN subjectN]
                           [i.= i./ parameterI subjectI]
                           [r.= r./ parameterR subjectR]
                           [f.= f./ parameterF subjectF]
                           [ratio.= ratio./ parameter/ subject/]
                           [complex.= complex./ parameterC subjectC]]]
                     [/.% [[n.= n.% parameterN subjectN]
                           [i.= i.% parameterI subjectI]
                           [r.= r.% parameterR subjectR]
                           [f.= f.% parameterF subjectF]
                           [ratio.= ratio.% parameter/ subject/]
                           [complex.= complex.% parameterC subjectC]]]
                     ))
               (~~ (with_template [</> <scenarios>']
                     [(_.coverage [</>]
                        (with_expansions [<scenarios> (template.spliced <scenarios>')]
                          (`` (and (~~ (with_template [<//> <parameter> <subject>]
                                         [(bit#= (<//> <parameter> <subject>)
                                                 (</> <parameter> <subject>))]
                                         
                                         <scenarios>))))))]

                     [/.= [[n.= parameterN subjectN]
                           [i.= parameterI subjectI]
                           [r.= parameterR subjectR]
                           [f.= parameterF subjectF]
                           [ratio.= parameter/ subject/]
                           [complex.= parameterC subjectC]]]
                     [/.< [[n.< parameterN subjectN]
                           [i.< parameterI subjectI]
                           [r.< parameterR subjectR]
                           [f.< parameterF subjectF]
                           [ratio.< parameter/ subject/]]]
                     [/.<= [[n.<= parameterN subjectN]
                            [i.<= parameterI subjectI]
                            [r.<= parameterR subjectR]
                            [f.<= parameterF subjectF]
                            [ratio.<= parameter/ subject/]]]
                     [/.> [[n.> parameterN subjectN]
                           [i.> parameterI subjectI]
                           [r.> parameterR subjectR]
                           [f.> parameterF subjectF]
                           [ratio.> parameter/ subject/]]]
                     [/.>= [[n.>= parameterN subjectN]
                            [i.>= parameterI subjectI]
                            [r.>= parameterR subjectR]
                            [f.>= parameterF subjectF]
                            [ratio.>= parameter/ subject/]]]
                     ))

               /infix.test
               /modulus.test
               /modular.test
               /number.test
               /logic/continuous.test
               /logic/fuzzy.test
               ))))