summaryrefslogtreecommitdiff
path: root/tests/testdeque.vala
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testdeque.vala')
-rw-r--r--tests/testdeque.vala196
1 files changed, 100 insertions, 96 deletions
diff --git a/tests/testdeque.vala b/tests/testdeque.vala
index d100ce0..ff2d320 100644
--- a/tests/testdeque.vala
+++ b/tests/testdeque.vala
@@ -37,28 +37,30 @@ public abstract class DequeTests : QueueTests {
// Check the test deque is not null
assert (test_deque != null);
+ string[] to_offer = {
+ "one", "two", "three", "four", "five", "six", "seven", "
+eight",
+ "nine", "ten", "eleven", "twelve", "thirteen", "fourteen
+",
+ "fifteen", "sixteen", "seventeen", "eighteen", "nineteen
+", "twenty",
+ "twenty one", "twenty two", "twenty three", "twenty four",
+ "twenty five", "twenty six", "twenty seven", "twenty eight",
+ "twenty nine", "thirty", "thirty one", "thirty two", "thirty four",
+ "thirty five", "thirty six", "thirty seven", "thirty eight",
+ "thirty nine", "fourty"
+ };
// Check normal FIFO behavior
- assert (test_deque.offer_tail ("one"));
- assert (test_deque.size == 1);
- assert (test_deque.offer_tail ("two"));
- assert (test_deque.size == 2);
- assert (test_deque.offer_tail ("three"));
- assert (test_deque.size == 3);
- assert (test_deque.offer_tail ("four"));
- assert (test_deque.size == 4);
- assert (test_deque.peek_head () == "one");
- assert (test_deque.poll_head () == "one");
- assert (test_deque.size == 3);
- assert (test_deque.peek_head () == "two");
- assert (test_deque.poll_head () == "two");
- assert (test_deque.size == 2);
- assert (test_deque.peek_head () == "three");
- assert (test_deque.poll_head () == "three");
- assert (test_deque.size == 1);
- assert (test_deque.peek_head () == "four");
- assert (test_deque.poll_head () == "four");
- assert (test_deque.size == 0);
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.offer_tail (to_offer[i]));
+ assert (test_deque.size == i + 1);
+ }
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.peek_head () == to_offer[i]);
+ assert (test_deque.poll_head () == to_offer[i]);
+ assert (test_deque.size == to_offer.length - i - 1);
+ }
// Check normal behavior when no element
assert (test_deque.peek_head () == null);
@@ -66,21 +68,20 @@ public abstract class DequeTests : QueueTests {
// Check drain with FIFO behavior
recipient.clear ();
- assert (test_deque.offer_tail ("one"));
- assert (test_deque.offer_tail ("two"));
- assert (test_deque.offer_tail ("three"));
- assert (test_deque.offer_tail ("four"));
- assert (test_deque.size == 4);
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.offer_tail (to_offer[i]));
+ }
+ assert (test_deque.size == to_offer.length);
assert (test_deque.drain_head (recipient, 1) == 1);
- assert (test_deque.size == 3);
+ assert (test_deque.size == to_offer.length - 1);
assert (recipient.size == 1);
- assert (recipient.get (0) == "one");
- assert (test_deque.drain_head (recipient) == 3);
+ assert (recipient.get (0) == to_offer[0]);
+ assert (test_deque.drain_head (recipient) == to_offer.length - 1);
assert (test_deque.size == 0);
- assert (recipient.size == 4);
- assert (recipient.get (1) == "two");
- assert (recipient.get (2) == "three");
- assert (recipient.get (3) == "four");
+ assert (recipient.size == to_offer.length);
+ for (int i = 1; i < to_offer.length; i++) {
+ assert (recipient.get (i) == to_offer[i]);
+ }
// Check drain one when no element
recipient.clear ();
@@ -98,31 +99,33 @@ public abstract class DequeTests : QueueTests {
public void test_stack_use () {
var test_deque = test_collection as Gee.Deque<string>;
ArrayList<string> recipient = new ArrayList<string> ();
+ string[] to_offer = {
+ "one", "two", "three", "four", "five", "six", "seven", "
+eight",
+ "nine", "ten", "eleven", "twelve", "thirteen", "fourteen
+",
+ "fifteen", "sixteen", "seventeen", "eighteen", "nineteen
+", "twenty",
+ "twenty one", "twenty two", "twenty three", "twenty four",
+ "twenty five", "twenty six", "twenty seven", "twenty eight",
+ "twenty nine", "thirty", "thirty one", "thirty two", "thirty four",
+ "thirty five", "thirty six", "thirty seven", "thirty eight",
+ "thirty nine", "fourty"
+ };
// Check the test deque is not null
assert (test_deque != null);
// Check normal LIFO behavior
- assert (test_deque.offer_head ("one"));
- assert (test_deque.size == 1);
- assert (test_deque.offer_head ("two"));
- assert (test_deque.size == 2);
- assert (test_deque.offer_head ("three"));
- assert (test_deque.size == 3);
- assert (test_deque.offer_head ("four"));
- assert (test_deque.size == 4);
- assert (test_deque.peek_head () == "four");
- assert (test_deque.poll_head () == "four");
- assert (test_deque.size == 3);
- assert (test_deque.peek_head () == "three");
- assert (test_deque.poll_head () == "three");
- assert (test_deque.size == 2);
- assert (test_deque.peek_head () == "two");
- assert (test_deque.poll_head () == "two");
- assert (test_deque.size == 1);
- assert (test_deque.peek_head () == "one");
- assert (test_deque.poll_head () == "one");
- assert (test_deque.size == 0);
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.offer_head (to_offer[i]));
+ assert (test_deque.size == i + 1);
+ }
+ for (int i = to_offer.length - 1; i >= 0; i--) {
+ assert (test_deque.peek_head () == to_offer[i]);
+ assert (test_deque.poll_head () == to_offer[i]);
+ assert (test_deque.size == i);
+ }
// Check normal behavior when no element
assert (test_deque.peek_head () == null);
@@ -130,21 +133,20 @@ public abstract class DequeTests : QueueTests {
// Check drain with LIFO behavior
recipient.clear ();
- assert (test_deque.offer_head ("one"));
- assert (test_deque.offer_head ("two"));
- assert (test_deque.offer_head ("three"));
- assert (test_deque.offer_head ("four"));
- assert (test_deque.size == 4);
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.offer_head (to_offer[i]));
+ }
+ assert (test_deque.size == to_offer.length);
assert (test_deque.drain_head (recipient, 1) == 1);
- assert (test_deque.size == 3);
+ assert (test_deque.size == to_offer.length - 1);
assert (recipient.size == 1);
- assert (recipient.get (0) == "four");
- assert (test_deque.drain_head (recipient) == 3);
+ assert (recipient.get (0) == to_offer[to_offer.length - 1]);
+ assert (test_deque.drain_head (recipient) == to_offer.length - 1);
assert (test_deque.size == 0);
- assert (recipient.size == 4);
- assert (recipient.get (1) == "three");
- assert (recipient.get (2) == "two");
- assert (recipient.get (3) == "one");
+ assert (recipient.size == to_offer.length);
+ for (int i = 1; i < to_offer.length; i++) {
+ assert (recipient.get (i) == to_offer[to_offer.length - i - 1]);
+ }
// Check drain one when no element
recipient.clear ();
@@ -162,31 +164,33 @@ public abstract class DequeTests : QueueTests {
public void test_reversed_stack_use () {
var test_deque = test_collection as Gee.Deque<string>;
ArrayList<string> recipient = new ArrayList<string> ();
+ string[] to_offer = {
+ "one", "two", "three", "four", "five", "six", "seven", "
+eight",
+ "nine", "ten", "eleven", "twelve", "thirteen", "fourteen
+",
+ "fifteen", "sixteen", "seventeen", "eighteen", "nineteen
+", "twenty",
+ "twenty one", "twenty two", "twenty three", "twenty four",
+ "twenty five", "twenty six", "twenty seven", "twenty eight",
+ "twenty nine", "thirty", "thirty one", "thirty two", "thirty four",
+ "thirty five", "thirty six", "thirty seven", "thirty eight",
+ "thirty nine", "fourty"
+ };
// Check the test deque is not null
assert (test_deque != null);
// Check normal LIFO behavior
- assert (test_deque.offer_tail ("one"));
- assert (test_deque.size == 1);
- assert (test_deque.offer_tail ("two"));
- assert (test_deque.size == 2);
- assert (test_deque.offer_tail ("three"));
- assert (test_deque.size == 3);
- assert (test_deque.offer_tail ("four"));
- assert (test_deque.size == 4);
- assert (test_deque.peek_tail () == "four");
- assert (test_deque.poll_tail () == "four");
- assert (test_deque.size == 3);
- assert (test_deque.peek_tail () == "three");
- assert (test_deque.poll_tail () == "three");
- assert (test_deque.size == 2);
- assert (test_deque.peek_tail () == "two");
- assert (test_deque.poll_tail () == "two");
- assert (test_deque.size == 1);
- assert (test_deque.peek_tail () == "one");
- assert (test_deque.poll_tail () == "one");
- assert (test_deque.size == 0);
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.offer_tail (to_offer[i]));
+ assert (test_deque.size == i + 1);
+ }
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.peek_tail () == to_offer[to_offer.length - i - 1]);
+ assert (test_deque.poll_tail () == to_offer[to_offer.length - i - 1]);
+ assert (test_deque.size == to_offer.length - i - 1);
+ }
// Check normal behavior when no element
assert (test_deque.peek_tail () == null);
@@ -194,21 +198,20 @@ public abstract class DequeTests : QueueTests {
// Check drain with LIFO behavior
recipient.clear ();
- assert (test_deque.offer_tail ("one"));
- assert (test_deque.offer_tail ("two"));
- assert (test_deque.offer_tail ("three"));
- assert (test_deque.offer_tail ("four"));
- assert (test_deque.size == 4);
+ for (int i = 0; i < to_offer.length; i++) {
+ assert (test_deque.offer_tail (to_offer[i]));
+ }
+ assert (test_deque.size == to_offer.length);
assert (test_deque.drain_tail (recipient, 1) == 1);
- assert (test_deque.size == 3);
+ assert (test_deque.size == to_offer.length - 1);
assert (recipient.size == 1);
- assert (recipient.get (0) == "four");
- assert (test_deque.drain_tail (recipient) == 3);
+ assert (recipient.get (0) == to_offer[to_offer.length - 1]);
+ assert (test_deque.drain_tail (recipient) == to_offer.length - 1);
assert (test_deque.size == 0);
- assert (recipient.size == 4);
- assert (recipient.get (1) == "three");
- assert (recipient.get (2) == "two");
- assert (recipient.get (3) == "one");
+ assert (recipient.size == to_offer.length);
+ for (int i = 1; i < to_offer.length; i++) {
+ assert (recipient.get (i) == to_offer[to_offer.length - i - 1]);
+ }
// Check drain one when no element
recipient.clear ();
@@ -223,3 +226,4 @@ public abstract class DequeTests : QueueTests {
assert (recipient.size == 0);
}
}
+