-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
73 lines (72 loc) · 1.73 KB
/
test.cpp
File metadata and controls
73 lines (72 loc) · 1.73 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
#ifndef TEST_YAY_CPP
#define TEST_YAY_CPP
#include "test.h"
bool Test::fail = false;
Test::Test(const char* file_name)
{
ifstream file(file_name);
string line;
while( getline(file, line) )
{
sets.add_set(line);
}
}
bool Test::my_return(bool ret)
{
if(!ret)
fail = true;
return ret;
}
bool Test::test_duplicates(unsigned int expected_duplicates,
unsigned int expected_unique)
{
unsigned int dup, uni;
sets.get_n_duplicates(dup, uni);
return my_return((dup==expected_duplicates) and (expected_unique==uni));
}
bool Test::test_most_repeated(vector<int> expected, unsigned int n_repeated)
{
int ret;
vector<int> s = sets.get_most_repeated_vec(ret);
auto it1 = expected.begin();
for(auto it0 = s.begin();
(it0 != s.end()) && (it1 != expected.end());
++it0, ++it1)
{
if(*it0 != *it1)
return false;
}
return my_return(ret == n_repeated);
}
bool Test::test_invalids(vector<string> expected)
{
return my_return(expected == sets.get_invalids());
}
void Test::print_most_repeated()
{
int times;
string s = sets.get_most_repeated(times);
cout << s << " repeated " << times << " times.\n";
}
void Test::print_invalid()
{
cout << "Invalid inputs:" << endl;
auto& vec = sets.get_invalids();
for(auto& i : vec )
cout << i << endl;
cout << "Total invalid lines: " << vec.size()<< endl;
}
void Test::print_n_duplicates()
{
unsigned int dup, unique;
sets.get_n_duplicates(dup, unique);
cout << "Total duplicates: " << dup <<".\n";
cout << "Total unique: " << unique << ".\n";
}
void Test::print_all()
{
print_n_duplicates();
print_most_repeated();
print_invalid();
}
#endif