add tests for Simulation class

This commit is contained in:
Hannes Signer 2023-08-06 19:24:17 +02:00
parent aa4ce6a086
commit 30bc676604
2 changed files with 39 additions and 1 deletions

View File

@ -123,7 +123,7 @@ class Simulation {
* @brief Creates a CSV file with a name containing the current simulation
* parameters. If the data name already exists, an additional counter is
* appended to the name. The name of the file is built up as follows:
* <approach> + <number rows> + <number columns> + <number of iterations>-<counter>.csv
* <approach> + <number rows> + <number columns> + <number of iterations>+<counter>.csv
*
* @return string Filename with given simulation parameter.
*/

View File

@ -63,3 +63,41 @@ TEST_CASE("equality to reference matrix") {
Grid grid = setupSimulation();
CHECK(checkSimilarity(reference, grid.getConcentrations(), 0.1) == true);
}
TEST_CASE("Initialize environment"){
int rc = 12;
Grid grid(rc, rc);
Boundary boundary(grid);
CHECK_NOTHROW(Simulation sim(grid, boundary, FTCS_APPROACH));
}
TEST_CASE("Simulation environment"){
int rc = 12;
Grid grid(rc, rc);
Boundary boundary(grid);
Simulation sim(grid, boundary, FTCS_APPROACH);
SUBCASE("default paremeters"){
CHECK_EQ(sim.getIterations(), 1000);
}
SUBCASE("set iterations"){
CHECK_NOTHROW(sim.setIterations(2000));
CHECK_EQ(sim.getIterations(), 2000);
CHECK_THROWS(sim.setIterations(-300));
}
SUBCASE("set timestep"){
CHECK_NOTHROW(sim.setTimestep(0.1));
CHECK_EQ(sim.getTimestep(), 0.1);
CHECK_THROWS(sim.setTimestep(-0.3));
}
SUBCASE("filename"){
string s1 = sim.createCSVfile();
string s2 = "FTCS_12_12_1000";
CHECK_EQ(s1.find(s2) != std::string::npos, true);
}
}