-
Notifications
You must be signed in to change notification settings - Fork 20
/
run.template
79 lines (71 loc) · 1.87 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
#include "%TaskFile%"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cctype>
#include <ctime>
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() {
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 << "Test #" << ++testID << std::endl;
std::cout << "Input: \n" << test.input << std::endl;
if (test.has_output) {
std::cout << "Expected output: \n" << test.output << std::endl;
}
else {
std::cout << "Expected output: \n" << "N/A" << std::endl;
}
if (test.active) {
std::stringstream in(test.input);
std::ostringstream out;
std::clock_t start = std::clock();
%ClassName% solver;
%SolverCall%
std::clock_t finish = std::clock();
double currentTime = double(finish - start) / CLOCKS_PER_SEC;
maxTime = std::max(currentTime, maxTime);
std::cout << "Actual output: \n" << out.str() << std::endl;
if (test.has_output) {
bool result = jhelper::check(test.output, out.str());
allOK = allOK && result;
std::cout << "Result: " << (result ? "OK" : "Wrong answer") << std::endl;
}
std::cout << "Time: " << currentTime << std::endl;
}
else {
std::cout << "SKIPPED\n";
}
std::cout << std::endl;
}
if(allOK) {
std::cout << "All OK" << std::endl;
}
else {
std::cout << "Some cases failed" << std::endl;
}
std::cout << "Maximal time: " << maxTime << "s." << std::endl;
return 0;
}