Add object counter to UnitTests

The counter allows for checking if each object in the array is accessed
once.
This commit is contained in:
Stephen Seo 2021-06-09 14:43:55 +09:00
parent ca19346ea7
commit c18c5dc56a

View file

@ -7,6 +7,7 @@ struct Indices {
unsigned long long y; unsigned long long y;
unsigned long long z; unsigned long long z;
unsigned long long i; unsigned long long i;
unsigned long long counter;
}; };
TEST_CASE("two_to_one", "n_to_one") { TEST_CASE("two_to_one", "n_to_one") {
@ -155,6 +156,7 @@ TEST_CASE("n=2 objects long", "n_to_one") {
one_to_two(idx, &x, &y, 5); one_to_two(idx, &x, &y, 5);
indices[idx].x = x; indices[idx].x = x;
indices[idx].y = y; indices[idx].y = y;
indices[idx].counter = 0;
} }
for(y = 0; y < 4; ++y) { for(y = 0; y < 4; ++y) {
@ -163,8 +165,13 @@ TEST_CASE("n=2 objects long", "n_to_one") {
REQUIRE(idx < 5*4); REQUIRE(idx < 5*4);
CHECK(indices[idx].x == x); CHECK(indices[idx].x == x);
CHECK(indices[idx].y == y); CHECK(indices[idx].y == y);
++indices[idx].counter;
} }
} }
for(idx = 0; idx < 5*4; ++idx) {
CHECK(indices[idx].counter == 1);
}
} }
TEST_CASE("n=3 objects long", "n_to_one") { TEST_CASE("n=3 objects long", "n_to_one") {
@ -179,6 +186,7 @@ TEST_CASE("n=3 objects long", "n_to_one") {
indices[idx].x = x; indices[idx].x = x;
indices[idx].y = y; indices[idx].y = y;
indices[idx].z = z; indices[idx].z = z;
indices[idx].counter = 0;
} }
for(z = 0; z < 3; ++z) { for(z = 0; z < 3; ++z) {
@ -189,9 +197,14 @@ TEST_CASE("n=3 objects long", "n_to_one") {
CHECK(indices[idx].x == x); CHECK(indices[idx].x == x);
CHECK(indices[idx].y == y); CHECK(indices[idx].y == y);
CHECK(indices[idx].z == z); CHECK(indices[idx].z == z);
++indices[idx].counter;
} }
} }
} }
for(idx = 0; idx < 5*4*3; ++idx) {
CHECK(indices[idx].counter == 1);
}
} }
TEST_CASE("n=4 objects long", "n_to_one") { TEST_CASE("n=4 objects long", "n_to_one") {
@ -208,6 +221,7 @@ TEST_CASE("n=4 objects long", "n_to_one") {
indices[idx].y = y; indices[idx].y = y;
indices[idx].z = z; indices[idx].z = z;
indices[idx].i = i; indices[idx].i = i;
indices[idx].counter = 0;
} }
for(i = 0; i < 2; ++i) { for(i = 0; i < 2; ++i) {
@ -220,10 +234,15 @@ TEST_CASE("n=4 objects long", "n_to_one") {
CHECK(indices[idx].y == y); CHECK(indices[idx].y == y);
CHECK(indices[idx].z == z); CHECK(indices[idx].z == z);
CHECK(indices[idx].i == i); CHECK(indices[idx].i == i);
++indices[idx].counter;
} }
} }
} }
} }
for(idx = 0; idx < 5*4*3*2; ++idx) {
CHECK(indices[idx].counter == 1);
}
} }
TEST_CASE("two_to_one_l", "n_to_one") { TEST_CASE("two_to_one_l", "n_to_one") {
@ -372,6 +391,7 @@ TEST_CASE("n=2 objects long long", "n_to_one") {
one_to_two_l(idx, &x, &y, 5); one_to_two_l(idx, &x, &y, 5);
indices[idx].x = x; indices[idx].x = x;
indices[idx].y = y; indices[idx].y = y;
indices[idx].counter = 0;
} }
for(y = 0; y < 4; ++y) { for(y = 0; y < 4; ++y) {
@ -380,8 +400,13 @@ TEST_CASE("n=2 objects long long", "n_to_one") {
REQUIRE(idx < 5*4); REQUIRE(idx < 5*4);
CHECK(indices[idx].x == x); CHECK(indices[idx].x == x);
CHECK(indices[idx].y == y); CHECK(indices[idx].y == y);
++indices[idx].counter;
} }
} }
for(idx = 0; idx < 5*4; ++idx) {
CHECK(indices[idx].counter == 1);
}
} }
TEST_CASE("n=3 objects long long", "n_to_one") { TEST_CASE("n=3 objects long long", "n_to_one") {
@ -396,6 +421,7 @@ TEST_CASE("n=3 objects long long", "n_to_one") {
indices[idx].x = x; indices[idx].x = x;
indices[idx].y = y; indices[idx].y = y;
indices[idx].z = z; indices[idx].z = z;
indices[idx].counter = 0;
} }
for(z = 0; z < 3; ++z) { for(z = 0; z < 3; ++z) {
@ -406,9 +432,14 @@ TEST_CASE("n=3 objects long long", "n_to_one") {
CHECK(indices[idx].x == x); CHECK(indices[idx].x == x);
CHECK(indices[idx].y == y); CHECK(indices[idx].y == y);
CHECK(indices[idx].z == z); CHECK(indices[idx].z == z);
++indices[idx].counter;
} }
} }
} }
for(idx = 0; idx < 5*4*3; ++idx) {
CHECK(indices[idx].counter == 1);
}
} }
TEST_CASE("n=4 objects long long", "n_to_one") { TEST_CASE("n=4 objects long long", "n_to_one") {
@ -425,6 +456,7 @@ TEST_CASE("n=4 objects long long", "n_to_one") {
indices[idx].y = y; indices[idx].y = y;
indices[idx].z = z; indices[idx].z = z;
indices[idx].i = i; indices[idx].i = i;
indices[idx].counter = 0;
} }
for(i = 0; i < 2; ++i) { for(i = 0; i < 2; ++i) {
@ -437,8 +469,13 @@ TEST_CASE("n=4 objects long long", "n_to_one") {
CHECK(indices[idx].y == y); CHECK(indices[idx].y == y);
CHECK(indices[idx].z == z); CHECK(indices[idx].z == z);
CHECK(indices[idx].i == i); CHECK(indices[idx].i == i);
++indices[idx].counter;
} }
} }
} }
} }
for(idx = 0; idx < 5*4*3*2; ++idx) {
CHECK(indices[idx].counter == 1);
}
} }