From 9d0eaa97963d4e37a6afbe30f62c5bb9991ef49e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 16 Oct 2017 18:13:12 -0400 Subject: - Moved Array type to lux.lux. - Re-named some array functions. - Minor refactorings. --- stdlib/test/test/lux/data/coll/array.lux | 80 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'stdlib/test') 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 number;Eq) = original clone) + (and (:: (@;Eq number;Eq) = 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 number;Eq) = original copy) + (exec (@;copy size +0 original +0 copy) + (and (:: (@;Eq number;Eq) = original copy) (not (is original copy))))) (test "Array folding should go over all values." - (exec (:: &;Fold fold + (exec (:: @;Fold fold (function [x idx] - (exec (&;put idx x manual-copy) + (exec (@;write idx x manual-copy) (n.inc idx))) +0 original) - (:: (&;Eq number;Eq) = original manual-copy))) + (:: (@;Eq number;Eq) = original manual-copy))) (test "Transformations between (full) arrays and lists shouldn't cause lose or change any values." (|> original - &;to-list &;from-list - (:: (&;Eq number;Eq) = original))) + @;to-list @;from-list + (:: (@;Eq number;Eq) = 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 - (^open) (&;Eq number;Eq)] + (let [(^open) @;Functor + (^open) (@;Eq number;Eq)] ($_ 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 - (^open) (&;Eq number;Eq) + #let [(^open) @;Monoid + (^open) (@;Eq number;Eq) 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))) )) -- cgit v1.2.3