diff options
author | Eduardo Julian | 2020-03-04 21:54:41 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-03-04 21:54:41 -0400 |
commit | a6c0acbf9d5730f238292ac8a53196d98fbbda72 (patch) | |
tree | 4370164766200823751f4527396c9eab4321d617 /stdlib/source/test | |
parent | 21777826feb4affa53bf150588b70fc11bb92512 (diff) |
Test for enums + adjustments to Python-generation code.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/abstract.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/abstract/codec.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/abstract/enum.lux | 60 | ||||
-rw-r--r-- | stdlib/source/test/lux/macro/poly/json.lux | 3 |
4 files changed, 54 insertions, 13 deletions
diff --git a/stdlib/source/test/lux/abstract.lux b/stdlib/source/test/lux/abstract.lux index cbc89fce9..b35b38137 100644 --- a/stdlib/source/test/lux/abstract.lux +++ b/stdlib/source/test/lux/abstract.lux @@ -3,11 +3,13 @@ ["_" test (#+ Test)]] ["." / #_ ["#." codec] + ["#." enum] ["#." interval]]) (def: #export test Test ($_ _.and /codec.test + /enum.test /interval.test )) diff --git a/stdlib/source/test/lux/abstract/codec.lux b/stdlib/source/test/lux/abstract/codec.lux index 84a3997b3..0793ee371 100644 --- a/stdlib/source/test/lux/abstract/codec.lux +++ b/stdlib/source/test/lux/abstract/codec.lux @@ -39,7 +39,7 @@ (do r.monad [expected r.bit] (<| (_.context (%.name (name-of /.Codec))) - (_.test "Composition." + (_.test (%.name (name-of /.compose)) (case (|> expected (:: ..codec encode) (:: ..codec decode)) (#try.Success actual) (bit@= expected actual) diff --git a/stdlib/source/test/lux/abstract/enum.lux b/stdlib/source/test/lux/abstract/enum.lux index 926230ce1..b67f846f5 100644 --- a/stdlib/source/test/lux/abstract/enum.lux +++ b/stdlib/source/test/lux/abstract/enum.lux @@ -1,28 +1,68 @@ (.module: [lux #* - ["%" data/text/format (#+ format)] + [data + ["%" text/format (#+ format)] + ["." product] + ["." maybe ("#@." functor)] + [number + ["n" nat]] + [collection + ["." list ("#@." fold)]]] ["_" test (#+ Test)] - [control - ["." function]] [abstract/monad (#+ do)] [math ["r" random (#+ Random)]]] {1 ["." / (#+ Enum)]}) +(def: #export test + Test + (let [limit (: (Random Nat) + (:: r.monad map (n.% 20) r.nat))] + (do r.monad + [start limit + end limit + #let [[start end] (if (n.< end start) + [start end] + [end start]) + range (/.range n.enum start end)]] + (<| (_.context (%.name (name-of /.Enum))) + ($_ _.and + (_.test (%.name (name-of /.range)) + (let [expected-size (|> end (n.- start) inc) + expected-start? (|> range list.head (maybe@map (n.= start)) (maybe.default false)) + expected-end? (|> range list.last (maybe@map (n.= end)) (maybe.default false)) + every-element-is-a-successor? (case range + (#.Cons head tail) + (|> (list@fold (function (_ next [verdict prev]) + [(and verdict + (n.= next (:: n.enum succ prev))) + next]) + [true head] + tail) + product.left) + + #.Nil + false)] + (and (n.= expected-size (list.size range)) + expected-start? + expected-end? + every-element-is-a-successor?))) + ))))) + (def: #export (spec (^open "/@.") gen-sample) (All [a] (-> (Enum a) (Random a) Test)) (do r.monad [sample gen-sample] - (<| (_.context (%.name (name-of /.Order))) + (<| (_.context (%.name (name-of /.Enum))) ($_ _.and (_.test "Successor and predecessor are inverse functions." (and (/@= (|> sample /@succ /@pred) - (function.identity sample)) + sample) (/@= (|> sample /@pred /@succ) - (function.identity sample)) - (not (/@= (|> sample /@succ) - (function.identity sample))) - (not (/@= (|> sample /@pred) - (function.identity sample))))) + sample) + (not (/@= (/@succ sample) + sample)) + (not (/@= (/@pred sample) + sample)))) )))) diff --git a/stdlib/source/test/lux/macro/poly/json.lux b/stdlib/source/test/lux/macro/poly/json.lux index 92a8ce00c..063a20518 100644 --- a/stdlib/source/test/lux/macro/poly/json.lux +++ b/stdlib/source/test/lux/macro/poly/json.lux @@ -113,5 +113,4 @@ (def: #export test Test (<| (_.context (%.name (name-of /._))) - (<| (_.seed 14562075782602945288) - ($codec.spec ..equivalence ..codec gen-record)))) + ($codec.spec ..equivalence ..codec gen-record))) |