From c489af8e1a4e1caf35dd7be616ef4a848a477317 Mon Sep 17 00:00:00 2001 From: Roy Frostig Date: Wed, 28 Jul 2010 17:31:41 -0700 Subject: [PATCH] Test the deque some more. --- src/test/run-pass/lib-deque.rs | 156 ++++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 2 deletions(-) diff --git a/src/test/run-pass/lib-deque.rs b/src/test/run-pass/lib-deque.rs index 003fb9a27b1..188b5ec5f9a 100644 --- a/src/test/run-pass/lib-deque.rs +++ b/src/test/run-pass/lib-deque.rs @@ -39,6 +39,158 @@ fn test_simple() { * segfault. */ } -fn main() { - test_simple(); +fn test_boxes(@int a, @int b, @int c, @int d) { + let deque.t[@int] deq = deque.create[@int](); + check (deq.size() == 0u); + deq.add_front(a); + deq.add_front(b); + deq.add_back(c); + check (deq.size() == 3u); + deq.add_back(d); + check (deq.size() == 4u); + + check (deq.peek_front() == b); + check (deq.peek_back() == d); + + check (deq.pop_front() == b); + check (deq.pop_back() == d); + check (deq.pop_back() == c); + check (deq.pop_back() == a); + + /* FIXME (issue #138): Test d.get() once it no longer causes + * segfault. */ +} + +type eqfn[T] = fn(&T a, &T b) -> bool; + +fn test_parameterized[T](eqfn[T] e, &T a, &T b, &T c, &T d) { + let deque.t[T] deq = deque.create[T](); + check (deq.size() == 0u); + deq.add_front(a); + deq.add_front(b); + deq.add_back(c); + check (deq.size() == 3u); + deq.add_back(d); + check (deq.size() == 4u); + + check (e(deq.peek_front(), b)); + check (e(deq.peek_back(), d)); + + check (e(deq.pop_front(), b)); + check (e(deq.pop_back(), d)); + check (e(deq.pop_back(), c)); + check (e(deq.pop_back(), a)); + + /* FIXME (issue #138): Test d.get() once it no longer causes + * segfault. */ +} + +type taggy = tag(one(int), two(int, int), three(int, int, int)); + +type taggypar[T] = tag(onepar(int), + twopar(int, int), + threepar(int, int, int)); + +fn main() { + fn inteq(&int a, &int b) -> bool { + ret a == b; + } + + fn intboxeq(&@int a, &@int b) -> bool { + ret a == b; + } + + fn taggyeq(&taggy a, &taggy b) -> bool { + alt (a) { + case (one(a1)) { + alt (b) { + case (one(b1)) { ret a1 == b1; } + case (_) { ret false; } + } + } + case (two(a1, a2)) { + alt (b) { + case (two(b1, b2)) { ret (a1 == b1 && a2 == b2); } + case (_) { ret false; } + } + } + case (three(a1, a2, a3)) { + alt (b) { + case (three(b1, b2, b3)) { ret (a1 == b1 && a2 == b2 && a3 == b3); } + case (_) { ret false; } + } + } + } + } + + fn taggypareq[T](&taggypar[T] a, &taggypar[T] b) -> bool { + alt (a) { + case (onepar[T](a1)) { + alt (b) { + case (onepar[T](b1)) { ret a1 == b1; } + case (_) { ret false; } + } + } + case (twopar[T](a1, a2)) { + alt (b) { + case (twopar[T](b1, b2)) { ret (a1 == b1 && a2 == b2); } + case (_) { ret false; } + } + } + case (threepar[T](a1, a2, a3)) { + alt (b) { + case (threepar[T](b1, b2, b3)) { + ret (a1 == b1 && a2 == b2 && a3 == b3); + } + case (_) { ret false; } + } + } + } + } + + + log "test simple"; + test_simple(); + + /* + * FIXME: Causes "Invalid read of size 4" under valgrind. + + log "test boxes"; + test_boxes(@5, @72, @64, @175); + + */ + + log "test parameterized: int"; + let eqfn[int] eq1 = bind inteq(_, _); + test_parameterized[int](eq1, 5, 72, 64, 175); + + /* + * FIXME: Appears to segfault after an upcall_grow_task + + log "test parameterized: @int"; + let eqfn[@int] eq2 = bind intboxeq(_, _); + test_parameterized[@int](eq2, @5, @72, @64, @175); + + */ + + + log "test parameterized: taggy"; + let eqfn[taggy] eq3 = bind taggyeq(_, _); + test_parameterized[taggy](eq3, + one(1), two(1, 2), three(1, 2, 3), two(17, 42)); + + /* + * FIXME: Segfault. + + log "test parameterized: taggypar[int]"; + let eqfn[taggypar[int]] eq4 = bind taggypareq[int](_, _); + test_parameterized[taggypar[int]](eq4, + onepar[int](1), + twopar[int](1, 2), + threepar[int](1, 2, 3), + twopar[int](17, 42)); + + */ + + log "done"; }