aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/control/lazy.lux
blob: 9343107fd3528a804cf37e619a7e75c91501377e (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
(.require
 [library
  [lux (.except)
   [abstract
    ["[0]" monad (.only do)
     ["[1]T" \\test]]
    ["[0]" functor
     ["[1]T" \\test (.only Injection Comparison)]]
    ["[0]" apply
     ["[1]T" \\test]]
    ["[0]" equivalence
     ["[1]T" \\test]]]
   [data
    ["[0]" product]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only Lazy)]])

(def injection
  (Injection Lazy)
  (|>> /.lazy))

(def comparison
  (Comparison Lazy)
  (function (_ ==)
    (of (/.equivalence ==) =)))

(def .public lazy
  (All (_ a) (-> (Random a) (Random (Lazy a))))
  (of random.functor each (|>> /.lazy)))

(def .public test
  Test
  (with_expansions [<eager> (is [Nat Nat]
                                [(n.+ left right)
                                 (n.* left right)])]
    (<| (_.covering /._)
        (do random.monad
          [left random.nat
           right random.nat
           .let [expected <eager>]]
          (_.for [/.Lazy]
                 (all _.and
                      (_.for [/.equivalence]
                             (equivalenceT.spec (/.equivalence n.equivalence) (..lazy random.nat)))
                      (_.for [/.functor]
                             (functorT.spec ..injection ..comparison /.functor))
                      (_.for [/.apply]
                             (applyT.spec ..injection ..comparison /.apply))
                      (_.for [/.monad]
                             (monadT.spec ..injection ..comparison /.monad))

                      (_.coverage [/.lazy]
                        (let [lazy (/.lazy <eager>)
                              (open "_#=") (product.equivalence n.equivalence n.equivalence)]
                          (_#= expected
                               (/.value lazy))))

                      (_.coverage [/.value]
                        (let [lazy (/.lazy <eager>)]
                          (and (not (same? expected
                                           (/.value lazy)))
                               (same? (/.value lazy)
                                      (/.value lazy)))))
                      ))))))