-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.template
104 lines (97 loc) · 3.35 KB
/
run.template
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "%TaskFile%"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cctype>
#include <ctime>
#include "../lib/general.h"
namespace jhelper {
struct Test {
std::string input;
std::string output;
bool active;
bool has_output;
};
bool check(std::string expected, std::string actual) {
while(!expected.empty() && isspace(*--expected.end()))
expected.erase(--expected.end());
while(!actual.empty() && isspace(*--actual.end()))
actual.erase(--actual.end());
return expected == actual;
}
} // namespace jhelper
int main() {
string blue = "\x1B[34m";
string red = "\x1B[31m";
string green = "\x1B[32m";
string yellow = "\x1B[33m";
string def = "\033[0m";
std::vector<jhelper::Test> tests = {
%Tests%
};
bool allOK = true;
int testID = 0;
std::cout << std::fixed;
double maxTime = 0.0;
for(const jhelper::Test& test: tests ) {
std::cout << blue << "Test #" << ++testID << def << std::endl;
if (!test.active) {
std::cout << yellow << "SKIPPED\n" << def;
std::cout << std::endl;
continue;
}
std::cout << blue << "Input: \n" << def << test.input << std::endl;
if (test.has_output) {
std::cout << blue << "Expected output: \n" << def << test.output << std::endl;
}
else {
std::cout << blue << "Expected output: \n" << def << yellow << "N/A" << def << std::endl;
}
if (test.active) {
std::ofstream inw;
inw.open("jhelperinput.txt");
inw << test.input;
inw.close();
freopen("jhelperinput.txt", "r", stdin);
ofstream fout("jhelperoutput.txt");
std::clock_t start = std::clock();
try {
in = Input();
out.setOut(fout);
%ClassName% solver;
%SolverCall%
out.flush();
fout.close();
} catch (const char* e) {
std::cerr << e << std::endl;
}
if (!in.isExhausted() && in.skipWhitespace() != EOF) {
cout << red << "Input is not exhausted" << def << endl;
}
std::clock_t finish = std::clock();
double currentTime = double(finish - start) / CLOCKS_PER_SEC;
maxTime = std::max(currentTime, maxTime);
std::ifstream t("jhelperoutput.txt");
std::stringstream output;
output << t.rdbuf();
std::cout << blue << "Actual output: \n" << def << output.str() << std::endl;
if (test.has_output) {
bool result = jhelper::check(test.output, output.str());
allOK = allOK && result;
std::cout << blue << "Result: " << def << (result ? green + "OK" : red + "Wrong answer") << def << std::endl;
}
std::cout << blue << "Time: " << int(currentTime) << "." << (int(currentTime * 10) % 10) << (int(currentTime * 100) % 10) << (int(currentTime * 1000) % 10) << "s" << def << std::endl;
t.close();
}
std::cout << std::endl;
}
if (allOK) {
std::cout << green << "All OK" << def << std::endl;
} else {
std::cout << red << "Some cases failed" << def << std::endl;
}
std::cout << blue << "Maximal time: " << int(maxTime) << "." << (int(maxTime * 10) % 10) << (int(maxTime * 100) % 10) << (int(maxTime * 1000) % 10) << "s" << def << std::endl;
return 0;
}