[ADT] Add a pop_back_val method to the SparseSet container.

The next commit will use it.

llvm-svn: 263455
This commit is contained in:
Quentin Colombet
2016-03-14 18:10:41 +00:00
parent 7a21bb196b
commit de89d5f81f
2 changed files with 25 additions and 0 deletions

View File

@@ -183,4 +183,24 @@ TEST(SparseSetTest, AltStructSet) {
EXPECT_FALSE(Set.erase(5));
EXPECT_TRUE(Set.erase(6));
}
TEST(SparseSetTest, PopBack) {
USet Set;
const unsigned UpperBound = 300;
Set.setUniverse(UpperBound);
for (unsigned i = 0; i < UpperBound; ++i)
Set.insert(i);
// Make sure pop back returns the values in the reverse order we
// inserted them.
unsigned Expected = UpperBound;
while (!Set.empty())
ASSERT_TRUE(--Expected == Set.pop_back_val());
// Insert again the same elements in the sparse set and make sure
// each insertion actually inserts the elements. I.e., check
// that the underlying data structure are properly cleared.
for (unsigned i = 0; i < UpperBound; ++i)
ASSERT_TRUE(Set.insert(i).second);
}
} // namespace