Skip to content

Commit

Permalink
Check that Primitive doesn't exceed the dimensionality of the lattice
Browse files Browse the repository at this point in the history
  • Loading branch information
dean0x7d committed Jul 12, 2017
1 parent d1484ac commit 2ba0276
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cppcore/src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace cpb {

void Model::add(Primitive new_primitive) {
primitive = new_primitive;
for (auto i = lattice.ndim(); i < 3; ++i) {
if (primitive.size[i] != 1) {
throw std::logic_error("Primitive shape has more dimensions than the lattice");
}
}
clear_structure();
}

Expand Down
5 changes: 5 additions & 0 deletions cppcore/tests/test_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include "fixtures.hpp"
using namespace cpb;

TEST_CASE("Primitive") {
REQUIRE_THROWS_WITH(Model(lattice::square(), Primitive(2, 2, 2)),
Catch::Contains("more dimensions than the lattice"));
}

TEST_CASE("FreeformShape", "[shape]") {
auto const contains = [](CartesianArrayConstRef p) -> ArrayX<bool> { return p.x() > 0.5f; };
auto const shape = FreeformShape(contains, {1, 1, 1}, {0.5f, 0.5f, 0.5f});
Expand Down

0 comments on commit 2ba0276

Please sign in to comment.