diff options
author | Florian Hahn <florian.hahn@arm.com> | 2018-06-08 21:14:49 +0000 |
---|---|---|
committer | Florian Hahn <florian.hahn@arm.com> | 2018-06-08 21:14:49 +0000 |
commit | 79510be7cfd297e04b37d4def233aa416cdbc8f4 (patch) | |
tree | 0859ab1d59210bcb30273c8c261be92f5f68ec62 /llvm/unittests/ADT/SmallSetTest.cpp | |
parent | 9391061fd7c7a09df6a502cf038f52e0402d7a69 (diff) | |
download | bcm5719-llvm-79510be7cfd297e04b37d4def233aa416cdbc8f4.tar.gz bcm5719-llvm-79510be7cfd297e04b37d4def233aa416cdbc8f4.zip |
[SmallSet] Add some simple unit tests.
Reviewers: craig.topper, dblaikie
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D47940
llvm-svn: 334321
Diffstat (limited to 'llvm/unittests/ADT/SmallSetTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallSetTest.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/SmallSetTest.cpp b/llvm/unittests/ADT/SmallSetTest.cpp new file mode 100644 index 00000000000..7608e65674e --- /dev/null +++ b/llvm/unittests/ADT/SmallSetTest.cpp @@ -0,0 +1,70 @@ +//===- llvm/unittest/ADT/SmallSetTest.cpp ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// SmallSet unit tests. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/SmallSet.h" +#include "gtest/gtest.h" + +using namespace llvm; + +TEST(SmallSetTest, Insert) { + + SmallSet<int, 4> s1; + + for (int i = 0; i < 4; i++) + s1.insert(i); + + for (int i = 0; i < 4; i++) + s1.insert(i); + + EXPECT_EQ(4u, s1.size()); + + for (int i = 0; i < 4; i++) + EXPECT_EQ(1u, s1.count(i)); + + EXPECT_EQ(0u, s1.count(4)); +} + +TEST(SmallSetTest, Grow) { + SmallSet<int, 4> s1; + + for (int i = 0; i < 8; i++) + s1.insert(i); + + EXPECT_EQ(8u, s1.size()); + + for (int i = 0; i < 8; i++) + EXPECT_EQ(1u, s1.count(i)); + + EXPECT_EQ(0u, s1.count(8)); +} + +TEST(SmallSetTest, Erase) { + SmallSet<int, 4> s1; + + for (int i = 0; i < 8; i++) + s1.insert(i); + + EXPECT_EQ(8u, s1.size()); + + // Remove elements one by one and check if all other elements are still there. + for (int i = 0; i < 8; i++) { + EXPECT_EQ(1u, s1.count(i)); + EXPECT_TRUE(s1.erase(i)); + EXPECT_EQ(0u, s1.count(i)); + EXPECT_EQ(8u - i - 1, s1.size()); + for (int j = i + 1; j < 8; j++) + EXPECT_EQ(1u, s1.count(j)); + } + + EXPECT_EQ(0u, s1.count(8)); +} |