add tests for all 4 rules

This commit is contained in:
kai
2025-06-14 13:15:56 +02:00
parent 2b00def7af
commit 85a631d37b

View File

@@ -0,0 +1,48 @@
#include "test.h"
#include "common.h"
#include "game_of_life.h"
#include "matrix.h"
Matrix init_step(Matrix start) {
GameOfLife gol = GameOfLife(start, MPIGridSize());
gol.step();
return gol.getGrid();
}
TEST(test_underpopulation) {
Matrix start = Matrix::zeros(10);
start(0, 0) = 1;
Matrix end = init_step(start);
check(end(0, 0), 0);
}
TEST(test_survive) {
Matrix start = Matrix::zeros(10);
start(0, 0) = 1;
start(0, 1) = 1;
start(1, 0) = 1;
Matrix end = init_step(start);
check(end(0, 0), 1);
}
TEST(test_overpopulation) {
Matrix start = Matrix::zeros(10);
start(1, 1) = 1;
start(0, 1) = 1;
start(1, 0) = 1;
start(2, 1) = 1;
start(1, 2) = 1;
Matrix end = init_step(start);
check(end(1, 1), 0);
}
TEST(test_reproduction) {
Matrix start = Matrix::zeros(10);
start(0, 1) = 1;
start(1, 0) = 1;
start(2, 1) = 1;
Matrix end = init_step(start);
check(end(1, 1), 1);
}
int main() { return 0; }