1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
//continued
list.Clear();
list.PushFront(20);
list.PushFront(30);
list.PushFront(40);
list.PushFront(50);
list.PushBack(60);
list.PushBack(70);
list.PushBack(80);
list.PushBack(10);\
Test(list.GetSize() == 8,
"PushFront(20, 30, 40 ,50), PushBack(60, 70, 80, 10");
Test(list.ToStringForwards() == "50, 40, 30, 20, 60, 70, 80, 10",
"ToStringForwards()");
Test(list.ToStringBackwards() == "10, 80, 70, 60, 20, 30, 40, 50",
"ToStringBackwards()");
sserr.str("");
list.RemoveFirst(1);
Test(sserr.str() == no_value, "RemoveFirst(1)");
sserr.str("");
list.RemoveFirst(50);
Test(sserr.str() == "", "RemoveFirst(50)");
Test(list.GetSize() == 7, "GetSize()");
Test(list.ToStringForwards() == "40, 30, 20, 60, 70, 80, 10",
"ToStringForwards()");
Test(list.ToStringBackwards() == "10, 80, 70, 60, 20, 30, 40",
"ToStringBackwards()");
sserr.str("");
list.RemoveFirst(10);
Test(sserr.str() == "", "RemoveFirst(10)");
Test(list.GetSize() == 6, "GetSize()");
Test(list.ToStringForwards() == "40, 30, 20, 60, 70, 80",
"ToStringForwards()");
Test(list.ToStringBackwards() == "80, 70, 60, 20, 30, 40",
"ToStringBackwards()");
sserr.str("");
list.RemoveFirst(30);
Test(sserr.str() == "", "RemoveFirst(30)");
Test(list.GetSize() == 5, "GetSize()");
Test(list.ToStringForwards() == "40, 20, 60, 70, 80", "ToStringForwards()");
Test(list.ToStringBackwards() == "80, 70, 60, 20, 40", "ToStringBackwards()");
list.Clear();
list.PushFront(20);
list.PushFront(30);
list.PushFront(40);
list.PushFront(50);
list.PushBack(50);
list.PushBack(70);
list.PushBack(80);
list.PushBack(20);
Test(list.GetSize() == 8,
"PushFront(20, 30, 40 ,50), PushBack(50, 70, 80, 20");
Test(list.ToStringForwards() == "50, 40, 30, 20, 50, 70, 80, 20",
"ToStringForwards()");
Test(list.ToStringBackwards() == "20, 80, 70, 50, 20, 30, 40, 50",
"ToStringBackwards()");
list.RemoveAll(20);
Test(list.GetSize() == 6, "RemoveAll(20), GetSize()");
Test(list.ToStringForwards() == "50, 40, 30, 50, 70, 80",
"ToStringForwards()");
Test(list.ToStringBackwards() == "80, 70, 50, 30, 40, 50",
"ToStringBackwards()");
sserr.str("");
list.RemoveAll(15);
Test(sserr.str() == no_value, "RemoveAll(15)");
sserr.str("");
list.RemoveAll(80);
Test(list.GetSize() == 5, "RemoveAll(80), GetSize()");
Test(list.ToStringForwards() == "50, 40, 30, 50, 70", "ToStringForwards()");
Test(list.ToStringBackwards() == "70, 50, 30, 40, 50", "ToStringBackwards()");
list.RemoveAll(50);
Test(list.GetSize() == 3, "RemoveAll(50), GetSize()");
Test(list.ToStringForwards() == "40, 30, 70", "ToStringForwards()");
Test(list.ToStringBackwards() == "70, 30, 40", "ToStringBackwards()");
list.Clear();
for (unsigned int i = 0; i < 1000; i++)
list.PushFront(i);
Test(list.GetSize() == 1000, "PushFront() \"HIGH LOAD\" & GetSize()");
Test(list.ToStringForwards() == full_head_list.str(), "ToStringForwards()");
Test(list.ToStringBackwards() == full_tail_list.str(), "ToStringBackwards()");
Test(list.Exists(500) == true, "Exists(500)");
Test(list.Exists(-1) == false, "Exists(-1)");
for (unsigned int i = 0; i < 500; i++)
list.PopFront();
Test(list.GetSize() == 500, "PopFront() \"HIGH LOAD / 2\" & GetSize()");
Test(list.ToStringForwards() == half_head_list.str(), "ToStringForwards()");
Test(list.ToStringBackwards() == half_tail_list.str(), "ToStringBackwards()");
for (unsigned int i = 0; i < 600; i++)
list.PopFront();
Test(list.GetSize() == 0, "PopFront() \"HIGH LOAD / 2\" & GetSize()");
Test(list.ToStringForwards() == "", "ToStringForwards()");
Test(list.ToStringBackwards() == "", "ToStringBackwards()");
for (unsigned int i = 0; i < 1000; i++)
list.PushBack(i);
Test(list.GetSize() == 1000, "PushBack() \"HIGH LOAD\" & GetSize()");
Test(list.ToStringForwards() == full_tail_list.str(), "ToStringForwards()");
Test(list.ToStringBackwards() == full_head_list.str(), "ToStringBackwards()");
Test(list.Exists(500) == true, "Exists(500)");
Test(list.Exists(-1) == false, "Exists(-1)");
for (unsigned int i = 0; i < 500; i++)
list.PopBack();
Test(list.GetSize() == 500, "PopBack() \"HIGH LOAD / 2\" & GetSize()");
Test(list.ToStringForwards() == half_tail_list.str(), "ToStringForwards()");
Test(list.ToStringBackwards() == half_head_list.str(), "ToStringBackwards()");
for (unsigned int i = 0; i < 600; i++)
list.PopBack();
Test(list.GetSize() == 0, "PopBack() \"HIGH LOAD / 2\" & GetSize()");
Test(list.ToStringForwards() == "", "ToStringForwards()");
Test(list.ToStringBackwards() == "", "ToStringBackwards()");
// Restore cerr
std::cerr.rdbuf(old_cerr);
cout << string(temp.length() - 1, '-') << endl;
cout << "Unit Test Complete!\n" << "Passed: " << ut_passed << " / "
<< ut_total << endl << "Failed: " << ut_failed << " / " << ut_total
<< endl << endl;
}
// For testing (DO NOT ALTER)
void Test(bool test, string more_info) {
static int test_number = 1;
if (test) {
cout << "PASSSED TEST ";
ut_passed++;
} else {
cout << "FAILED TEST ";
ut_failed++;
}
cout << test_number << " " << more_info << "!" << endl;
test_number++;
ut_total++;
}
|