-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
73 lines (59 loc) · 1.6 KB
/
test.cpp
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
#include "Calculator.hpp"
#include <sstream>
std::string read_file(const std::string& file_name)
{
std::ifstream f(file_name.c_str());
std::stringstream ss;
ss << f.rdbuf();
return ss.str();
}
bool test(int test_num)
{
const char quit = 'q';
const char print = ';';
std::string test_filename = "test_files/test";
std::string res_filename = "test_files/result";
std::string ref_res_filename = "test_files/ref_result";
test_filename += std::to_string(test_num);
res_filename += std::to_string(test_num);
ref_res_filename += std::to_string(test_num);
test_filename += ".txt";
res_filename += ".txt";
ref_res_filename += ".txt";
std::ifstream fin(test_filename.c_str(), std::ios::in);
std::ofstream fout( res_filename.c_str(), std::ios::out);
//std::cout << read_file(test_filename) << "\n";
Token_Stream < std::ifstream > token_stream{ fin };
calculate(token_stream, quit, print, fout);
fout.close();
fin.close();
std::string res = read_file(res_filename);
std::string ref_res = read_file(ref_res_filename);
//std::cout <<"res " << res << "\n";
//std::cout << "ref res " << ref_res << "\n";
if (res == ref_res)
{
std::cout << "Test " << test_num << " passed\n";
return true;
}
else
{
std::cout << "Test " << test_num << " failed\n";
return false;
}
}
int main()
{
int num_of_passed = 0;
int total_num = 12;
for (int i = 0; i < total_num; i++)
{
bool flag = test(i);
if(flag)
{
num_of_passed++;
}
}
std::cout << "Total " << num_of_passed << " tests passed out of " << total_num << "\n";
return 0;
}