-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmp.cpp
More file actions
141 lines (128 loc) · 3.26 KB
/
Copy pathcmp.cpp
File metadata and controls
141 lines (128 loc) · 3.26 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <string>
#include <vector>
int read_res(FILE *f, std::vector<std::string> &rel, std::set<std::map<std::string, int> > &data) {
char *buf = NULL;
size_t len_buf = 0;
size_t len = getline(&buf, &len_buf, f);
if (len == -1) {
printf("UNKNOWN\n");
exit(EXIT_SUCCESS);
}
if (!strcmp(buf, "Infinite\n")) return 1;
if (strcmp(buf, "Finite\n")) {
printf("UNKNOWN\n");
exit(EXIT_SUCCESS);
}
len = getline(&buf, &len_buf, f);
if (len == -1) {
printf("UNKNOWN\n");
exit(EXIT_SUCCESS);
}
assert(len >= 2);
assert(buf[0] == '(');
assert(buf[len - 1] == ')' || (buf[len - 1] == '\n' && buf[len - 2] == ')'));
int pos = 1;
while (buf[pos] != ')') {
std::string n;
while (buf[pos] != ',' && buf[pos] != ')') {
n.push_back(buf[pos++]);
}
rel.push_back(n);
if (buf[pos] == ',') pos++;
}
while ((len = getline(&buf, &len_buf, f)) != -1) {
if (!strcmp(buf, "\n")) continue;
assert(len >= 2);
assert(buf[0] == '(');
assert(buf[len - 1] == ')' || (buf[len - 1] == '\n' && buf[len - 2] == ')'));
int pos = 1;
std::vector<int> tup;
while (buf[pos] != ')') {
std::string n;
while (buf[pos] != ',' && buf[pos] != ')') {
n.push_back(buf[pos++]);
}
tup.push_back(atoi(n.c_str()));
if (buf[pos] == ',') pos++;
}
assert(rel.size() == tup.size());
std::map<std::string, int> m;
for (unsigned i = 0; i < tup.size(); i++) m[rel[i]] = tup[i];
data.insert(m);
}
free(buf);
return 0;
}
void usage() {
fprintf(stderr, "\
Usage: cmp res1 res2 [res2neg]\n");
exit(EXIT_FAILURE);
}
int main(int argc, char **argv) {
if (argc != 3 && argc != 4) {
usage();
}
std::vector<std::string> rel1;
std::set<std::map<std::string, int> > data1;
FILE *f1 = fopen(argv[1], "r");
int inf1 = read_res(f1, rel1, data1);
fclose(f1);
std::vector<std::string> rel2;
std::set<std::map<std::string, int> > data2;
FILE *f2 = fopen(argv[2], "r");
int inf2 = read_res(f2, rel2, data2);
fclose(f2);
if (argc == 4) {
std::vector<std::string> rel3;
std::set<std::map<std::string, int> > data3;
FILE *f3 = fopen(argv[3], "r");
int inf3 = read_res(f3, rel3, data3);
fclose(f3);
int ok = 1;
for (auto it : data2) {
if (data1.find(it) == data1.end()) {
printf("POS WRONG;");
ok = 0;
break;
}
}
for (auto it : data3) {
if (data1.find(it) != data1.end()) {
printf("NEG WRONG;");
ok = 0;
break;
}
}
if (ok) printf("OK");
printf("\n");
} else {
if (inf1 == inf2 && data1 == data2) {
printf("OK\n");
} else {
printf("DIFF\n");
/*
for (auto it : data1) {
if (data2.find(it) == data2.end()) {
printf("ONLY IN data1:");
for (auto it2 : it) printf(" %s->%d", it2.first.c_str(), it2.second);
printf("\n");
}
}
for (auto it : data2) {
if (data1.find(it) == data1.end()) {
printf("ONLY IN data2:");
for (auto it2 : it) printf(" %s->%d", it2.first.c_str(), it2.second);
printf("\n");
}
}
*/
}
}
return 0;
}