mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 04:47:14 +02:00
WIP
This commit is contained in:
@ -1,55 +1,81 @@
|
||||
#include "FixedCapacityContainer.h"
|
||||
#include "catch.hpp"
|
||||
#include "TypeTraits.h"
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
using sls::FixedCapacityContainer;
|
||||
|
||||
TEST_CASE("FixedCapacityContainer is a container"){
|
||||
REQUIRE(sls::is_container<FixedCapacityContainer<int,7>>::value == true);
|
||||
TEST_CASE("FixedCapacityContainer is a container") {
|
||||
REQUIRE(sls::is_container<FixedCapacityContainer<int, 7>>::value == true);
|
||||
}
|
||||
|
||||
TEST_CASE("Compare array and fixed capacity container") {
|
||||
std::array<int, 3> arr{1, 2, 3};
|
||||
std::array<int, 3> arr2{1, 7, 3};
|
||||
FixedCapacityContainer<int, 7> fcc{1, 2, 3};
|
||||
REQUIRE(fcc == arr);
|
||||
REQUIRE(arr == fcc);
|
||||
REQUIRE_FALSE(fcc != arr);
|
||||
REQUIRE_FALSE(arr != fcc);
|
||||
REQUIRE_FALSE(fcc == arr2);
|
||||
REQUIRE_FALSE(arr2 == fcc);
|
||||
}
|
||||
|
||||
TEST_CASE("Construct from vector"){
|
||||
std::vector<int> vec{1,2,3};
|
||||
TEST_CASE("Compare vector and fixed capacity container") {
|
||||
std::vector<int> vec{1, 2, 3};
|
||||
std::vector<int> vec2{10, 2, 3};
|
||||
FixedCapacityContainer<int, 7> fcc{1, 2, 3};
|
||||
REQUIRE(fcc == vec);
|
||||
REQUIRE(vec == fcc);
|
||||
REQUIRE_FALSE(fcc != vec);
|
||||
REQUIRE_FALSE(vec != fcc);
|
||||
REQUIRE_FALSE(fcc == vec2);
|
||||
REQUIRE_FALSE(vec2 == fcc);
|
||||
}
|
||||
|
||||
TEST_CASE("Construct from vector") {
|
||||
std::vector<int> vec{1, 2, 3};
|
||||
FixedCapacityContainer<int, 5> fcc{vec};
|
||||
REQUIRE(fcc == vec);
|
||||
}
|
||||
|
||||
TEST_CASE("Copy construct from vector"){
|
||||
std::vector<int> vec{1,2,3};
|
||||
TEST_CASE("Copy construct from vector") {
|
||||
std::vector<int> vec{1, 2, 3};
|
||||
FixedCapacityContainer<int, 5> fcc = vec;
|
||||
REQUIRE(fcc == vec);
|
||||
}
|
||||
|
||||
TEST_CASE("Copy assignment from vector"){
|
||||
std::vector<int> vec{1,2,3};
|
||||
TEST_CASE("Copy assignment from vector") {
|
||||
std::vector<int> vec{1, 2, 3};
|
||||
FixedCapacityContainer<int, 5> fcc;
|
||||
fcc = vec;
|
||||
REQUIRE(fcc == vec);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Construct from array"){
|
||||
std::array<int,3> arr{1,2,3};
|
||||
TEST_CASE("Construct from array") {
|
||||
std::array<int, 3> arr{1, 2, 3};
|
||||
FixedCapacityContainer<int, 5> fcc{arr};
|
||||
REQUIRE(fcc == arr);
|
||||
}
|
||||
|
||||
TEST_CASE("Copy assign from array"){
|
||||
std::array<int,3> arr{1,2,3};
|
||||
TEST_CASE("Copy assign from array") {
|
||||
std::array<int, 3> arr{1, 2, 3};
|
||||
FixedCapacityContainer<int, 5> fcc;
|
||||
fcc = arr;
|
||||
REQUIRE(fcc == arr);
|
||||
}
|
||||
|
||||
TEST_CASE("Copy construct from array"){
|
||||
std::array<int,3> arr{1,2,3};
|
||||
TEST_CASE("Copy construct from array") {
|
||||
std::array<int, 3> arr{1, 2, 3};
|
||||
FixedCapacityContainer<int, 5> fcc = arr;
|
||||
REQUIRE(fcc == arr);
|
||||
}
|
||||
|
||||
TEST_CASE("Free function and method gives the same iterators") {
|
||||
FixedCapacityContainer<int, 3> fcc{1, 2, 3};
|
||||
REQUIRE(std::begin(fcc) == fcc.begin());
|
||||
}
|
||||
SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") {
|
||||
|
||||
GIVEN("A default constructed container") {
|
||||
@ -57,7 +83,7 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") {
|
||||
FixedCapacityContainer<int, n_elem> vec;
|
||||
|
||||
REQUIRE(vec.empty());
|
||||
REQUIRE(vec.size() == 0); //NOLINT
|
||||
REQUIRE(vec.size() == 0); // NOLINT
|
||||
REQUIRE(vec.capacity() == n_elem);
|
||||
REQUIRE(sizeof(vec) == sizeof(int) * n_elem + sizeof(size_t));
|
||||
|
||||
@ -121,13 +147,12 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") {
|
||||
WHEN("We try to resize beyond the capacity") {
|
||||
THEN("it throws") { CHECK_THROWS(vec.resize(25)); }
|
||||
}
|
||||
WHEN("We call front and back"){
|
||||
THEN("They return referenced to the first and last element"){
|
||||
WHEN("We call front and back") {
|
||||
THEN("They return referenced to the first and last element") {
|
||||
REQUIRE(vec.front() == 23);
|
||||
REQUIRE(&vec.front() == &vec[0]);
|
||||
REQUIRE(vec.back() == 11);
|
||||
REQUIRE(&vec.back() == &vec[2]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,7 +215,8 @@ SCENARIO("Comparison of FixedCapacityContainers", "[support]") {
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("Sorting, removing and other manipulation of a container", "[support]") {
|
||||
SCENARIO("Sorting, removing and other manipulation of a container",
|
||||
"[support]") {
|
||||
GIVEN("An unsorted container") {
|
||||
FixedCapacityContainer<int, 5> a{14, 12, 90, 12};
|
||||
WHEN("We sort it") {
|
||||
@ -202,23 +228,23 @@ SCENARIO("Sorting, removing and other manipulation of a container", "[support]")
|
||||
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(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);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,30 +274,28 @@ SCENARIO("Assigning containers to each other", "[support]") {
|
||||
REQUIRE(c[2] == 3);
|
||||
}
|
||||
}
|
||||
WHEN("We create a const FixedCapacityContainer"){
|
||||
WHEN("We create a const FixedCapacityContainer") {
|
||||
const FixedCapacityContainer<int, 5> c(a);
|
||||
THEN("The values are still the same using const operators"){
|
||||
THEN("The values are still the same using const operators") {
|
||||
REQUIRE(c[0] == 1);
|
||||
REQUIRE(c[1] == 2);
|
||||
REQUIRE(c[2] == 3);
|
||||
REQUIRE(c.front() == 1);
|
||||
REQUIRE(c.back() == 3);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("Converting to vector", "[support]"){
|
||||
GIVEN("a FixedCapacityContainer"){
|
||||
FixedCapacityContainer<int, 5> a{1,2,3};
|
||||
WHEN("Converted into a vector"){
|
||||
SCENARIO("Converting to vector", "[support]") {
|
||||
GIVEN("a FixedCapacityContainer") {
|
||||
FixedCapacityContainer<int, 5> a{1, 2, 3};
|
||||
WHEN("Converted into a vector") {
|
||||
std::vector<int> b(a);
|
||||
THEN("Data and size matches"){
|
||||
THEN("Data and size matches") {
|
||||
REQUIRE(a == b);
|
||||
REQUIRE(a.size() == b.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user