[PATCH] D113461: [ADT] Add unit test for EquivalanceClasses comparator

Matthias Springer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 16 15:08:19 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG068483978b37: [ADT] Add unit test for EquivalanceClasses comparator (authored by springerm).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113461/new/

https://reviews.llvm.org/D113461

Files:
  llvm/unittests/ADT/EquivalenceClassesTest.cpp


Index: llvm/unittests/ADT/EquivalenceClassesTest.cpp
===================================================================
--- llvm/unittests/ADT/EquivalenceClassesTest.cpp
+++ llvm/unittests/ADT/EquivalenceClassesTest.cpp
@@ -66,8 +66,14 @@
         EXPECT_FALSE(EqClasses.isEquivalent(i, j));
 }
 
-TEST(EquivalenceClassesTest, MultipleSets) {
-  EquivalenceClasses<int> EqClasses;
+// Type-parameterized tests: Run the same test cases with different element
+// types.
+template <typename T> class ParameterizedTest : public testing::Test {};
+
+TYPED_TEST_SUITE_P(ParameterizedTest);
+
+TYPED_TEST_P(ParameterizedTest, MultipleSets) {
+  TypeParam EqClasses;
   // Split numbers from [0, 100) into sets so that values in the same set have
   // equal remainders (mod 17).
   for (int i = 0; i < 100; i++)
@@ -81,4 +87,30 @@
         EXPECT_FALSE(EqClasses.isEquivalent(i, j));
 }
 
+namespace {
+// A dummy struct for testing EquivalenceClasses with a comparator.
+struct TestStruct {
+  TestStruct(int value) : value(value) {}
+
+  bool operator==(const TestStruct &other) const {
+    return value == other.value;
+  }
+
+  int value;
+};
+// Comparator to be used in test case.
+struct TestStructComparator {
+  bool operator()(const TestStruct &lhs, const TestStruct &rhs) const {
+    return lhs.value < rhs.value;
+  }
+};
+} // namespace
+
+REGISTER_TYPED_TEST_SUITE_P(ParameterizedTest, MultipleSets);
+using ParamTypes =
+    testing::Types<EquivalenceClasses<int>,
+                   EquivalenceClasses<TestStruct, TestStructComparator>>;
+INSTANTIATE_TYPED_TEST_SUITE_P(EquivalenceClassesTest, ParameterizedTest,
+                               ParamTypes);
+
 } // llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113461.387772.patch
Type: text/x-patch
Size: 1685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211116/3473e6e8/attachment.bin>


More information about the llvm-commits mailing list