succesfully migrated super_matrix
This commit is contained in:
@@ -21,10 +21,19 @@ private:
|
||||
Matrix grid_;
|
||||
};
|
||||
|
||||
inline SuperGrid::SuperGrid(const Matrix &other) : grid_(other) {}
|
||||
inline SuperGrid::SuperGrid(const Matrix &other)
|
||||
: grid_(
|
||||
Matrix::zeros(other.rows() + 2, other.cols() + 2)) // initialize grid_
|
||||
{
|
||||
for (int i = 0; i < other.rows(); i++) {
|
||||
for (int j = 0; j < other.cols(); j++) {
|
||||
grid_(i + 1, j + 1) = other(i, j); // copy into grid_ directly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline SuperGrid SuperGrid::zeros(int rows, int cols) {
|
||||
return SuperGrid(Matrix::zeros(rows + 2, cols + 2));
|
||||
return SuperGrid(Matrix::zeros(rows, cols));
|
||||
}
|
||||
|
||||
inline double &SuperGrid::operator()(int i, int j) {
|
||||
|
||||
@@ -2,35 +2,33 @@
|
||||
#include "common.h"
|
||||
#include "game_of_life.h"
|
||||
#include "matrix.h"
|
||||
#include "super_grid.h"
|
||||
#include "utils.h"
|
||||
|
||||
Matrix init_step(Matrix start) {
|
||||
Matrix init_step(SuperGrid start) {
|
||||
GameOfLife gol = GameOfLife(start, MPIGridSize());
|
||||
gol.step();
|
||||
return gol.getGrid();
|
||||
}
|
||||
|
||||
TEST(test_underpopulation) {
|
||||
Matrix start = Matrix::zeros(10);
|
||||
SuperGrid start = SuperGrid::zeros(10, 10);
|
||||
start(0, 0) = 1;
|
||||
Matrix end = init_step(start);
|
||||
check(end(0, 0), 0);
|
||||
}
|
||||
|
||||
TEST(test_survive_2) {
|
||||
Matrix start = Matrix::zeros(10);
|
||||
SuperGrid start = SuperGrid::zeros(10, 10);
|
||||
start(0, 0) = 1;
|
||||
start(0, 1) = 1;
|
||||
start(1, 0) = 1;
|
||||
|
||||
print(start);
|
||||
Matrix end = init_step(start);
|
||||
print(end);
|
||||
check(end(0, 0), 1);
|
||||
}
|
||||
|
||||
TEST(test_survive_3) {
|
||||
Matrix start = Matrix::zeros(10);
|
||||
SuperGrid start = SuperGrid::zeros(10, 10);
|
||||
start(0, 0) = 1;
|
||||
start(1, 1) = 1;
|
||||
start(0, 1) = 1;
|
||||
@@ -40,7 +38,7 @@ TEST(test_survive_3) {
|
||||
}
|
||||
|
||||
TEST(test_overpopulation) {
|
||||
Matrix start = Matrix::zeros(10);
|
||||
SuperGrid start = SuperGrid::zeros(10, 10);
|
||||
start(1, 1) = 1;
|
||||
start(0, 1) = 1;
|
||||
start(1, 0) = 1;
|
||||
@@ -51,7 +49,7 @@ TEST(test_overpopulation) {
|
||||
}
|
||||
|
||||
TEST(test_reproduction) {
|
||||
Matrix start = Matrix::zeros(10);
|
||||
SuperGrid start = SuperGrid::zeros(10, 10);
|
||||
start(0, 1) = 1;
|
||||
start(1, 0) = 1;
|
||||
start(2, 1) = 1;
|
||||
@@ -60,7 +58,7 @@ TEST(test_reproduction) {
|
||||
}
|
||||
|
||||
TEST(test_survive_edge) {
|
||||
Matrix start = Matrix::zeros(10);
|
||||
SuperGrid start = SuperGrid::zeros(10, 10);
|
||||
start(0, 0) = 1;
|
||||
start(9, 0) = 1;
|
||||
start(0, 9) = 1;
|
||||
@@ -68,4 +66,10 @@ TEST(test_survive_edge) {
|
||||
check(end(0, 0), 1);
|
||||
}
|
||||
|
||||
TEST(test_super_grid) {
|
||||
SuperGrid su_grid = SuperGrid::zeros(10, 10);
|
||||
check(su_grid.rows(), 10);
|
||||
check(su_grid.cols(), 10);
|
||||
}
|
||||
|
||||
int main() { return 0; }
|
||||
|
||||
@@ -90,3 +90,12 @@ void print(Matrix &grid) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void print(const Matrix &grid) {
|
||||
for (int i = 0; i < grid.rows(); ++i) {
|
||||
for (int j = 0; j < grid.cols(); ++j) {
|
||||
std::cout << ((grid(i, j) == 1) ? "X " : ". ");
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,6 @@ void storeAnimation(const std::string &foldername, const Matrix &initstate,
|
||||
void print(const GameOfLife &game);
|
||||
|
||||
void print(Matrix &matrix);
|
||||
void print(const Matrix &matrix);
|
||||
|
||||
#endif // UTILS_H
|
||||
|
||||
Reference in New Issue
Block a user