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/static_vector_test.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/test/static_vector_test.cpp')
-rw-r--r-- | source/test/static_vector_test.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/source/test/static_vector_test.cpp b/source/test/static_vector_test.cpp new file mode 100644 index 0000000..ad42b34 --- /dev/null +++ b/source/test/static_vector_test.cpp @@ -0,0 +1,56 @@ +#include "StarStaticVector.hpp" + +#include "gtest/gtest.h" + +using namespace Star; + +TEST(StaticVectorTest, InsertErase) { + typedef StaticVector<int, 64> 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(StaticVectorTest, Comparators) { + typedef StaticVector<int, 64> 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(StaticVectorTest, SizeLimits) { + StaticVector<int, 0> a; + StaticVector<int, 1> b; + b.push_back(0); + StaticVector<int, 2> c; + c.resize(2, 0); + + EXPECT_THROW(a.push_back(0), StaticVectorSizeException); + EXPECT_THROW(b.push_back(0), StaticVectorSizeException); + EXPECT_THROW(c.push_back(0), StaticVectorSizeException); +} |