diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/test/small_vector_test.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/test/small_vector_test.cpp')
-rw-r--r-- | source/test/small_vector_test.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/source/test/small_vector_test.cpp b/source/test/small_vector_test.cpp new file mode 100644 index 0000000..387c6a9 --- /dev/null +++ b/source/test/small_vector_test.cpp @@ -0,0 +1,59 @@ +#include "StarSmallVector.hpp" + +#include "gtest/gtest.h" + +using namespace Star; + +TEST(SmallVectorTest, InsertErase) { + typedef SmallVector<int, 2> SV; + SV a = {1, 2, 3, 4}; + EXPECT_EQ(a.size(), 4u); + EXPECT_EQ(a, SV({1, 2, 3, 4})); + EXPECT_NE(a, SV({1, 2, 3})); + a.insert(a.begin(), 0); + a.insert(a.begin(), -1); + EXPECT_EQ(a, SV({-1, 0, 1, 2, 3, 4})); + a.insert(a.begin(), {-3, -2}); + EXPECT_EQ(a, SV({-3, -2, -1, 0, 1, 2, 3, 4})); + a.erase(a.begin() + 1); + EXPECT_EQ(a, SV({-3, -1, 0, 1, 2, 3, 4})); + a.erase(a.begin(), a.begin() + 3); + EXPECT_EQ(a, SV({1, 2, 3, 4})); + a.insert(a.end(), {5, 6, 7, 8}); + EXPECT_EQ(a, SV({1, 2, 3, 4, 5, 6, 7, 8})); + a.erase(a.begin() + 2, a.end() - 2); + EXPECT_EQ(a, SV({1, 2, 7, 8})); + a.insert(a.begin() + 2, 6); + a.insert(a.begin() + 2, 5); + a.insert(a.begin() + 2, 4); + a.insert(a.begin() + 2, 3); + EXPECT_EQ(a, SV({1, 2, 3, 4, 5, 6, 7, 8})); + + SV b(a.begin(), a.end()); + EXPECT_EQ(b, SV({1, 2, 3, 4, 5, 6, 7, 8})); +} + +TEST(SmallVectorTest, Comparators) { + typedef SmallVector<int, 3> SV; + + EXPECT_TRUE(SV({1, 2, 3, 4}) < SV({1, 2, 3, 5})); + EXPECT_FALSE(SV({1, 2, 3, 4}) < SV({1, 2, 3, 4})); + EXPECT_FALSE(SV({1, 2, 3, 4}) < SV({1, 2, 3, 3})); + EXPECT_TRUE(SV({1, 2, 3}) < SV({1, 2, 3, 4})); + EXPECT_FALSE(SV({1, 2, 3, 4, 5}) < SV({1, 2, 3, 4})); +} + +TEST(SmallVectorTest, Destructors) { + auto i = make_shared<int>(0); + SmallVector<shared_ptr<int>, 1> v; + v.push_back(i); + v.push_back(i); + v.push_back(i); + EXPECT_EQ(i.use_count(), 4); + v.pop_back(); + EXPECT_EQ(i.use_count(), 3); + v.pop_back(); + EXPECT_EQ(i.use_count(), 2); + v.clear(); + EXPECT_EQ(i.use_count(), 1); +} |