aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/type/poly/equivalence.lux
blob: 6be8c7ec6ddfbf6a401ee1d97906f25f6d7bb4d9 (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
(.using
 [library
  [lux (.except Variant Record)
   ["_" test (.only Test)]
   ["@" target]
   [abstract
    [monad (.only do)]
    [equivalence (.only Equivalence)
     [\\poly
      ["[0]" /]]]
    [\\specification
     ["$[0]" equivalence]]]
   [control
    ["[0]" maybe]]
   [data
    ["[0]" bit]
    ["[0]" text]
    [collection
     ["[0]" list]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]
     ["i" int]]]]])

(type: Variant
  (.Variant
   {#Case0 Bit}
   {#Case1 Int}
   {#Case2 Frac}))

(type: Recursive
  (Rec Recursive
    (.Variant
     {#Number Frac}
     {#Addition Frac Recursive})))

(type: Record
  (.Record
   [#bit Bit
    #int Int
    #frac Frac
    #text Text
    #maybe (Maybe Int)
    #list (List Int)
    #variant Variant
    #tuple [Int Frac Text]
    #recursive Recursive]))

(def: gen_recursive
  (Random Recursive)
  (random.rec (function (_ gen_recursive)
                (random.or random.safe_frac
                           (random.and random.safe_frac
                                       gen_recursive)))))

(def: random
  (Random Record)
  (do [! random.monad]
    [size (# ! each (n.% 2) random.nat)
     .let [gen_int (|> random.int (# ! each (|>> i.abs (i.% +1,000,000))))]]
    (all random.and
         random.bit
         gen_int
         random.safe_frac
         (random.unicode size)
         (random.maybe gen_int)
         (random.list size gen_int)
         (all random.or
              random.bit
              gen_int
              random.safe_frac)
         (all random.and
              gen_int
              random.safe_frac
              (random.unicode size))
         gen_recursive)))

(for @.old (these)
     (these (def: equivalence
              (Equivalence ..Record)
              (/.equivalence ..Record))))

(def: .public test
  Test
  (<| (_.covering /._)
      (_.for [/.equivalence]
             (for @.old (_.property "PLACEHOLDER" true)
                  ($equivalence.spec ..equivalence ..random)))))