aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/function/contract.lux
blob: fcff396f1093d1f81c66d3a684234d14e5d6635c (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
(.require
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" try]
    ["[0]" exception]]
   [data
    ["[0]" text]]
   [math
    ["[0]" random]
    [number
     ["n" nat]]]]]
 [\\library
  ["[0]" /]])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [expected random.nat])
      (all _.and
           (_.coverage [/.pre /.pre_condition_failed]
             (case (try (/.pre (n.even? expected)
                               true))
               {try.#Success output}
               output
               
               {try.#Failure error}
               (and (text.contains? (the exception.#label /.pre_condition_failed)
                                    error)
                    (not (n.even? expected)))))
           (_.coverage [/.post /.post_condition_failed]
             (case (try (/.post n.odd?
                                expected))
               {try.#Success actual}
               (same? expected actual)
               
               {try.#Failure error}
               (and (text.contains? (the exception.#label /.post_condition_failed)
                                    error)
                    (not (n.odd? expected)))))
           )))