[llvm] r292817 - Add unittests for empty bitvectors.

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 11:06:54 PST 2017


Author: matze
Date: Mon Jan 23 13:06:54 2017
New Revision: 292817

URL: http://llvm.org/viewvc/llvm-project?rev=292817&view=rev
Log:
Add unittests for empty bitvectors.

Addendum to r292575

Modified:
    llvm/trunk/unittests/ADT/BitVectorTest.cpp

Modified: llvm/trunk/unittests/ADT/BitVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/BitVectorTest.cpp?rev=292817&r1=292816&r2=292817&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/BitVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/BitVectorTest.cpp Mon Jan 23 13:06:54 2017
@@ -425,5 +425,42 @@ TYPED_TEST(BitVectorTest, MoveAssignment
   EXPECT_EQ(C, B);
 }
 
+template<class TypeParam>
+static void testEmpty(const TypeParam &A) {
+  EXPECT_TRUE(A.empty());
+  EXPECT_EQ((size_t)0, A.size());
+  EXPECT_EQ((size_t)0, A.count());
+  EXPECT_FALSE(A.any());
+  EXPECT_TRUE(A.all());
+  EXPECT_TRUE(A.none());
+  EXPECT_EQ(-1, A.find_first());
+  EXPECT_EQ(A, TypeParam());
+}
+
+/// Tests whether BitVector behaves well with Bits==nullptr, Capacity==0
+TYPED_TEST(BitVectorTest, EmptyVector) {
+  TypeParam A;
+  testEmpty(A);
+
+  TypeParam B;
+  B.reset();
+  testEmpty(B);
+
+  TypeParam C;
+  C.clear();
+  testEmpty(C);
+
+  TypeParam D(A);
+  testEmpty(D);
+
+  TypeParam E;
+  E = A;
+  testEmpty(E);
+
+  TypeParam F;
+  E.reset(A);
+  testEmpty(E);
+}
+
 }
 #endif




More information about the llvm-commits mailing list