-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTests.cpp
More file actions
126 lines (125 loc) · 3.34 KB
/
Copy pathUnitTests.cpp
File metadata and controls
126 lines (125 loc) · 3.34 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
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
#include<iostream>
#include <cassert>
#include "primes.h"
class UnitTest {
public:
static void startAllTests();
static void defaultConstructorTEST();
static void maxConstructorTEST();
static void quantityConstructorTEST();
static void copyConstructorTEST();
static void moveConstructorTEST();
static void beginTEST();
static void endTEST();
static void sizeTEST();
static void copyOperatorTEST();
static void moveOperatorTEST();
static void indexOperatorTEST();
};
void UnitTest::startAllTests()
{
defaultConstructorTEST();
maxConstructorTEST();
quantityConstructorTEST();
copyConstructorTEST();
moveConstructorTEST();
beginTEST();
endTEST();
sizeTEST();
copyOperatorTEST();
moveOperatorTEST();
indexOperatorTEST();
std::cout << "All test successfully passed!" << std::endl;
}
void UnitTest::defaultConstructorTEST()
{
Primes pr;
assert(25 == pr.length);
assert(pr.typeFlag == true);
assert(pr.containerData!=nullptr);
}
void UnitTest::maxConstructorTEST()
{
Primes pr(300);
Primes pr1(0);
assert(pr.typeFlag == true);
assert(pr.containerData != nullptr);
assert(pr1.length == 0);
assert(pr1.containerData == nullptr);
}
void UnitTest::quantityConstructorTEST()
{
Primes pr(100,Primes::UNLIMITED);
assert(pr.containerData != nullptr);
assert(pr.length == 100);
assert(pr.typeFlag == Primes::UNLIMITED);
}
void UnitTest::copyConstructorTEST()
{
Primes pr1(0,Primes::UNLIMITED);
Primes pr2(pr1);
assert(pr1.containerData != pr2.containerData);
assert(pr1.length == pr2.length);
assert(pr1.typeFlag == pr2.typeFlag);
}
void UnitTest::moveConstructorTEST()
{
Primes pr1(50);
Primes pr2(pr1);
pr1 = pr2;
assert(pr1.containerData != pr2.containerData);
assert(pr1.length == pr2.length);
assert(pr1.typeFlag == pr2.typeFlag);
}
void UnitTest::copyOperatorTEST()
{
Primes pr1(50,Primes::UNLIMITED);
Primes pr2(std::move(pr1));
assert(pr1.containerData == nullptr);
assert(pr1.length == 0);
assert(pr1.typeFlag == false);
assert(pr2.containerData != nullptr);
assert(pr2.length == 50);
assert(pr2.typeFlag == false);
}
void UnitTest::moveOperatorTEST()
{
Primes pr1(50,Primes::UNLIMITED);
Primes pr2(10,Primes::UNLIMITED);
pr2 = std::move(pr1);
assert(pr1.containerData == nullptr);
assert(pr1.length == 0);
assert(pr1.typeFlag == false);
assert(pr2.containerData != nullptr);
assert(pr2.length == 50);
assert(pr2.typeFlag == false);
}
void UnitTest::beginTEST()
{
Primes pr1;
assert(pr1.begin().pointer != nullptr);
assert(pr1.begin().pointer == pr1.containerData);
}
void UnitTest::endTEST()
{
Primes pr1;
Primes pr2(0,Primes::UNLIMITED);
//assert(pr1.end() == Primes::Iterator(pr1.containerData + pr1.length));
//assert(pr2.end() == Primes::Iterator(nullptr));
}
void UnitTest::sizeTEST()
{
Primes pr1(100,Primes::UNLIMITED);
assert(pr1.length == pr1.size());
}
void UnitTest::indexOperatorTEST()
{
Primes pr1(100,Primes::UNLIMITED);
assert(pr1.containerData[30] == pr1[30]);
}
int main(int argc, char* argv[])
{
UnitTest::startAllTests();
std::cout << std::endl << "press something to exit" << std::endl;
getchar();
}