aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/specification/lux/abstract/codec.lux
blob: c220c8de608fdea9d78e95c985723abc7aeeb655 (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
(.using
  [library
   [lux "*"
    ["_" test {"+" Test}]
    [abstract
     [monad {"+" do}]]
    [control
     ["[0]" try]]
    [math
     ["[0]" random {"+" Random}]]]]
  [\\library
   ["[0]" /
    [//
     [equivalence {"+" Equivalence}]]]])

(def: .public (spec (^open "@//[0]") (^open "@//[0]") generator)
  (All (_ m a) (-> (Equivalence a) (/.Codec m a) (Random a) Test))
  (do random.monad
    [expected generator]
    (_.for [/.Codec]
           (_.test "Isomorphism."
                   (case (|> expected @//encoded @//decoded)
                     {try.#Success actual}
                     (@//= expected actual)
                     
                     {try.#Failure _}
                     false)))))