diff options
author | Eduardo Julian | 2017-10-16 18:13:12 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-10-16 18:13:12 -0400 |
commit | 9d0eaa97963d4e37a6afbe30f62c5bb9991ef49e (patch) | |
tree | 293a89b9f8f4ce78caf5ac9d1d57ae45a1ddcc5d /stdlib/test | |
parent | c3470e9d3eff01a5bbd180e449ac04f659c061f7 (diff) |
- Moved Array type to lux.lux.
- Re-named some array functions.
- Minor refactorings.
Diffstat (limited to 'stdlib/test')
-rw-r--r-- | stdlib/test/test/lux/data/coll/array.lux | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/stdlib/test/test/lux/data/coll/array.lux b/stdlib/test/test/lux/data/coll/array.lux index 81f8144d2..d5fde5a64 100644 --- a/stdlib/test/test/lux/data/coll/array.lux +++ b/stdlib/test/test/lux/data/coll/array.lux @@ -3,7 +3,7 @@ (lux (control [monad #+ do Monad] pipe) [io] - (data (coll ["&" array] + (data (coll ["@" array] [list]) [number] [maybe]) @@ -18,72 +18,72 @@ (context: "Arrays and their copies" [size bounded-size original (R;array size R;nat) - #let [clone (&;clone original) - copy (: (&;Array Nat) - (&;new size)) - manual-copy (: (&;Array Nat) - (&;new size))]] + #let [clone (@;clone original) + copy (: (Array Nat) + (@;new size)) + manual-copy (: (Array Nat) + (@;new size))]] ($_ seq (test "Size function must correctly return size of array." - (n.= size (&;size original))) + (n.= size (@;size original))) (test "Cloning an array should yield and identical array, but not the same one." - (and (:: (&;Eq<Array> number;Eq<Nat>) = original clone) + (and (:: (@;Eq<Array> number;Eq<Nat>) = original clone) (not (is original clone)))) (test "Full-range manual copies should give the same result as cloning." - (exec (&;copy size +0 original +0 copy) - (and (:: (&;Eq<Array> number;Eq<Nat>) = original copy) + (exec (@;copy size +0 original +0 copy) + (and (:: (@;Eq<Array> number;Eq<Nat>) = original copy) (not (is original copy))))) (test "Array folding should go over all values." - (exec (:: &;Fold<Array> fold + (exec (:: @;Fold<Array> fold (function [x idx] - (exec (&;put idx x manual-copy) + (exec (@;write idx x manual-copy) (n.inc idx))) +0 original) - (:: (&;Eq<Array> number;Eq<Nat>) = original manual-copy))) + (:: (@;Eq<Array> number;Eq<Nat>) = original manual-copy))) (test "Transformations between (full) arrays and lists shouldn't cause lose or change any values." (|> original - &;to-list &;from-list - (:: (&;Eq<Array> number;Eq<Nat>) = original))) + @;to-list @;from-list + (:: (@;Eq<Array> number;Eq<Nat>) = original))) )) (context: "Array mutation" [size bounded-size idx (:: @ map (n.% size) R;nat) array (|> (R;array size R;nat) - (R;filter (|>. &;to-list (list;any? n.odd?)))) - #let [value (maybe;assume (&;get idx array))]] + (R;filter (|>. @;to-list (list;any? n.odd?)))) + #let [value (maybe;assume (@;read idx array))]] ($_ seq (test "Shouldn't be able to find a value in an unoccupied cell." - (case (&;get idx (&;remove idx array)) + (case (@;read idx (@;delete idx array)) (#;Some _) false #;None true)) (test "You should be able to access values put into the array." - (case (&;get idx (&;put idx value array)) + (case (@;read idx (@;write idx value array)) (#;Some value') (n.= value' value) #;None false)) (test "All cells should be occupied on a full array." - (and (n.= size (&;occupied array)) - (n.= +0 (&;vacant array)))) + (and (n.= size (@;occupied array)) + (n.= +0 (@;vacant array)))) (test "Filtering mutates the array to remove invalid values." - (exec (&;filter n.even? array) - (and (n.< size (&;occupied array)) - (n.> +0 (&;vacant array)) - (n.= size (n.+ (&;occupied array) - (&;vacant array)))))) + (exec (@;filter n.even? array) + (and (n.< size (@;occupied array)) + (n.> +0 (@;vacant array)) + (n.= size (n.+ (@;occupied array) + (@;vacant array)))))) )) (context: "Finding values." [size bounded-size array (|> (R;array size R;nat) - (R;filter (|>. &;to-list (list;any? n.even?))))] + (R;filter (|>. @;to-list (list;any? n.even?))))] ($_ seq (test "Can find values inside arrays." - (|> (&;find n.even? array) + (|> (@;find n.even? array) (case> (#;Some _) true #;None false))) (test "Can find values inside arrays (with access to indices)." - (|> (&;find+ (function [idx n] + (|> (@;find+ (function [idx n] (and (n.even? n) (n.< size idx))) array) @@ -93,8 +93,8 @@ (context: "Functor" [size bounded-size array (R;array size R;nat)] - (let [(^open) &;Functor<Array> - (^open) (&;Eq<Array> number;Eq<Nat>)] + (let [(^open) @;Functor<Array> + (^open) (@;Eq<Array> number;Eq<Nat>)] ($_ seq (test "Functor shouldn't alter original array." (let [copy (map id array)] @@ -111,20 +111,20 @@ sizeR bounded-size left (R;array sizeL R;nat) right (R;array sizeR R;nat) - #let [(^open) &;Monoid<Array> - (^open) (&;Eq<Array> number;Eq<Nat>) + #let [(^open) @;Monoid<Array> + (^open) (@;Eq<Array> number;Eq<Nat>) fusion (compose left right)]] ($_ seq (test "Appending two arrays should produce a new one twice as large." - (n.= (n.+ sizeL sizeR) (&;size fusion))) + (n.= (n.+ sizeL sizeR) (@;size fusion))) (test "First elements of fused array should equal the first array." - (|> (: (&;Array Nat) - (&;new sizeL)) - (&;copy sizeL +0 fusion +0) + (|> (: (Array Nat) + (@;new sizeL)) + (@;copy sizeL +0 fusion +0) (= left))) (test "Last elements of fused array should equal the second array." - (|> (: (&;Array Nat) - (&;new sizeR)) - (&;copy sizeR sizeL fusion +0) + (|> (: (Array Nat) + (@;new sizeR)) + (@;copy sizeR sizeL fusion +0) (= right))) )) |