Skip to content
Snippets Groups Projects
Commit db531ee3 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add unit test for Array

parent 1e823da3
No related branches found
No related tags found
1 merge request!7Feature/itemvalue
...@@ -4,6 +4,7 @@ set(EXECUTABLE_OUTPUT_PATH ${PASTIS_BINARY_DIR}) ...@@ -4,6 +4,7 @@ set(EXECUTABLE_OUTPUT_PATH ${PASTIS_BINARY_DIR})
add_executable (unit_tests add_executable (unit_tests
test_main.cpp test_main.cpp
test_Array.cpp
test_ItemType.cpp test_ItemType.cpp
test_PastisAssert.cpp test_PastisAssert.cpp
test_RevisionInfo.cpp test_RevisionInfo.cpp
......
#include <catch.hpp>
#include <PastisAssert.hpp>
#include <Array.hpp>
#include <Types.hpp>
// Instantiate to ensure full coverage is performed
template class Array<int>;
TEST_CASE("Array", "[utils]") {
Array<int> a(10);
REQUIRE(a.size() == 10);
for (size_t i=0; i<a.size(); ++i) {
a[i] = 2*i;
}
REQUIRE(((a[0] == 0) and (a[1] == 2) and
(a[2] == 4) and (a[3] == 6) and
(a[4] == 8) and (a[5] ==10) and
(a[6] ==12) and (a[7] ==14) and
(a[8] ==16) and (a[9] ==18)));
SECTION("checking for copies") {
Array<const int> b{a};
REQUIRE(((b[0] == 0) and (b[1] == 2) and
(b[2] == 4) and (b[3] == 6) and
(b[4] == 8) and (b[5] ==10) and
(b[6] ==12) and (b[7] ==14) and
(b[8] ==16) and (b[9] ==18)));
Array<int> c{a};
REQUIRE(((c[0] == 0) and (c[1] == 2) and
(c[2] == 4) and (c[3] == 6) and
(c[4] == 8) and (c[5] ==10) and
(c[6] ==12) and (c[7] ==14) and
(c[8] ==16) and (c[9] ==18)));
Array<int> d = std::move(c);
REQUIRE(((d[0] == 0) and (d[1] == 2) and
(d[2] == 4) and (d[3] == 6) and
(d[4] == 8) and (d[5] ==10) and
(d[6] ==12) and (d[7] ==14) and
(d[8] ==16) and (d[9] ==18)));
}
SECTION("checking for affectations") {
Array<const int> b;
b = a;
REQUIRE(((b[0] == 0) and (b[1] == 2) and
(b[2] == 4) and (b[3] == 6) and
(b[4] == 8) and (b[5] ==10) and
(b[6] ==12) and (b[7] ==14) and
(b[8] ==16) and (b[9] ==18)));
Array<int> c;
c = a;
REQUIRE(((c[0] == 0) and (c[1] == 2) and
(c[2] == 4) and (c[3] == 6) and
(c[4] == 8) and (c[5] ==10) and
(c[6] ==12) and (c[7] ==14) and
(c[8] ==16) and (c[9] ==18)));
Array<int> d;
d = std::move(c);
REQUIRE(((d[0] == 0) and (d[1] == 2) and
(d[2] == 4) and (d[3] == 6) and
(d[4] == 8) and (d[5] ==10) and
(d[6] ==12) and (d[7] ==14) and
(d[8] ==16) and (d[9] ==18)));
}
#ifndef NDEBUG
SECTION("checking for bounds violation") {
REQUIRE_THROWS_AS(a[10], AssertError);
}
#endif // NDEBUG
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment