diff options
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux/data/binary.lux | 27 | ||||
-rw-r--r-- | stdlib/source/test/lux/world/file.lux | 4 |
2 files changed, 17 insertions, 14 deletions
diff --git a/stdlib/source/test/lux/data/binary.lux b/stdlib/source/test/lux/data/binary.lux index 89237babc..11d4a8889 100644 --- a/stdlib/source/test/lux/data/binary.lux +++ b/stdlib/source/test/lux/data/binary.lux @@ -84,8 +84,8 @@ sample (..random size) value random.nat #let [gen_idx (|> random.nat (\ ! map (n.% size)))] - [from to] (random.and gen_idx gen_idx) - #let [[from to] [(n.min from to) (n.max from to)]]] + offset gen_idx + length (\ ! map (n.% (n.- offset size)) random.nat)] (_.for [/.Binary] ($_ _.and (_.for [/.equivalence] @@ -113,12 +113,15 @@ (_.cover [/.read/64 /.write/64] (..binary_io 3 /.read/64 /.write/64 value)))) (_.cover [/.slice] - (let [slice_size (|> to (n.- from) inc) - random_slice (try.assume (/.slice from to sample)) - idxs (enum.range n.enum 0 (dec slice_size)) - reader (function (_ binary idx) (/.read/8 idx binary))] - (and (n.= slice_size (/.size random_slice)) - (case [(monad.map try.monad (|>> (n.+ from) (reader sample)) idxs) + (let [random_slice (try.assume (/.slice offset length sample)) + idxs (: (List Nat) + (case length + 0 (list) + _ (enum.range n.enum 0 (dec length)))) + reader (function (_ binary idx) + (/.read/8 idx binary))] + (and (n.= length (/.size random_slice)) + (case [(monad.map try.monad (|>> (n.+ offset) (reader sample)) idxs) (monad.map try.monad (reader random_slice) idxs)] [(#try.Success binary_vals) (#try.Success slice_vals)] (\ (list.equivalence n.equivalence) = binary_vals slice_vals) @@ -127,10 +130,10 @@ #0)))) (_.cover [/.slice_out_of_bounds] (and (throws? /.slice_out_of_bounds (/.slice size size sample)) - (throws? /.slice_out_of_bounds (/.slice from size sample)))) - (_.cover [/.inverted_slice] - (or (throws? /.inverted_slice (/.slice to from sample)) - (n.= to from))) + (let [verdict (throws? /.slice_out_of_bounds (/.slice offset size sample))] + (case offset + 0 (not verdict) + _ verdict)))) (_.cover [/.drop] (and (\ /.equivalence = sample (/.drop 0 sample)) (\ /.equivalence = (/.create 0) (/.drop size sample)) diff --git a/stdlib/source/test/lux/world/file.lux b/stdlib/source/test/lux/world/file.lux index 002d76c42..c7f546a1b 100644 --- a/stdlib/source/test/lux/world/file.lux +++ b/stdlib/source/test/lux/world/file.lux @@ -110,10 +110,10 @@ ## (wrap (and (n.= (n.* 2 file_size) read_size) ## (\ binary.equivalence = ## dataL - ## (try.assume (binary.slice 0 (dec file_size) content))) + ## (try.assume (binary.slice 0 file_size content))) ## (\ binary.equivalence = ## dataR - ## (try.assume (binary.slice file_size (dec read_size) content)))))))] + ## (try.assume (binary.slice file_size (n.- file_size read_size) content)))))))] ## (_.assert "Can append to files." ## (try.default #0 result)))) ## (wrap (do promise.monad |