-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathTestMain.cpp
More file actions
56 lines (48 loc) · 1.33 KB
/
TestMain.cpp
File metadata and controls
56 lines (48 loc) · 1.33 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
#include <functional>
#include "TestUtils.h"
namespace HealthPointsTests {
bool testInitialization();
bool testArithmaticOperators();
bool testComparisonOperators();
bool testOutputOperator();
}
namespace QueueTests {
bool testQueueMethods();
bool testModuleFunctions();
bool testExceptions();
bool testConstQueue();
}
std::function<bool()> testsList[] = {
HealthPointsTests::testInitialization,
HealthPointsTests::testArithmaticOperators,
HealthPointsTests::testComparisonOperators,
HealthPointsTests::testOutputOperator,
QueueTests::testQueueMethods,
QueueTests::testModuleFunctions,
QueueTests::testExceptions,
QueueTests::testConstQueue
};
const int NUMBER_OF_TESTS = sizeof(testsList)/sizeof(std::function<bool()>);
int main(int argc, char *argv[])
{
if (argc < 2) {
for (int i = 0; i < NUMBER_OF_TESTS; ++i) {
runTest(testsList[i], "Test " + std::to_string(i + 1));
}
}
else {
int idx = -1;
try {
idx = std::stoi(argv[1]) - 1;
} catch (const std::invalid_argument &e) {
std::cerr << "Error: invalid argument: " << argv[1] << std::endl;
return 1;
}
if (idx < 0 || idx > NUMBER_OF_TESTS - 1) {
std::cerr << "Error: index out of range: " << argv[1] << std::endl;
return 1;
}
runTest(testsList[idx], "Test " + std::to_string(idx + 1));
}
return 0;
}