-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTesting.cpp
More file actions
62 lines (49 loc) · 1.45 KB
/
Testing.cpp
File metadata and controls
62 lines (49 loc) · 1.45 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "Testing.h"
Testing::Testing(ParseFile parf){
pf = parf;
}
bool Testing::TestDefault(string filename){
Build b = pf.getBuild(filename);
stringbuf resbuf(ios::out);
auto oldresbuf = cout.rdbuf(std::addressof(resbuf));
b.Run();
cout.rdbuf(oldresbuf);
string resOutput = resbuf.str();
string ansOutput = getAnswer("java -jar venus.jar " + filename);
cout << "RESULT : " << resOutput << endl;
cout << "ANSWER : " << ansOutput << endl;
return resOutput == ansOutput;
}
void Testing::TestAll(){
string path = "Tests/default_commands";
int passed = 0;
int count = 0;
for(auto& entry : filesystem::directory_iterator(path)){
cout << "TEST " << (count+1) << " : " << entry.path() << endl;
count++;
if(TestDefault(entry.path())){
cout << "===| SUCCESS |===" << endl;
passed++;
}else{
cout << "===| FAILURE |===" << endl;
}
}
cout << "=======| " << passed << "/" << count << " PASSED |=======" << endl;
}
string Testing::getAnswer(string command) {
char buffer[128];
string result = "";
// Open pipe to file
FILE* pipe = popen(command.c_str(), "r");
if (!pipe) {
return "popen failed!";
}
// read till end of process:
while (!feof(pipe)) {
// use buffer to read and add to result
if (fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
}