aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2017-04-03 20:36:25 -0400
committerEduardo Julian2017-04-03 20:36:25 -0400
commitddacd6a4db08a5546222f2b2c49499c16e7ae536 (patch)
treed6a12a2b90c626ae944f42af4922f5b5b402ddc8 /stdlib/test
parent367c56f33d72621120bcf00953f5fafffb028e97 (diff)
- Priority-queues and sequences can now be empty.
Diffstat (limited to 'stdlib/test')
-rw-r--r--stdlib/test/test/lux/data/coll/priority-queue.lux42
-rw-r--r--stdlib/test/test/lux/data/coll/seq.lux15
-rw-r--r--stdlib/test/tests.lux2
3 files changed, 27 insertions, 32 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."
diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux
index ca0079092..c773b3f17 100644
--- a/stdlib/test/tests.lux
+++ b/stdlib/test/tests.lux
@@ -46,7 +46,7 @@
[set]
[ordered]
[stack]
- [vector]
+ ## [vector]
(tree [rose]
[zipper])
["_;" seq]