osb/source/test/static_vector_test.cpp

57 lines
1.6 KiB
C++
Raw Normal View History

2023-06-20 04:33:09 +00:00
#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);
}