(.module: [library [lux #* ["_" test (#+ Test)] [abstract [monad (#+ do)] [equivalence (#+ Equivalence)] [functor [\\specification ["$." contravariant]]]] [control ["." try]] [data ["." text ("#\." equivalence)] ["." bit] ["." name] [format ["." xml] ["." json]] [collection ["." list ("#\." functor)]]] ["." time ["." day] ["." month] ["." instant] ["." duration] ["." date]] [math ["." random (#+ Random) ("#\." monad)] ["." modulus] ["." modular] [number ["." nat] ["." int] ["." rev] ["." frac] ["." ratio]]] [macro ["." code]] [meta ["." location]] ["." type]]] ["$." /// #_ [format ["#." xml] ["#." json]] ["#." name] [// ["#." type] [macro ["#." code]]]] [\\library ["." /]]) (implementation: (equivalence example) (All (_ a) (-> a (Equivalence (/.Format a)))) (def: (= reference subject) (text\= (reference example) (subject example)))) (def: random_contravariant (Random (Ex (_ a) [(/.Format a) (Random a)])) ($_ random.either (random\in [/.bit random.bit]) (random\in [/.nat random.nat]) (random\in [/.int random.int]) (random\in [/.rev random.rev]) (random\in [/.frac random.frac]) )) (def: codec Test (`` ($_ _.and (~~ (template [ ] [(do random.monad [sample ] (_.cover [] (text\= (\ encoded sample) ( sample))))] [/.bit bit.codec random.bit] [/.nat nat.decimal random.nat] [/.int int.decimal random.int] [/.rev rev.decimal random.rev] [/.frac frac.decimal random.frac] [/.ratio ratio.codec random.ratio] [/.name name.codec ($///name.random 5 5)] [/.xml xml.codec $///xml.random] [/.json json.codec $///json.random] [/.day day.codec random.day] [/.month month.codec random.month] [/.instant instant.codec random.instant] [/.duration duration.codec random.duration] [/.date date.codec random.date] [/.time time.codec random.time] [/.nat/2 nat.binary random.nat] [/.nat/8 nat.octal random.nat] [/.nat/10 nat.decimal random.nat] [/.nat/16 nat.hex random.nat] [/.int/2 int.binary random.int] [/.int/8 int.octal random.int] [/.int/10 int.decimal random.int] [/.int/16 int.hex random.int] [/.rev/2 rev.binary random.rev] [/.rev/8 rev.octal random.rev] [/.rev/10 rev.decimal random.rev] [/.rev/16 rev.hex random.rev] [/.frac/2 frac.binary random.frac] [/.frac/8 frac.octal random.frac] [/.frac/10 frac.decimal random.frac] [/.frac/16 frac.hex random.frac] )) ))) (def: .public test Test (<| (_.covering /._) (_.for [/.Format]) (`` ($_ _.and (_.for [/.functor] (do random.monad [[format random] ..random_contravariant example random] ($contravariant.spec (..equivalence example) format /.functor))) (do random.monad [left (random.unicode 5) mid (random.unicode 5) right (random.unicode 5)] (_.cover [/.format] (text\= (/.format left mid right) ($_ "lux text concat" left mid right)))) ..codec (~~ (template [ ] [(do random.monad [sample ] (_.cover [] (text\= ( sample) ( sample))))] [/.text text.format (random.unicode 5)] [/.code code.format $///code.random] [/.type type.format ($///type.random 0)] [/.location location.format ($_ random.and (random.unicode 5) random.nat random.nat)] )) (do random.monad [members (random.list 5 random.nat)] (_.cover [/.list] (text\= (/.list /.nat members) (|> members (list\each /.nat) (text.interposed " ") list (/.list (|>>)))))) (do random.monad [sample (random.maybe random.nat)] (_.cover [/.maybe] (case sample #.None true (#.Some value) (text.contains? (/.nat value) (/.maybe /.nat sample))))) (do {! random.monad} [modulus (random.one (|>> modulus.modulus try.maybe) random.int) sample (\ ! each (modular.modular modulus) random.int)] (_.cover [/.mod] (text\= (\ (modular.codec modulus) encoded sample) (/.mod sample)))) ))))