diff options
author | Eduardo Julian | 2020-11-28 19:45:56 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-11-28 19:45:56 -0400 |
commit | a02b7bf8ff358ccfa35b03272d28537aeac723ae (patch) | |
tree | 66f27c97f192d31d7cbee6b87be5ac6546640253 /stdlib/source/test/lux/data/collection/array.lux | |
parent | 889139602b77e4387a6e8bfbedacc2a08703e976 (diff) |
Added "private" macro to lux/debug.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/data/collection/array.lux | 77 |
1 files changed, 49 insertions, 28 deletions
diff --git a/stdlib/source/test/lux/data/collection/array.lux b/stdlib/source/test/lux/data/collection/array.lux index 7a5e686ac..5a94f13b7 100644 --- a/stdlib/source/test/lux/data/collection/array.lux +++ b/stdlib/source/test/lux/data/collection/array.lux @@ -12,6 +12,8 @@ [data ["." bit] ["." maybe] + ["." text ("#\." equivalence) + ["%" format (#+ format)]] [number ["n" nat]] [collection @@ -46,6 +48,45 @@ ($fold.spec ..injection /.equivalence /.fold)) ))) +(def: search + Test + (do {! random.monad} + [size ..bounded-size + base random.nat + shift random.nat + #let [expected (n.+ base shift)] + the-array (random.array size random.nat)] + ($_ _.and + (_.cover [/.find] + (:: (maybe.equivalence n.equivalence) = + (/.find n.even? the-array) + (list.find n.even? (/.to-list the-array)))) + (_.cover [/.find+] + (case [(/.find n.even? the-array) + (/.find+ (function (_ idx member) + (n.even? member)) + the-array)] + [(#.Some expected) (#.Some [idx actual])] + (case (/.read idx the-array) + (#.Some again) + (and (n.= expected actual) + (n.= actual again)) + + #.None + false) + + [#.None #.None] + true)) + (_.cover [/.every?] + (:: bit.equivalence = + (list.every? n.even? (/.to-list the-array)) + (/.every? n.even? the-array))) + (_.cover [/.any?] + (:: bit.equivalence = + (list.any? n.even? (/.to-list the-array)) + (/.any? n.even? the-array))) + ))) + (def: #export test Test (<| (_.covering /._) @@ -59,10 +100,18 @@ the-array (random.array size random.nat)] ($_ _.and ..structures + ..search (_.cover [/.new /.size] (n.= size (/.size (: (Array Nat) (/.new size))))) + (_.cover [/.type-name] + (case (:of (/.new size)) + (^ (#.UnivQ _ (#.Apply _ (#.Named _ (#.UnivQ _ (#.Primitive nominal-type (list (#.Parameter 1)))))))) + (text\= /.type-name nominal-type) + + _ + false)) (_.cover [/.read /.write!] (let [the-array (|> (/.new 2) (: (Array Nat)) @@ -171,32 +220,4 @@ (or (n.even? value) (is? default value))) (/.to-list' default the-array))))) - (_.cover [/.find] - (:: (maybe.equivalence n.equivalence) = - (/.find n.even? the-array) - (list.find n.even? (/.to-list the-array)))) - (_.cover [/.find+] - (case [(/.find n.even? the-array) - (/.find+ (function (_ idx member) - (n.even? member)) - the-array)] - [(#.Some expected) (#.Some [idx actual])] - (case (/.read idx the-array) - (#.Some again) - (and (n.= expected actual) - (n.= actual again)) - - #.None - false) - - [#.None #.None] - true)) - (_.cover [/.every?] - (:: bit.equivalence = - (list.every? n.even? (/.to-list the-array)) - (/.every? n.even? the-array))) - (_.cover [/.any?] - (:: bit.equivalence = - (list.any? n.even? (/.to-list the-array)) - (/.any? n.even? the-array))) )))) |