diff --git a/slsSupportLib/include/sls/StaticVector.h b/slsSupportLib/include/sls/StaticVector.h index 3c671f80b..cf72aa05d 100644 --- a/slsSupportLib/include/sls/StaticVector.h +++ b/slsSupportLib/include/sls/StaticVector.h @@ -113,10 +113,10 @@ template class StaticVector { // auto begin() noexcept -> decltype(data_.begin()) { return data_.begin(); // } const_iterator begin() const noexcept { return data_.begin(); } - iterator end() noexcept { return &data_[current_size]; } - const_iterator end() const noexcept { return &data_[current_size]; } + iterator end() noexcept { return data_.begin()+current_size; } + const_iterator end() const noexcept { return data_.begin()+current_size; } const_iterator cbegin() const noexcept { return data_.cbegin(); } - const_iterator cend() const noexcept { return &data_[current_size]; } + const_iterator cend() const noexcept { return data_.cbegin()+current_size; } void size_check(size_type s) const { if (s > Capacity) { diff --git a/slsSupportLib/tests/test-StaticVector.cpp b/slsSupportLib/tests/test-StaticVector.cpp index 6f9f5da50..2ff548fce 100644 --- a/slsSupportLib/tests/test-StaticVector.cpp +++ b/slsSupportLib/tests/test-StaticVector.cpp @@ -8,12 +8,15 @@ #include #include -namespace sls { + +using sls::StaticVector; TEST_CASE("StaticVector is a container") { - REQUIRE(is_container>::value == true); + REQUIRE(sls::is_container>::value == true); } + + TEST_CASE("Comparing StaticVector containers") { StaticVector a{0, 1, 2}; StaticVector b{0, 1, 2}; @@ -90,10 +93,17 @@ TEST_CASE("Copy construct from array") { REQUIRE(fcc == arr); } +TEST_CASE("Construct from a smaller StaticVector") { + StaticVector sv{1, 2, 3}; + StaticVector sv2{sv}; + REQUIRE(sv == sv2); +} + TEST_CASE("Free function and method gives the same iterators") { StaticVector fcc{1, 2, 3}; REQUIRE(std::begin(fcc) == fcc.begin()); } + SCENARIO("StaticVectors can be sized and resized", "[support]") { GIVEN("A default constructed container") { @@ -246,23 +256,23 @@ SCENARIO("Sorting, removing and other manipulation of a container", REQUIRE(a[3] == 90); } } - // WHEN("Sorting is done using free function for begin and end") { - // std::sort(begin(a), end(a)); - // THEN("it also works") { - // REQUIRE(a[0] == 12); - // REQUIRE(a[1] == 12); - // REQUIRE(a[2] == 14); - // REQUIRE(a[3] == 90); - // } - // } - // WHEN("Erasing elements of a certain value") { - // a.erase(std::remove(begin(a), end(a), 12)); - // THEN("all elements of that value are removed") { - // REQUIRE(a.size() == 2); - // REQUIRE(a[0] == 14); - // REQUIRE(a[1] == 90); - // } - // } + WHEN("Sorting is done using free function for begin and end") { + std::sort(std::begin(a), std::end(a)); + THEN("it also works") { + REQUIRE(a[0] == 12); + REQUIRE(a[1] == 12); + REQUIRE(a[2] == 14); + REQUIRE(a[3] == 90); + } + } + WHEN("Erasing elements of a certain value") { + a.erase(std::remove(std::begin(a), std::end(a), 12)); + THEN("all elements of that value are removed") { + REQUIRE(a.size() == 2); + REQUIRE(a[0] == 14); + REQUIRE(a[1] == 90); + } + } } } @@ -335,4 +345,3 @@ TEST_CASE("StaticVector stream") { REQUIRE(oss.str() == "[33, 85667, 2]"); } -} // namespace sls