added first grid test

This commit is contained in:
philippun 2023-08-03 22:33:55 +02:00
parent 4e043e712e
commit 8596f3ffda
4 changed files with 63 additions and 2 deletions

View File

@ -95,6 +95,13 @@ class Grid {
*/
int getDim();
/**
* @brief Gets length of 1D grid. Must be one dimensional grid.
*
* @return int Length of 1D grid.
*/
int getLength();
/**
* @brief Gets the number of rows of the grid.
*
@ -132,7 +139,7 @@ class Grid {
double getDeltaCol();
/**
* @brief Gets the delta value in y-direction.
* @brief Gets the delta value in y-direction. Must be two dimensional grid.
*
* @return double Delta value in y-direction.
*/

View File

@ -103,6 +103,14 @@ int Grid::getDim() {
return dim;
}
int Grid::getLength() {
if (dim != 1) {
throw_invalid_argument("Grid is not one dimensional, you should probably use getRow() or getCol()!");
}
return col;
}
int Grid::getRow() {
return row;
}
@ -142,5 +150,9 @@ double Grid::getDeltaCol() {
}
double Grid::getDeltaRow() {
if (dim != 2) {
throw_invalid_argument("Grid is not two dimensional, meaning there is no delta in y-direction!");
}
return this->deltaRow;
}

View File

@ -11,7 +11,7 @@ if(NOT DOCTEST_LIB)
FetchContent_MakeAvailable(DocTest)
endif()
add_executable(testTug setup.cpp testSimulation.cpp) # testBoundaryCondition.cpp testDiffusion.cpp
add_executable(testTug setup.cpp testSimulation.cpp testGrid.cpp) # testBoundaryCondition.cpp testDiffusion.cpp
target_link_libraries(testTug doctest tug)
# get relative path of the CSV file

42
test/testGrid.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <doctest/doctest.h>
#include <tug/Grid.hpp>
TEST_CASE("1D Grid") {
int l = 12;
Grid grid(l);
SUBCASE("correct construction") {
CHECK_EQ(grid.getDim(), 1);
CHECK_EQ(grid.getLength(), l);
CHECK_EQ(grid.getCol(), l);
CHECK_EQ(grid.getRow(), 1);
CHECK_EQ(grid.getConcentrations().rows(), 1);
CHECK_EQ(grid.getConcentrations().cols(), l);
CHECK_EQ(grid.getAlpha().rows(), 1);
CHECK_EQ(grid.getAlpha().cols(), l);
CHECK_EQ(grid.getDeltaCol(), 1);
CHECK_THROWS(grid.getAlphaX());
CHECK_THROWS(grid.getAlphaY());
CHECK_THROWS(grid.getDeltaRow());
}
SUBCASE("") {
}
}
TEST_CASE("2D Grid quadratic") {
int r = 12;
int c = 12;
// TODO
}
TEST_CASE("2D Grid non-quadratic") {
int r = 12;
int c = 15;
// TODO
}