-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcpjudge.cpp
More file actions
43 lines (35 loc) · 943 Bytes
/
cpjudge.cpp
File metadata and controls
43 lines (35 loc) · 943 Bytes
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
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
string readFile(string path)
{
ifstream file(path);
return string((istreambuf_iterator<char>(file)),
istreambuf_iterator<char>());
}
int main()
{
int total = 2;
int passed = 0;
for(int i=1;i<=total;i++)
{
string input = "tests/input" + to_string(i) + ".txt";
string expected = "tests/output" + to_string(i) + ".txt";
string cmd = "./solution < " + input + " > temp.txt";
system(cmd.c_str());
string out = readFile("temp.txt");
string exp = readFile(expected);
if(out.find(exp) != string::npos)
{
cout << "Test " << i << " PASSED\n";
passed++;
}
else
{
cout << "Test " << i << " FAILED\n";
}
}
cout << "\nPassed " << passed << "/" << total << " tests\n";
}