diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/data/collection/dictionary.lux | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/stdlib/source/test/lux/data/collection/dictionary.lux b/stdlib/source/test/lux/data/collection/dictionary.lux index 4512c0bec..432909629 100644 --- a/stdlib/source/test/lux/data/collection/dictionary.lux +++ b/stdlib/source/test/lux/data/collection/dictionary.lux @@ -12,7 +12,7 @@ [data ["." maybe] [number - ["." nat]] + ["n" nat]] [collection ["." list ("#@." functor)]]] [math @@ -22,30 +22,30 @@ (def: injection (Injection (/.Dictionary Nat)) - (|>> [0] list (/.from-list nat.hash))) + (|>> [0] list (/.from-list n.hash))) (def: #export test Test (<| (_.context (%.name (name-of /.Dictionary))) (do r.monad - [#let [capped-nat (:: r.monad map (n/% 100) r.nat)] + [#let [capped-nat (:: r.monad map (n.% 100) r.nat)] size capped-nat - dict (r.dictionary nat.hash size r.nat capped-nat) + dict (r.dictionary n.hash size r.nat capped-nat) non-key (|> r.nat (r.filter (function (_ key) (not (/.contains? key dict))))) - test-val (|> r.nat (r.filter (function (_ val) (not (list.member? nat.equivalence (/.values dict) val)))))] + test-val (|> r.nat (r.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))] ($_ _.and - ($equivalence.spec (/.equivalence nat.equivalence) - (r.dictionary nat.hash size r.nat r.nat)) + ($equivalence.spec (/.equivalence n.equivalence) + (r.dictionary n.hash size r.nat r.nat)) ($functor.spec ..injection /.equivalence /.functor) (_.test "Size function should correctly represent Dictionary size." - (n/= size (/.size dict))) + (n.= size (/.size dict))) (_.test "Dictionaries of size 0 should be considered empty." - (if (n/= 0 size) + (if (n.= 0 size) (/.empty? dict) (not (/.empty? dict)))) (_.test "The functions 'entries', 'keys' and 'values' should be synchronized." - (:: (list.equivalence (eq.product nat.equivalence nat.equivalence)) = + (:: (list.equivalence (eq.product n.equivalence n.equivalence)) = (/.entries dict) (list.zip2 (/.keys dict) (/.values dict)))) @@ -63,18 +63,18 @@ _ #1)) (_.test "Should be able to put and then get a value." (case (/.get non-key (/.put non-key test-val dict)) - (#.Some v) (n/= test-val v) + (#.Some v) (n.= test-val v) _ #1)) (_.test "Should be able to try-put and then get a value." (case (/.get non-key (/.try-put non-key test-val dict)) - (#.Some v) (n/= test-val v) + (#.Some v) (n.= test-val v) _ #1)) (_.test "Shouldn't be able to try-put an existing key." - (or (n/= 0 size) + (or (n.= 0 size) (let [first-key (|> dict /.keys list.head maybe.assume)] (case (/.get first-key (/.try-put first-key test-val dict)) - (#.Some v) (not (n/= test-val v)) + (#.Some v) (not (n.= test-val v)) _ #1)))) (_.test "Removing a key should make it's value inaccessible." (let [base (/.put non-key test-val dict)] @@ -85,45 +85,45 @@ updt (/.update non-key inc base)] (case [(/.get non-key base) (/.get non-key updt)] [(#.Some x) (#.Some y)] - (n/= (inc x) y) + (n.= (inc x) y) _ #0))) (_.test "Additions and removals to a Dictionary should affect its size." (let [plus (/.put non-key test-val dict) base (/.remove non-key plus)] - (and (n/= (inc (/.size dict)) (/.size plus)) - (n/= (dec (/.size plus)) (/.size base))))) + (and (n.= (inc (/.size dict)) (/.size plus)) + (n.= (dec (/.size plus)) (/.size base))))) (_.test "A Dictionary should equal itself & going to<->from lists shouldn't change that." - (let [(^open ".") (/.equivalence nat.equivalence)] + (let [(^open ".") (/.equivalence n.equivalence)] (and (= dict dict) - (|> dict /.entries (/.from-list nat.hash) (= dict))))) + (|> dict /.entries (/.from-list n.hash) (= dict))))) (_.test "Merging a Dictionary to itself changes nothing." - (let [(^open ".") (/.equivalence nat.equivalence)] + (let [(^open ".") (/.equivalence n.equivalence)] (= dict (/.merge dict dict)))) (_.test "If you merge, and the second dict has overlapping keys, it should overwrite yours." (let [dict' (|> dict /.entries (list@map (function (_ [k v]) [k (inc v)])) - (/.from-list nat.hash)) - (^open ".") (/.equivalence nat.equivalence)] + (/.from-list n.hash)) + (^open ".") (/.equivalence n.equivalence)] (= dict' (/.merge dict' dict)))) (_.test "Can merge values in such a way that they become combined." - (list.every? (function (_ [x x*2]) (n/= (n/* 2 x) x*2)) + (list.every? (function (_ [x x*2]) (n.= (n.* 2 x) x*2)) (list.zip2 (/.values dict) - (/.values (/.merge-with n/+ dict dict))))) + (/.values (/.merge-with n.+ dict dict))))) (_.test "Should be able to select subset of keys from dict." (|> dict (/.put non-key test-val) (/.select (list non-key)) /.size - (n/= 1))) + (n.= 1))) (_.test "Should be able to re-bind existing values to different keys." - (or (n/= 0 size) + (or (n.= 0 size) (let [first-key (|> dict /.keys list.head maybe.assume) rebound (/.re-bind first-key non-key dict)] - (and (n/= (/.size dict) (/.size rebound)) + (and (n.= (/.size dict) (/.size rebound)) (/.contains? non-key rebound) (not (/.contains? first-key rebound)) - (n/= (maybe.assume (/.get first-key dict)) + (n.= (maybe.assume (/.get first-key dict)) (maybe.assume (/.get non-key rebound))))))) )))) |