Skip to content

Commit af8a228

Browse files
committed
Fix incorrect set_difference usage
1 parent 1939bfb commit af8a228

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/substrait/textplan/tests/ParseResultMatchers.cpp

+19-16
Original file line numberDiff line numberDiff line change
@@ -149,31 +149,34 @@ class HasSymbolsMatcher {
149149

150150
bool MatchAndExplain(const ParseResult& result, std::ostream* listener)
151151
const {
152-
auto actualSymbols = symbolNames(result.getSymbolTable().getSymbols());
152+
// Note: Need set or sorted vector for set_difference.
153+
auto actualSymbolsSorted =
154+
symbolNames(result.getSymbolTable().getSymbols());
155+
std::sort(actualSymbolsSorted.begin(), actualSymbolsSorted.end());
156+
std::vector<std::string> extraSymbols;
157+
auto expectedSymbolsSorted = expectedSymbols_;
158+
std::sort(expectedSymbolsSorted.begin(), expectedSymbolsSorted.end());
153159
if (listener != nullptr) {
154-
std::vector<std::string> extraSymbols(actualSymbols.size());
155160
auto end = std::set_difference(
156-
actualSymbols.begin(),
157-
actualSymbols.end(),
158-
expectedSymbols_.begin(),
159-
expectedSymbols_.end(),
160-
extraSymbols.begin());
161-
extraSymbols.resize(end - extraSymbols.begin());
161+
actualSymbolsSorted.begin(),
162+
actualSymbolsSorted.end(),
163+
expectedSymbolsSorted.begin(),
164+
expectedSymbolsSorted.end(),
165+
std::back_inserter(extraSymbols));
162166
if (!extraSymbols.empty()) {
163167
*listener << std::endl << " with extra symbols: ";
164168
for (const auto& symbol : extraSymbols) {
165169
*listener << " \"" << symbol << "\"";
166170
}
167171
}
168172

169-
std::vector<std::string> missingSymbols(expectedSymbols_.size());
173+
std::vector<std::string> missingSymbols;
170174
end = std::set_difference(
171-
expectedSymbols_.begin(),
172-
expectedSymbols_.end(),
173-
actualSymbols.begin(),
174-
actualSymbols.end(),
175-
missingSymbols.begin());
176-
missingSymbols.resize(end - missingSymbols.begin());
175+
expectedSymbolsSorted.begin(),
176+
expectedSymbolsSorted.end(),
177+
actualSymbolsSorted.begin(),
178+
actualSymbolsSorted.end(),
179+
std::back_inserter(missingSymbols));
177180
if (!missingSymbols.empty()) {
178181
if (!extraSymbols.empty()) {
179182
*listener << ", and missing symbols: ";
@@ -185,7 +188,7 @@ class HasSymbolsMatcher {
185188
}
186189
}
187190
}
188-
return actualSymbols == expectedSymbols_;
191+
return actualSymbolsSorted == expectedSymbolsSorted;
189192
}
190193

191194
void DescribeTo(std::ostream* os) const {

0 commit comments

Comments
 (0)