103 lines
2.8 KiB
C++
103 lines
2.8 KiB
C++
#include <catch2/catch_all.hpp>
|
|
|
|
#include "Mask.h"
|
|
#include "Grid.h"
|
|
|
|
TEST_CASE("Mask is created with all cells enabled", "[Mask]") {
|
|
Mask mask(2, 2);
|
|
REQUIRE(mask(0, 0) == true);
|
|
REQUIRE(mask(0, 1) == true);
|
|
REQUIRE(mask(1, 0) == true);
|
|
REQUIRE(mask(1, 1) == true);
|
|
}
|
|
|
|
TEST_CASE("Test Mask cell enable/disable by coordinate", "[Mask]") {
|
|
Mask mask(2, 2);
|
|
mask.disable(0, 0);
|
|
REQUIRE(mask(0, 0) == false);
|
|
mask.enable(0,0);
|
|
REQUIRE(mask(0, 0) == true);
|
|
}
|
|
|
|
TEST_CASE("Test Mask cell enable/disable by Cell ref", "[Mask]") {
|
|
Grid grid(2, 2);
|
|
Mask mask(2, 2);
|
|
mask.disable(grid.getCellRef(0, 0));
|
|
REQUIRE(mask(0, 0) == false);
|
|
mask.enable(grid.getCellRef(0, 0));
|
|
REQUIRE(mask(0, 0) == true);
|
|
}
|
|
|
|
TEST_CASE("Mask count reflects number of enabled cells", "[Mask]") {
|
|
Mask mask(2, 2);
|
|
REQUIRE(mask.count() == 4);
|
|
mask.disable(0, 0);
|
|
REQUIRE(mask.count() == 3);
|
|
mask.disable(0, 1);
|
|
REQUIRE(mask.count() == 2);
|
|
mask.disable(1, 0);
|
|
REQUIRE(mask.count() == 1);
|
|
mask.disable(1, 1);
|
|
REQUIRE(mask.count() == 0);
|
|
}
|
|
|
|
TEST_CASE("Mask count reflects number of enabled cells with repetative enables", "[Mask]") {
|
|
Mask mask(2,2);
|
|
REQUIRE(mask.count() == 4);
|
|
mask.enable(0,0);
|
|
mask.enable(0,0);
|
|
REQUIRE(mask.count() == 4);
|
|
}
|
|
|
|
TEST_CASE("Mask count reflects number of enabled cells with repetative disables", "[Mask]") {
|
|
Mask mask(2,2);
|
|
REQUIRE(mask.count() == 4);
|
|
mask.disable(0,0);
|
|
mask.disable(0,0);
|
|
REQUIRE(mask.count() == 3);
|
|
}
|
|
|
|
TEST_CASE("Mask from file 2x2_on.txt", "[Mask]") {
|
|
Mask mask = Mask::fromFile("data/2x2_on.txt");
|
|
REQUIRE(mask(0, 0) == true);
|
|
REQUIRE(mask(0, 1) == true);
|
|
REQUIRE(mask(1, 0) == true);
|
|
REQUIRE(mask(1, 1) == true);
|
|
REQUIRE(mask.count() == 4);
|
|
}
|
|
|
|
TEST_CASE("Mask from file 2x2_off.txt", "[Mask]") {
|
|
Mask mask = Mask::fromFile("data/2x2_off.txt");
|
|
REQUIRE(mask(0, 0) == false);
|
|
REQUIRE(mask(0, 1) == false);
|
|
REQUIRE(mask(1, 0) == false);
|
|
REQUIRE(mask(1, 1) == false);
|
|
REQUIRE(mask.count() == 0);
|
|
}
|
|
|
|
TEST_CASE("Mask from file 3x3_half_on.txt", "[Mask]") {
|
|
Mask mask = Mask::fromFile("data/3x3_half_on.txt");
|
|
REQUIRE(mask(0, 0) == false);
|
|
REQUIRE(mask(0, 1) == true);
|
|
REQUIRE(mask(0, 2) == true);
|
|
REQUIRE(mask(1, 0) == false);
|
|
REQUIRE(mask(1, 1) == false);
|
|
REQUIRE(mask(1, 2) == true);
|
|
REQUIRE(mask(2, 0) == false);
|
|
REQUIRE(mask(2, 1) == false);
|
|
REQUIRE(mask(2, 2) == false);
|
|
REQUIRE(mask.count() == 3);
|
|
}
|
|
|
|
TEST_CASE("Mask from file with invalid char", "[Mask]") {
|
|
REQUIRE_THROWS(Mask::fromFile("data/mask_invalid_char.txt"));
|
|
}
|
|
|
|
TEST_CASE("Mask from file with mismatched line lengths", "[Mask]") {
|
|
REQUIRE_THROWS(Mask::fromFile("data/mask_mismatched_line_lengths.txt"));
|
|
}
|
|
|
|
TEST_CASE("Mask from more complex mask file", "[Mask]") {
|
|
Mask mask = Mask::fromFile("data/mask.txt");
|
|
REQUIRE(mask.size() == 76);
|
|
} |