-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
81 lines (71 loc) · 2.96 KB
/
Copy pathtests.cpp
File metadata and controls
81 lines (71 loc) · 2.96 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
#include "utils.h"
#include "genome.h"
#include "readcontainer.h"
#include <memory>
#include <iostream>
#include <vector>
using namespace std;
uint errors(0);
uint lineNum(0);
string testmode;
vector<string> errorList;
void set_mode ( const string prg, const string module, const string options = "" ) {
cout << "Testing " << prg << " from " << module << ((options == "") ? "" : " "+options) << endl;
testmode = module + " " + prg + " " + options;
}
void test_assert( bool success, string strTest, string strError ) {
cout << to_string(++lineNum) << " Testing: " << strTest << "... ";
if (success) {
cout << "ok\n";
}
else {
errorList.push_back(to_string(lineNum) + ": " + testmode);
cout << "ERROR: " << strError << endl;
}
}
int main( int argc, char** argv ) {
/* ######################################################################
* utils.h strsplit
* ###################################################################### */
set_mode("strsplit", "utils");
{
string testIn = "This is a test string";
uint nExpected = 5;
auto result = strsplit(testIn, " ");
string strExpected[] = {"This", "is", "a", "test", "string"};
test_assert(result.size() == nExpected, "number of splits", to_string(result.size()) + " tokens instead of " + to_string(nExpected));
for (uint i(0); i < result.size(); ++i) {
test_assert(strExpected[i] == result.at(i), "value #" + to_string(i), "strsplit: " + result.at(i) + " should be " + strExpected[i]);
}
}
set_mode("strsplit", "utils", "without empty tokens");
{
string testIn = "This is a test string";
uint nExpected = 5;
auto result = strsplit(testIn, " ", false);
string strExpected[] = {"This", "is", "a", "test", "string"};
test_assert(result.size() == nExpected, "number of splits", to_string(result.size()) + " tokens instead of expected " + to_string(nExpected));
for (uint i(0); i < result.size(); ++i) {
test_assert(strExpected[i] == result.at(i), "value #" + to_string(i), "strsplit: " + result.at(i) + " should be " + strExpected[i]);
}
}
set_mode("strsplit", "utils", "with empty tokens");
{
string testIn = "This is a test string";
uint nExpected = 8;
auto result = strsplit(testIn, " ", true);
string strExpected[] = {"This", "is", "", "", "a", "test", "", "string"};
test_assert(result.size() == nExpected, "number of splits", to_string(result.size()) + " tokens instead of " + to_string(nExpected));
for (uint i(0); i < result.size(); ++i) {
test_assert(strExpected[i] == result.at(i), "value #" + to_string(i), "strsplit: " + result.at(i) + " should be " + strExpected[i]);
}
}
/* ######################################################################
* Done, print results
* ###################################################################### */
cout << "Unit testing done, " << errors << " error(s)\n";
for (auto& err_str : errorList) {
cout << err_str << endl;
}
return 0;
}