aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/collection/dictionary
diff options
context:
space:
mode:
authorEduardo Julian2020-12-02 20:37:13 -0400
committerEduardo Julian2020-12-02 20:37:13 -0400
commit28c724857d76afdc40b5b036f415cc151eb66263 (patch)
tree3e970ca2a10dd7bb5c7ddd405349762945464d39 /stdlib/source/test/lux/data/collection/dictionary
parent34e310622bdeb1d0588c0664c0e78cbaa84f837c (diff)
Replaced "contains?" function with "key?" function.
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/data/collection/dictionary.lux43
-rw-r--r--stdlib/source/test/lux/data/collection/dictionary/ordered.lux13
2 files changed, 36 insertions, 20 deletions
diff --git a/stdlib/source/test/lux/data/collection/dictionary.lux b/stdlib/source/test/lux/data/collection/dictionary.lux
index 718c9f0c9..b852f8dbf 100644
--- a/stdlib/source/test/lux/data/collection/dictionary.lux
+++ b/stdlib/source/test/lux/data/collection/dictionary.lux
@@ -2,6 +2,7 @@
[lux #*
["_" test (#+ Test)]
[abstract
+ [hash (#+ Hash)]
[monad (#+ do)]
["." equivalence]
{[0 #spec]
@@ -28,12 +29,14 @@
(def: for-dictionaries
Test
- (do random.monad
+ (do {! random.monad}
[#let [capped-nat (\ random.monad map (n.% 100) random.nat)]
size capped-nat
dict (random.dictionary n.hash size random.nat capped-nat)
- non-key (|> random.nat (random.filter (function (_ key) (not (/.contains? key dict)))))
- test-val (|> random.nat (random.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))]
+ non-key (random.filter (|>> (/.key? dict) not)
+ random.nat)
+ test-val (random.filter (|>> (list.member? n.equivalence (/.values dict)) not)
+ random.nat)]
($_ _.and
(_.cover [/.size]
(n.= size (/.size dict)))
@@ -47,6 +50,16 @@
(let [sample (/.new n.hash)]
(and (n.= 0 (/.size sample))
(/.empty? sample))))
+
+ (do !
+ [constant random.nat
+ #let [hash (: (Hash Nat)
+ (structure
+ (def: &equivalence n.equivalence)
+ (def: (hash _)
+ constant)))]]
+ (_.cover [/.key-hash]
+ (is? hash (/.key-hash (/.new hash)))))
(_.cover [/.entries /.keys /.values]
(\ (list.equivalence (equivalence.product n.equivalence n.equivalence)) =
@@ -82,11 +95,13 @@
[#let [capped-nat (\ random.monad map (n.% 100) random.nat)]
size capped-nat
dict (random.dictionary n.hash size random.nat capped-nat)
- non-key (|> random.nat (random.filter (function (_ key) (not (/.contains? key dict)))))
- test-val (|> random.nat (random.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))]
+ non-key (random.filter (|>> (/.key? dict) not)
+ random.nat)
+ test-val (random.filter (|>> (list.member? n.equivalence (/.values dict)) not)
+ random.nat)]
($_ _.and
- (_.cover [/.contains?]
- (list.every? (function (_ key) (/.contains? key dict))
+ (_.cover [/.key?]
+ (list.every? (/.key? dict)
(/.keys dict)))
(_.cover [/.get]
@@ -130,8 +145,8 @@
(_.cover [/.remove]
(and (let [base (/.put non-key test-val dict)]
- (and (/.contains? non-key base)
- (not (/.contains? non-key (/.remove non-key base)))))
+ (and (/.key? base non-key)
+ (not (/.key? (/.remove non-key base) non-key))))
(case (list.head (/.keys dict))
#.None
true
@@ -186,8 +201,8 @@
(let [first-key (|> dict /.keys list.head maybe.assume)
rebound (/.re-bind first-key non-key dict)]
(and (n.= (/.size dict) (/.size rebound))
- (/.contains? non-key rebound)
- (not (/.contains? first-key rebound))
+ (/.key? rebound non-key)
+ (not (/.key? rebound first-key))
(n.= (maybe.assume (/.get first-key dict))
(maybe.assume (/.get non-key rebound)))))))
)))
@@ -200,8 +215,10 @@
[#let [capped-nat (\ random.monad map (n.% 100) random.nat)]
size capped-nat
dict (random.dictionary n.hash size random.nat capped-nat)
- non-key (|> random.nat (random.filter (function (_ key) (not (/.contains? key dict)))))
- test-val (|> random.nat (random.filter (function (_ val) (not (list.member? n.equivalence (/.values dict) val)))))]
+ non-key (random.filter (|>> (/.key? dict) not)
+ random.nat)
+ test-val (random.filter (|>> (list.member? n.equivalence (/.values dict)) not)
+ random.nat)]
($_ _.and
(_.with-cover [/.equivalence]
($equivalence.spec (/.equivalence n.equivalence)
diff --git a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux
index c34f3e3cf..01920fa1c 100644
--- a/stdlib/source/test/lux/data/collection/dictionary/ordered.lux
+++ b/stdlib/source/test/lux/data/collection/dictionary/ordered.lux
@@ -32,8 +32,7 @@
_
(do random.monad
[partial (dictionary order gen-key gen-value (dec size))
- key (random.filter (function (_ candidate)
- (not (/.contains? candidate partial)))
+ key (random.filter (|>> (/.key? partial) not)
gen-key)
value gen-value]
(wrap (/.put key value partial)))))
@@ -103,14 +102,14 @@
(|> sample
/.entries (/.from-list n.order)
(/\= sample)))
- (_.cover [/.contains?]
- (and (list.every? (function (_ key) (/.contains? key sample))
+ (_.cover [/.key?]
+ (and (list.every? (/.key? sample)
(/.keys sample))
- (not (/.contains? extra-key sample))))
+ (not (/.key? sample extra-key))))
(_.cover [/.put]
- (and (not (/.contains? extra-key sample))
+ (and (not (/.key? sample extra-key))
(let [sample+ (/.put extra-key extra-value sample)]
- (and (/.contains? extra-key sample+)
+ (and (/.key? sample+ extra-key)
(n.= (inc (/.size sample))
(/.size sample+))))))
(_.cover [/.get]