-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_tests_LinkedList.hpp
94 lines (72 loc) · 1.89 KB
/
unit_tests_LinkedList.hpp
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
#include <cassert>
#include "LinkedList.hpp"
class unit_tests_LinkedList
{
private:
static void test_Get()
{
int* a = new int[5];
for(int i = 0; i < 5; i++) a[i] = i;
LinkedList<int>* ll = new LinkedList<int>(a, 5);
assert(ll->GetFirst() == 0);
assert(ll->GetLast() == 4);
assert(ll->Get(3) == 3);
assert(ll->GetSize() == 5);
delete [] a;
delete ll;
}
static void test_Set()
{
int* a = new int[5];
for(int i = 0; i < 5; i++) a[i] = i;
LinkedList<int>* ll = new LinkedList<int>(a, 5);
ll->InsertAt(3, 77);
assert(ll->Get(3) == 77);
assert(ll->Get(4) == 3);
assert(ll->GetSize() == 6);
ll->Append(7);
assert(ll->GetLast() == 7);
ll->Prepend(11);
assert(ll->GetFirst() == 11);
delete [] a;
delete ll;
}
static void test_GetSubList()
{
int* a = new int[6];
for(int i = 0; i < 6; i++) a[i] = i;
LinkedList<int>* ll = new LinkedList<int>(a, 6);
LinkedList<int>* sub = ll->GetSubList(1, 5);
for (int i = 0; i < 3; i++) assert(sub->Get(i) == i + 1);
delete [] a;
delete ll;
delete sub;
}
static void test_Remove()
{
int* a = new int[6];
for(int i = 0; i < 6; i++) a[i] = i;
LinkedList<int>* ll = new LinkedList<int>(a, 6);
ll->Remove(0);
assert(ll->GetFirst() == 1);
assert(ll->GetSize() == 5);
ll->Remove(4);
assert(ll->GetLast() == 4);
ll->Remove(2);
assert(ll->Get(1) == 2);
assert(ll->Get(2) == 4);
for (int i = 0; i < 3; i++) ll->Remove(0);
assert(ll->GetSize() == 0);
delete [] a;
delete ll;
}
public:
static void Run()
{
test_Get();
test_Set();
test_GetSubList();
test_Remove();
std::cout << "LinkedList tests finished successfully. \n";
}
};