Skip to content

Commit

Permalink
Add tests/grid-test.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzv committed Jul 20, 2018
1 parent 9a083cf commit 8b43c78
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ target_link_libraries (rexchange-test ${libraries})
add_executable (iexchange-test iexchange.cpp)
target_link_libraries (iexchange-test ${libraries})

add_executable (grid-test grid.cpp)
target_link_libraries (grid-test ${libraries})

foreach (b 2 4 8 64)
add_test (NAME kd-tree-test-b${b}
COMMAND kd-tree-test -b ${b}
Expand All @@ -57,6 +60,10 @@ add_test (NAME partners-test
COMMAND partners-test
)

add_test (NAME grid-test
COMMAND grid-test
)

if (mpi)
# currently, I/O is only supported when built with MPI support.
add_test (NAME io-test
Expand Down
27 changes: 27 additions & 0 deletions tests/grid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include <diy/grid.hpp>
#include <diy/vertices.hpp>

TEST_CASE("diy::for_each", "[grid]")
{
SECTION("iterate over 3D grid")
{
using Grid = diy::Grid<int,3>;
using Vertex = Grid::Vertex;

Vertex shape { 8, 9, 10 };
Grid g(shape);

int total = 0;
diy::for_each(g.shape(), [&g,&total](Vertex x)
{
g(x) = total++;
});

REQUIRE(total == shape[0] * shape[1] * shape[2]);
Vertex x { 3, 4, 5 };
REQUIRE(g(x) == x[2] + x[1] * shape[2] + x[0] * shape[2] * shape[1]); // C order
}
}

0 comments on commit 8b43c78

Please sign in to comment.