Skip to content

Commit 9e927ec

Browse files
committed
Fixed file name mistake
1 parent 74ba8e0 commit 9e927ec

2 files changed

Lines changed: 99 additions & 211 deletions

File tree

Testing/RegressionTesting/compare-matrices.cpp

Lines changed: 0 additions & 119 deletions
This file was deleted.
Lines changed: 99 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,119 @@
1-
#include <iostream>
1+
#include <algorithm>
22
#include <fstream>
3+
#include <iostream>
4+
#include <map>
5+
#include <set>
36
#include <sstream>
47
#include <string>
58
#include <vector>
6-
#include <map>
7-
#include <set>
8-
#include <algorithm>
99

1010
// Helper to trim whitespace
11-
std::string trim(const std::string& s) {
12-
size_t start = s.find_first_not_of(" \t\r\n");
13-
size_t end = s.find_last_not_of(" \t\r\n");
14-
return (start == std::string::npos) ? "" : s.substr(start, end - start + 1);
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);
1516
}
1617

1718
// Parse matrices from XML file
18-
std::map<std::string, std::vector<std::string>> parse_matrices(const std::string& filename) {
19-
std::ifstream file(filename);
20-
std::map<std::string, std::vector<std::string>> matrices;
21-
std::string line, current_name;
22-
bool in_matrix = false;
23-
std::vector<std::string> values;
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;
2426

25-
while (std::getline(file, line)) {
26-
line = trim(line);
27-
if (line.find("<Matrix") == 0) {
28-
size_t name_pos = line.find("name=\"");
29-
if (name_pos != std::string::npos) {
30-
size_t start = name_pos + 6;
31-
size_t end = line.find("\"", start);
32-
current_name = line.substr(start, end - start);
33-
in_matrix = true;
34-
values.clear();
35-
}
36-
} else if (in_matrix && line.find("</Matrix>") == 0) {
37-
matrices[current_name] = values;
38-
in_matrix = false;
39-
} else if (in_matrix) {
40-
std::istringstream iss(line);
41-
std::string val;
42-
while (iss >> val) {
43-
values.push_back(val);
44-
}
45-
}
46-
}
47-
return matrices;
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;
4850
}
4951

50-
int main(int argc, char* argv[]) {
51-
if (argc != 3) {
52-
std::cerr << "Usage: compare_matrices good_output.xml test_output.xml\n";
53-
return 1;
54-
}
55-
56-
auto good = parse_matrices(argv[1]);
57-
auto test = parse_matrices(argv[2]);
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+
}
5858

59-
std::set<std::string> all_vars;
60-
for (const auto& kv : good) all_vars.insert(kv.first);
61-
for (const auto& kv : test) all_vars.insert(kv.first);
59+
auto good = parse_matrices(argv[1]);
60+
auto test = parse_matrices(argv[2]);
6261

63-
int compared = 0;
64-
std::vector<std::string> mismatched_vars;
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);
6567

66-
for (const auto& var : all_vars) {
68+
int compared = 0;
69+
std::vector<std::string> mismatched_vars;
6770

68-
int in_good = good.count(var);
69-
int in_test = test.count(var);
71+
for (const auto &var : all_vars) {
72+
int in_good = good.count(var);
73+
int in_test = test.count(var);
7074

71-
if (in_good==0) {
72-
std::cout << "Variable '" << var << "' present in test output but missing from good output.\n";
73-
continue;
74-
}
75-
if (in_test==0) {
76-
std::cout << "Variable '" << var << "' present in good output but missing from test output.\n";
77-
continue;
78-
}
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+
}
7985

80-
compared++;
81-
const auto& good_vals = good[var];
82-
const auto& test_vals = test[var];
83-
if (good_vals.size() != test_vals.size()) {
84-
std::cout << "Variable '" << var << "' has different number of values (good: " << good_vals.size()
85-
<< ", test: " << test_vals.size() << ").\n";
86-
mismatched_vars.push_back(var);
87-
continue;
88-
}
89-
bool mismatch = false;
90-
for (size_t i = 0; i < good_vals.size(); ++i) {
91-
if (good_vals[i] != test_vals[i]) {
92-
mismatch = true;
93-
break;
94-
}
95-
}
96-
if (mismatch) {
97-
std::cout << "Variable '" << var << "' has mismatched values.\n";
98-
mismatched_vars.push_back(var);
99-
}
100-
}
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+
}
101108

102-
std::cout << compared << " variables compared.\n";
103-
if (!mismatched_vars.empty()) {
104-
std::cout << "Mismatched values found for variables:\n";
105-
for (const auto& var : mismatched_vars) {
106-
std::cout << " " << var << "\n";
107-
}
108-
} else {
109-
std::cout << "All compared variables matched.\n";
110-
}
111-
return 0;
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;
112119
}

0 commit comments

Comments
 (0)