aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/function/polymorphism/predicate.lux
blob: 10f60809441ce3e62cf2b01f9eda30f7b360ec78 (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
(.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))))
           )))