Skip to content

Commit d34902c

Browse files
author
thk123
committed
Fix error in sorting properties that differ by property name
Add unit tests demonstrating the fix.
1 parent c238aee commit d34902c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/goto-checker/report_util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ is_property_less_than(const propertyt &property1, const propertyt &property2)
234234
const auto left_id_number = left_split.second;
235235

236236
const auto right_split = split_property_id(property2.first);
237-
const auto right_id_name = left_split.first;
238-
const auto right_id_number = left_split.second;
237+
const auto right_id_name = right_split.first;
238+
const auto right_id_number = right_split.second;
239239

240240
if(left_id_name != right_id_name)
241241
return left_id_name < right_id_name;

unit/goto-checker/report_util/is_property_less_than.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,34 @@ TEST_CASE("Comparing two properties")
6969
}
7070
}
7171
}
72+
SECTION("Compare property ids")
73+
{
74+
goto_programt::instructionst instructions;
75+
instructions.push_back(instruction_for_location("fileA", "funcA", 1));
76+
77+
std::vector<irep_idt> properties;
78+
properties.push_back("A.1");
79+
properties.push_back("A.2");
80+
properties.push_back("B.1");
81+
properties.push_back("B.2");
82+
83+
for(auto first_property = properties.begin();
84+
first_property != properties.end();
85+
++first_property)
86+
{
87+
for(auto second_property = std::next(first_property);
88+
second_property != properties.end();
89+
++second_property)
90+
{
91+
const propertyt p1 =
92+
property(*first_property, test_info(instructions.begin()));
93+
const propertyt p2 =
94+
property(*second_property, test_info(instructions.begin()));
95+
INFO(p1);
96+
INFO(p2);
97+
REQUIRE(is_property_less_than(p1, p2));
98+
REQUIRE_FALSE(is_property_less_than(p2, p1));
99+
}
100+
}
101+
}
72102
}

0 commit comments

Comments
 (0)