[llvm] [EquivClasses] Introduce members iterator-helper (PR #130139)
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 7 06:16:55 PST 2025
================
@@ -66,6 +66,22 @@ TEST(EquivalenceClassesTest, TwoSets) {
EXPECT_FALSE(EqClasses.isEquivalent(i, j));
}
+TEST(EquivalenceClassesTest, MembersIterator) {
+ EquivalenceClasses<int> EC;
+ EC.unionSets(1, 2);
+ EC.insert(4);
+ EC.insert(5);
+ EC.unionSets(5, 1);
+ EXPECT_EQ(EC.getNumClasses(), 2u);
+
+ std::set<int> ActualMembers;
+ std::set<int> ExpectedMembers{1, 2, 5};
+ EquivalenceClasses<int>::iterator I = EC.findValue(EC.getLeaderValue(1));
+ for (auto M : EC.members(I))
+ ActualMembers.insert(M);
+ EXPECT_EQ(ActualMembers, ExpectedMembers);
----------------
kuhar wrote:
You can use `EXPECT_THAT(EC.members(I), testing::ElementsAre(1, 2, 5))`. This prints nice error messages on mismatched elements
https://github.com/llvm/llvm-project/pull/130139
More information about the llvm-commits
mailing list