-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayList_TEST.cpp
More file actions
88 lines (77 loc) · 2.3 KB
/
Copy pathArrayList_TEST.cpp
File metadata and controls
88 lines (77 loc) · 2.3 KB
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
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "ArrayList.hpp"
TEST_CASE ("Testing ArrayList") {
SECTION ("Testing pushBack, popBack, and getBack") {
ArrayList<int>* a = new ArrayList<int>();
a->pushBack(5);
a->pushBack(4);
REQUIRE (a->getSize() == 2);
REQUIRE (a->getCapacity() == 10);
REQUIRE (a->isEmpty() == false);
REQUIRE (a->getBack() == 4);
a->popBack();
a->popBack();
REQUIRE (a->getSize() == 0);
REQUIRE (a->getCapacity() == 10);
REQUIRE (a->isEmpty() == true);
delete a;
}
SECTION ("Testing pushFront, popFront and getFront") {
ArrayList<int>* a = new ArrayList<int>(3);
a->pushFront(5);
a->pushFront(4);
a->pushFront(3);
a->pushFront(2);
a->pushFront(1);
a->pushFront(0);
REQUIRE (a->getSize() == 6);
REQUIRE (a->getCapacity() == 6);
REQUIRE (a->isEmpty() == false);
REQUIRE (a->getFront() == 0);
a->popFront();
REQUIRE (a->getSize() == 5);
REQUIRE (a->getCapacity() == 6);
REQUIRE (a->getFront() == 1);
a->popFront();
a->popFront();
a->popFront();
a->popFront();
a->popFront();
REQUIRE (a->isEmpty() == true);
delete a;
}
SECTION ("Testing getItem and setItem") {
ArrayList<int>* a = new ArrayList<int>();
a->setItem(8, 788);
a->setItem(0, 788);
a->setItem(0, 788);
a->setItem(1, 2);
a->setItem(2, 3);
REQUIRE (a->getItem(0) == 788);
REQUIRE (a->getItem(1) == 2);
REQUIRE (a->getItem(2) == 3);
a->setItem(0, 1);
REQUIRE (a->getItem(0) == 1);
delete a;
}
SECTION ("Testing insert and remove") {
ArrayList<int>* a = new ArrayList<int>();
a->insert(5, 1);
a->insert(0, 1);
a->insert(1, 2);
a->insert(2, 3);
a->insert(3, 4);
a->insert(4, 5);
a->insert(0, 788);
REQUIRE (a->getSize() == 6);
REQUIRE (a->getItem(0) == 788);
REQUIRE (a->getItem(1) == 1);
a->remove(3);
a->remove(9);
REQUIRE (a->getItem(3) == 4);
a->insert(3, 233);
REQUIRE (a->getItem(4) == 4);
delete a;
}
}