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

(def: .public (spec (^open "@//.") (^open "@//.") 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)))))