diff options
author | Eduardo Julian | 2017-04-03 20:34:38 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-04-03 20:34:38 -0400 |
commit | 95100b81d87e55668b242ef40aac623f52523e03 (patch) | |
tree | d32457ef7d46e63ba023115c1e7ccb2367200977 /stdlib/test | |
parent | 367c56f33d72621120bcf00953f5fafffb028e97 (diff) |
- Persistent queues and sequences can now be empty.
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test/lux/data/coll/priority-queue.lux | 42 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/coll/seq.lux | 15 |
2 files changed, 26 insertions, 31 deletions
diff --git a/stdlib/test/test/lux/data/coll/priority-queue.lux b/stdlib/test/test/lux/data/coll/priority-queue.lux index 5c53edfb1..de885f1ee 100644 --- a/stdlib/test/test/lux/data/coll/priority-queue.lux +++ b/stdlib/test/test/lux/data/coll/priority-queue.lux @@ -12,30 +12,18 @@ (-> Nat (R;Random (&;Queue Nat))) (do R;Monad<Random> [inputs (R;list size R;nat)] - (case inputs - (#;Cons head tail) - (loop [head head - tail tail] - (do @ - [priority R;nat] - (case tail - (#;Cons head' tail') - (do @ - [=tail (recur head' tail')] - (wrap (&;push priority head =tail))) - - _ - (wrap (&;new priority head))))) - - _ - (undefined)))) + (foldM @ (lambda [head tail] + (do @ + [priority R;nat] + (wrap (&;push priority head tail)))) + &;empty + inputs))) (test: "Queues" - [size (|> R;nat - (:: @ map (|>. (n.% +100) (n.max +1)))) + [size (|> R;nat (:: @ map (n.% +100))) sample (gen-queue size) non-member-priority R;nat - non-member R;nat] + non-member (|> R;nat (R;filter (|>. (&;member? number;Eq<Nat> sample) not)))] ($_ seq (assert "I can query the size of a queue (and empty queues have size 0)." (n.= size (&;size sample))) @@ -43,14 +31,20 @@ (assert "Enqueueing and dequeing affects the size of queues." (and (n.= (n.inc size) (&;size (&;push non-member-priority non-member sample))) - (or (n.= +1 (&;size sample)) + (or (n.= +0 (&;size sample)) (n.= (n.dec size) (&;size (&;pop sample)))))) (assert "I can query whether an element belongs to a queue." (and (and (not (&;member? number;Eq<Nat> sample non-member)) - (&;member? number;Eq<Nat> (&;push non-member-priority non-member sample) + (&;member? number;Eq<Nat> + (&;push non-member-priority non-member sample) non-member)) - (and (&;member? number;Eq<Nat> sample (&;peek sample)) - (not (&;member? number;Eq<Nat> (&;pop sample) (&;peek sample)))))) + (or (n.= +0 (&;size sample)) + (and (&;member? number;Eq<Nat> + sample + (default (undefined) (&;peek sample))) + (not (&;member? number;Eq<Nat> + (&;pop sample) + (default (undefined) (&;peek sample)))))))) )) diff --git a/stdlib/test/test/lux/data/coll/seq.lux b/stdlib/test/test/lux/data/coll/seq.lux index e62f36854..5fe3a5af1 100644 --- a/stdlib/test/test/lux/data/coll/seq.lux +++ b/stdlib/test/test/lux/data/coll/seq.lux @@ -8,7 +8,8 @@ [text "Text/" Monoid<Text>] [number] [bool] - [product]) + [product] + maybe) ["R" math/random] pipe) lux/test) @@ -22,13 +23,13 @@ [size bounded-size idx (:: @ map (n.% size) R;nat) sample (|> (R;list size R;nat) - (:: @ map (|>. &;from-list (default (undefined))))) + (:: @ map &;from-list)) extra R;nat #let [(^open "&/") (&;Eq<Seq> number;Eq<Nat>)]] ($_ seq (assert "Can convert to/from list." (|> sample - &;to-list &;from-list (default (undefined)) + &;to-list &;from-list (&/= sample))) (assert "The size function should correctly portray the size of the seq." @@ -75,7 +76,7 @@ (test: "Seqs: Part 2" [size bounded-size sample (|> (R;list size R;nat) - (:: @ map (|>. &;from-list (default (undefined))))) + (:: @ map &;from-list)) #let [(^open "&/") (&;Eq<Seq> number;Eq<Nat>) (^open "&/") &;Functor<Seq>]] ($_ seq @@ -98,10 +99,10 @@ [size bounded-size idx (:: @ map (n.% size) R;nat) sample (|> (R;list size R;nat) - (:: @ map (|>. &;from-list (default (undefined))))) + (:: @ map &;from-list)) other-size bounded-size other-sample (|> (R;list other-size R;nat) - (:: @ map (|>. &;from-list (default (undefined))))) + (:: @ map &;from-list)) elem R;nat #let [(^open "&/") (&;Eq<Seq> number;Eq<Nat>) (^open "&/") &;Monad<Seq>]] @@ -112,7 +113,7 @@ (&/apply (&/wrap n.inc) sample)))) (assert "Seq concatenation is a monad." - (&/= (F;branch sample other-sample) + (&/= (&;concat sample other-sample) (&/join (&;seq sample other-sample)))) (assert "You can find any value that satisfies some criterium, if such values exist in the seq." |