-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
47 lines (35 loc) · 1.33 KB
/
test.cpp
File metadata and controls
47 lines (35 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
#include <iostream>
#include <sstream>
#include <string>
#include <filesystem>
#include <fstream>
#include <algorithm>
#include "app.h"
namespace fs = std::filesystem;
void print_OX(std::string prompt, bool condition) {
std::cout << prompt << " : " << (condition ? "O" : "X") << std::endl;
}
bool is_space(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r';
}
void test(std::string test_name, fs::path input, fs::path output) {
std::ifstream ifs(input);
std::string line;
std::ostringstream oss;
App app(ifs, oss);
app.run();
std::string output_app = oss.str();
std::ifstream ifs_answer(output);
std::string output_answer((std::istreambuf_iterator<char>(ifs_answer)), (std::istreambuf_iterator<char>()));
output_app.erase(std::remove_if(output_app.begin(), output_app.end(), is_space), output_app.end());
output_answer.erase(std::remove_if(output_answer.begin(), output_answer.end(), is_space), output_answer.end());
bool is_correct = output_app == output_answer;
print_OX(test_name, is_correct);
}
int main() {
test("Test 1 - Login O", "test/1_1.in", "test/1_1.out");
test("Test 1 - Login X", "test/1_2.in", "test/1_2.out");
test("Test 2", "test/2_post.in", "test/2.out");
test("Test 3", "test/3_post.in", "test/3.out");
test("Test 4", "test/4_post.in", "test/4.out");
}