Add a unittest for SmallDenseMap that tests assigning a SmallDenseMap when it is...
authorMichael Gottesman <mgottesman@apple.com>
Sat, 31 Oct 2015 05:23:53 +0000 (05:23 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Sat, 31 Oct 2015 05:23:53 +0000 (05:23 +0000)
This complements CopyConstructorNotSmallTest. If we are testing the copy
constructor in such a way, we should also probably test assignment in the same
way.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251736 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/ADT/DenseMapTest.cpp

index 2c6fe35883271a6a767b4cad8a5ad4a114b00bd8..f3dcf95e92fd6374780530c3cc3f3c0d9c673ff5 100644 (file)
@@ -252,6 +252,22 @@ TYPED_TEST(DenseMapTest, AssignmentTest) {
   EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
 }
 
   EXPECT_EQ(this->getValue(), copyMap[this->getKey()]);
 }
 
+TYPED_TEST(DenseMapTest, AssignmentTestNotSmall) {
+  for (int Key = 0; Key < 5; ++Key)
+    this->Map[this->getKey(Key)] = this->getValue(Key);
+  TypeParam copyMap = this->Map;
+
+  EXPECT_EQ(5u, copyMap.size());
+  for (int Key = 0; Key < 5; ++Key)
+    EXPECT_EQ(this->getValue(Key), copyMap[this->getKey(Key)]);
+
+  // test self-assignment.
+  copyMap = copyMap;
+  EXPECT_EQ(5u, copyMap.size());
+  for (int Key = 0; Key < 5; ++Key)
+    EXPECT_EQ(this->getValue(Key), copyMap[this->getKey(Key)]);
+}
+
 // Test swap method
 TYPED_TEST(DenseMapTest, SwapTest) {
   this->Map[this->getKey()] = this->getValue();
 // Test swap method
 TYPED_TEST(DenseMapTest, SwapTest) {
   this->Map[this->getKey()] = this->getValue();