aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/specification/lux/abstract/codec.lux
blob: 9a39f4b1ce65632fe5745bc2739b9d5ffb52a20f (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)))))