Skip to content

Commit 74ba8e0

Browse files
committed
Fixed clang-format issues
1 parent 655df71 commit 74ba8e0

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include <algorithm>
2+
#include <fstream>
3+
#include <iostream>
4+
#include <map>
5+
#include <set>
6+
#include <sstream>
7+
#include <string>
8+
#include <vector>
9+
10+
// Helper to trim whitespace
11+
std::string trim(const std::string &s)
12+
{
13+
size_t start = s.find_first_not_of(" \t\r\n");
14+
size_t end = s.find_last_not_of(" \t\r\n");
15+
return (start == std::string::npos) ? "" : s.substr(start, end - start + 1);
16+
}
17+
18+
// Parse matrices from XML file
19+
std::map<std::string, std::vector<std::string>> parse_matrices(const std::string &filename)
20+
{
21+
std::ifstream file(filename);
22+
std::map<std::string, std::vector<std::string>> matrices;
23+
std::string line, current_name;
24+
bool in_matrix = false;
25+
std::vector<std::string> values;
26+
27+
while (std::getline(file, line)) {
28+
line = trim(line);
29+
if (line.find("<Matrix") == 0) {
30+
size_t name_pos = line.find("name=\"");
31+
if (name_pos != std::string::npos) {
32+
size_t start = name_pos + 6;
33+
size_t end = line.find("\"", start);
34+
current_name = line.substr(start, end - start);
35+
in_matrix = true;
36+
values.clear();
37+
}
38+
} else if (in_matrix && line.find("</Matrix>") == 0) {
39+
matrices[current_name] = values;
40+
in_matrix = false;
41+
} else if (in_matrix) {
42+
std::istringstream iss(line);
43+
std::string val;
44+
while (iss >> val) {
45+
values.push_back(val);
46+
}
47+
}
48+
}
49+
return matrices;
50+
}
51+
52+
int main(int argc, char *argv[])
53+
{
54+
if (argc != 3) {
55+
std::cerr << "Usage: compare_matrices good_output.xml test_output.xml\n";
56+
return 1;
57+
}
58+
59+
auto good = parse_matrices(argv[1]);
60+
auto test = parse_matrices(argv[2]);
61+
62+
std::set<std::string> all_vars;
63+
for (const auto &kv : good)
64+
all_vars.insert(kv.first);
65+
for (const auto &kv : test)
66+
all_vars.insert(kv.first);
67+
68+
int compared = 0;
69+
std::vector<std::string> mismatched_vars;
70+
71+
for (const auto &var : all_vars) {
72+
int in_good = good.count(var);
73+
int in_test = test.count(var);
74+
75+
if (in_good == 0) {
76+
std::cout << "Variable '" << var
77+
<< "' present in test output but missing from good output.\n";
78+
continue;
79+
}
80+
if (in_test == 0) {
81+
std::cout << "Variable '" << var
82+
<< "' present in good output but missing from test output.\n";
83+
continue;
84+
}
85+
86+
compared++;
87+
const auto &good_vals = good[var];
88+
const auto &test_vals = test[var];
89+
if (good_vals.size() != test_vals.size()) {
90+
std::cout << "Variable '" << var
91+
<< "' has different number of values (good: " << good_vals.size()
92+
<< ", test: " << test_vals.size() << ").\n";
93+
mismatched_vars.push_back(var);
94+
continue;
95+
}
96+
bool mismatch = false;
97+
for (size_t i = 0; i < good_vals.size(); ++i) {
98+
if (good_vals[i] != test_vals[i]) {
99+
mismatch = true;
100+
break;
101+
}
102+
}
103+
if (mismatch) {
104+
std::cout << "Variable '" << var << "' has mismatched values.\n";
105+
mismatched_vars.push_back(var);
106+
}
107+
}
108+
109+
std::cout << compared << " variables compared.\n";
110+
if (!mismatched_vars.empty()) {
111+
std::cout << "Mismatched values found for variables:\n";
112+
for (const auto &var : mismatched_vars) {
113+
std::cout << " " << var << "\n";
114+
}
115+
} else {
116+
std::cout << "All compared variables matched.\n";
117+
}
118+
return 0;
119+
}

0 commit comments

Comments
 (0)