aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/function/polymorphism/predicate.lux
blob: 8ffe48116aa61ddd400f9cb7fdcb5b491a62c70e (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
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["i" int]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" /]])

(/.def .public (any _ choice positive negative zero)
  [(All (_ value))] [Int value value value] value
  zero

  (/.method (any next choice positive negative zero)
    (i.> +0 choice)
    positive)

  (/.method (any next choice positive negative zero)
    (i.< +0 choice)
    negative)
  )

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [positive random.nat
         negative random.nat
         zero random.nat])
      (all _.and
           (_.coverage [/.def]
             (same? zero (any +0 positive negative zero)))
           (_.coverage [/.method]
             (and (same? positive (any +1 positive negative zero))
                  (same? negative (any -1 positive negative zero))))
           )))