static void TestDequeueFifo(int size) { Console.Write("Testing double ended queue as two FIFOs:\n\n"); DEQueue bQ = new DEQueue(size); Console.Write("Before testing array should be empty and it " + (bQ.IsEmpty() ? "is" : "is not") + "\n\n"); Console.Write("first add left, get right\n"); bQ.AddLeft(1); bQ.AddLeft(2); bQ.AddLeft(3); Console.Write(" first, sb 1 = " + bQ.GetRight() + " "); Console.Write(" next, sb 2 = " + bQ.GetRight() + " "); Console.Write(" last, sb 3 = " + bQ.GetRight() + "\n\n"); Console.Write("\nnow add right, get left\n"); bQ.AddRight(6); bQ.AddRight(7); bQ.AddRight(8); Console.Write(" first, sb 6 = " + bQ.GetLeft() + " "); Console.Write(" next, sb 7 = " + bQ.GetLeft() + " "); Console.Write(" last, sb 8 = " + bQ.GetLeft() + "\n"); Console.Write("\nAfter testing array should be empty and it " + (bQ.IsEmpty() ? "is" : "is not") + "\n\n"); }
static void TestListDequeue() { DEQueue cQ = new DEQueue(); Console.Write("\nNow testing list function:\n\n"); cQ.AddLeft(33); cQ.AddRight(43); cQ.AddLeft(34); cQ.AddRight(47);; Console.Write("listing left to right:\n should be 34 33 43 47 \n"); Console.Write(" actually is " + cQ.ListLeftRight()); Console.Write("\nEnd of testing list functions\n\n"); }
static void TestDequeueWrap(int size) { DEQueue dq = new DEQueue(size); Console.Write("Testing wrap from left to right: + \n\n"); Console.Write("Adding 10 even ints to left, removing four from right\n"); for (int i = 0; i < 10; i++) { dq.AddLeft(2 * i); } Console.Write(" should be: 0 2 4 6 \n"); Console.Write(" they are:"); for (int i = 0; i < 4; i++) { Console.Write(dq.GetRight().ToString().PadLeft(3)); } Console.Write("\n\n"); Console.Write("Adding 3 more to left \n"); for (int i = 10; i < 13; i++) { dq.AddLeft(2 * i); } Console.Write("Now removing all from the right \n should be: 8 10 12 14 16 18 20 22 24\n"); Console.Write(" they are:"); while (!dq.IsEmpty()) { Console.Write(dq.GetRight().ToString().PadLeft(3)); } Console.Write("\n\n"); Console.Write("Now repeating test from right to left with odd numbers\n"); for (int i = 0; i < 10; i++) { dq.AddRight(2 * i + 1); } Console.Write(" should be: 1 3 5 7 \n"); Console.Write(" they are:"); for (int i = 0; i < 4; i++) { Console.Write(dq.GetLeft().ToString().PadLeft(3)); } Console.Write("\n\n"); Console.Write("Adding 3 more to right \n"); for (int i = 10; i < 13; i++) { dq.AddRight(2 * i + 1); } Console.Write("Now removing all from the left \n should be: 9 11 13 15 17 19 21 23 25 \n"); Console.Write(" they are:"); while (!dq.IsEmpty()) { Console.Write(dq.GetLeft().ToString().PadLeft(3)); } Console.Write("\n"); Console.Write("\nDone with testing wrap on dequeue.\n\n"); }
static void TestDequeueGrow(int size) { Console.Write("Now testing adding to a full array\n\n"); DEQueue fq = new DEQueue(size); Console.Write("Testing overflow when adding to the left\n"); Console.Write("Adding first ten odd integers to left side of Dequeue \n"); for (int i = 0; i < 10; i++) { fq.AddLeft(2 * i + 1); } Console.Write(" and removing three of them" + "\n should be: 1 3 5 \n"); Console.Write(" they are:"); for (int i = 0; i < 3; i++) { Console.Write(fq.GetRight().ToString().PadLeft(3)); } Console.Write("\n"); Console.Write("\nNow adding five more, should cause wrap with growth\n"); for (int i = 10; i < 15; i++) { fq.AddLeft(2 * i + 1); } Console.Write("when we remove the remaining values,\n should be: 7 9 11 13 15 17 19 21 23 25 27 29 \n"); Console.Write(" they are:"); while (!fq.IsEmpty()) { Console.Write(fq.GetRight().ToString().PadLeft(3)); } Console.Write("\n\n"); DEQueue gq = new DEQueue(size); Console.Write("Now testing overflow when adding to the right\n\n"); Console.Write("Adding first ten even integers to right side of Dequeue \n"); for (int i = 0; i < 10; i++) { gq.AddRight(2 * i); } Console.Write("First removing three of them" + "\n should be: 0 2 4 \n"); Console.Write(" they are:"); for (int i = 0; i < 3; i++) { Console.Write(gq.GetLeft().ToString().PadLeft(3)); } Console.Write("\n"); Console.Write("\nNow adding five more, should cause wrap with growth\n"); for (int i = 10; i < 15; i++) { gq.AddRight(2 * i); } Console.Write("when we remove the remaining values" + "\n should be: 6 8 10 12 14 16 18 20 22 24 26 28 \n"); Console.Write(" they are: "); while (!gq.IsEmpty()) { Console.Write(gq.GetLeft().ToString().PadLeft(3)); } Console.Write("\n\n"); Console.Write("\nDone testing adding to full dequeue\n\n"); }