-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.hpp
75 lines (69 loc) · 2.28 KB
/
utils.hpp
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
//
// Created by Wollenschneider Luis on 04.12.22.
//
#include <iostream>
#include <fstream>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <array>
#define COLOR_RED "\x1b[31m"
#define COLOR_GREEN "\x1b[32m"
#define COLOR_YELLOW "\x1b[33m"
#define COLOR_BLUE "\x1b[34m"
#define COLOR_MAGENTA "\x1b[35m"
#define COLOR_CYAN "\x1b[36m"
#define COLOR_RESET "\x1b[0m"
#define COLOR_WHITE "\x1b[0m"
std::string get_expected_result(const std::string& filepath) {
std::ifstream file(filepath);
if (!file.is_open()) {
std::cout << COLOR_RED "File not found" COLOR_RESET << std::endl;
// read use input
std::cout << COLOR_BLUE "Enter expected result: " COLOR_RESET;
std::string expected_result;
std::cin >> expected_result;
// create file with expected result as content at path filepath
std::ofstream f(filepath);
f << expected_result;
return expected_result;
}
std::string line;
std::getline(file, line);
file.close();
return line;
}
template<class T>
T get_expected_result(const std::string& filepath) {
std::string line = get_expected_result(filepath);
if (typeid(T) == typeid(int)) {
return std::stoi(line);
} else if (typeid(T) == typeid(long)) {
return std::stol(line);
} else if (typeid(T) == typeid(long long) || typeid(T) == typeid(long long int)) {
return std::stoll(line);
}
std::cout << "Type not yet supported!" << std::endl;
exit(1);
}
template <typename T>
bool evaluate_results(T test_result, T expected_result) {
std::cout << COLOR_MAGENTA "TEST: " COLOR_RESET;
if (test_result == expected_result) {
std::cout << COLOR_GREEN << "PASSED" << COLOR_RESET << std::endl;
return true;
} else {
std::cout << COLOR_RED << "FAILED" << COLOR_RESET << std::endl;
std::cout << COLOR_BLUE << "Expected: " << expected_result << COLOR_RESET << std::endl;
std::cout << COLOR_RED << "Got: " << test_result << COLOR_RESET << std::endl;
return false;
}
}
template <typename T>
void tried_before(T res, std::set<T>& tried) {
if (tried.find(res) != tried.end()) {
std::cout << COLOR_RED << "Already tried: " << res << COLOR_RESET << std::endl;
}
}