-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_linked_list.cpp
86 lines (61 loc) · 2 KB
/
test_linked_list.cpp
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
#include <iostream>
#include "LinkedList.h"
using namespace std;
typedef LinkedListNode<int> IntNode;
typedef LinkedList<int> IntList;
void printHeader() {
cout << endl << "#####################################" << endl;
}
int main(int /*argc*/, char** /*argv*/) {
cout << endl << "Beginning LinkedList Test." << endl;
IntList linkedList;
// Print initial list
printHeader();
cout << endl << "Initial List..." << endl;
linkedList.print();
// Test insertions
printHeader();
cout << endl << "Testing Insertions..." << endl;
cout << endl << "Expected: 3";
cout << endl << "Actual: ";
linkedList.insertBeginning(3);
linkedList.print();
cout << endl << "Expected: 0 -> 3";
cout << endl << "Actual: ";
IntNode* zeroIntNode = linkedList.insertBeginning(0);
linkedList.print();
cout << endl << "Expected: 0 -> 1 -> 3";
cout << endl << "Actual: ";
IntNode* oneIntNode = linkedList.insertAfter(zeroIntNode, 1);
linkedList.print();
cout << endl << "Expected: 0 -> 1 -> 2 -> 3";
cout << endl << "Actual: ";
linkedList.insertAfter(oneIntNode, 2);
linkedList.print();
// Test deletions
printHeader();
cout << endl << "Testing Deletions..." << endl;
cout << endl << "Expected: 0 -> 1 -> 3";
cout << endl << "Actual: ";
linkedList.removeAfter(oneIntNode);
linkedList.print();
cout << endl << "Expected: 0 -> 1";
cout << endl << "Actual: ";
linkedList.removeAfter(oneIntNode);
linkedList.print();
cout << endl << "Expected: 1";
cout << endl << "Actual: ";
linkedList.removeBeginning();
linkedList.print();
cout << endl << "Expected: NULL";
cout << endl << "Actual: ";
linkedList.removeAfter(0);
linkedList.print();
cout << endl << "Expected: NULL";
cout << endl << "Actual: ";
linkedList.removeBeginning();
linkedList.print();
printHeader();
cout << endl << "Done With LinkedList Test." << endl;
return EXIT_SUCCESS;
}