diff options
author | Mark D. Roth <roth@google.com> | 2018-01-25 06:51:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-25 06:51:15 -0800 |
commit | 8ddc6b2658e54b7361d94098b5b027b56a5d1ac6 (patch) | |
tree | a949451f08c2b369155fedefe1e3f7f21dee2528 /test | |
parent | 80c9631ad086f20ad49619100df61e7a15e94603 (diff) | |
parent | d0e1f7466e00b826404881ae1eefa276736be0f4 (diff) |
Merge pull request #14146 from markdroth/inlined_vector_clear
Add clear() method for InlinedVector<>.
Diffstat (limited to 'test')
-rw-r--r-- | test/core/gprpp/inlined_vector_test.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/core/gprpp/inlined_vector_test.cc b/test/core/gprpp/inlined_vector_test.cc index 0e712dafe4..b900afaf3d 100644 --- a/test/core/gprpp/inlined_vector_test.cc +++ b/test/core/gprpp/inlined_vector_test.cc @@ -64,6 +64,44 @@ TEST(InlinedVectorTest, EmplaceBack) { EXPECT_EQ(3, *v[0]); } +TEST(InlinedVectorTest, ClearAndRepopulate) { + const int kNumElements = 10; + InlinedVector<int, 5> v; + EXPECT_EQ(0UL, v.size()); + for (int i = 0; i < kNumElements; ++i) { + v.push_back(i); + EXPECT_EQ(i + 1UL, v.size()); + } + for (int i = 0; i < kNumElements; ++i) { + EXPECT_EQ(i, v[i]); + } + v.clear(); + EXPECT_EQ(0UL, v.size()); + for (int i = 0; i < kNumElements; ++i) { + v.push_back(kNumElements + i); + EXPECT_EQ(i + 1UL, v.size()); + } + for (int i = 0; i < kNumElements; ++i) { + EXPECT_EQ(kNumElements + i, v[i]); + } +} + +TEST(InlinedVectorTest, ConstIndexOperator) { + const int kNumElements = 10; + InlinedVector<int, 5> v; + EXPECT_EQ(0UL, v.size()); + for (int i = 0; i < kNumElements; ++i) { + v.push_back(i); + EXPECT_EQ(i + 1UL, v.size()); + } + auto const_func = [kNumElements](const InlinedVector<int, 5>& v) { + for (int i = 0; i < kNumElements; ++i) { + EXPECT_EQ(i, v[i]); + } + }; + const_func(v); +} + } // namespace testing } // namespace grpc_core |