mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-22 10:41:33 +02:00
Merge pull request #1214 from slsdetectorgroup/dev/fixStaticVector
dev: rewrote end() for StaticVector
This commit is contained in:
commit
90d57cb6a9
@ -113,10 +113,10 @@ template <typename T, size_t Capacity> 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) {
|
||||
|
@ -8,12 +8,15 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace sls {
|
||||
|
||||
using sls::StaticVector;
|
||||
|
||||
TEST_CASE("StaticVector is a container") {
|
||||
REQUIRE(is_container<StaticVector<int, 7>>::value == true);
|
||||
REQUIRE(sls::is_container<StaticVector<int, 7>>::value == true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("Comparing StaticVector containers") {
|
||||
StaticVector<int, 5> a{0, 1, 2};
|
||||
StaticVector<int, 5> 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<int, 3> sv{1, 2, 3};
|
||||
StaticVector<int, 5> sv2{sv};
|
||||
REQUIRE(sv == sv2);
|
||||
}
|
||||
|
||||
TEST_CASE("Free function and method gives the same iterators") {
|
||||
StaticVector<int, 3> 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user