diff --git a/include/plsm/Subpaving.inl b/include/plsm/Subpaving.inl index 614c720..67cad95 100644 --- a/include/plsm/Subpaving.inl +++ b/include/plsm/Subpaving.inl @@ -85,7 +85,9 @@ Subpaving::processSubdivisionRatios( auto getNextFactor = [nonSelfFactors](auto toSub, auto refFactor) { using T = std::remove_reference_t; if (toSub % refFactor == 0) { - return refFactor; + if (refFactor != 1) { + return refFactor; + } } auto opt = nonSelfFactors(static_cast(toSub)); if (opt.empty()) { diff --git a/test/unittest_Subpaving.cpp b/test/unittest_Subpaving.cpp index 98311af..5c283d4 100644 --- a/test/unittest_Subpaving.cpp +++ b/test/unittest_Subpaving.cpp @@ -17,11 +17,24 @@ struct SubpavingTester { using Ratio = SubdivisionRatio; - void + bool checkRatios(const std::vector& ratios) { + bool ret = true; auto infos = subpaving.makeMirrorCopy()._subdivisionInfos; - REQUIRE(infos.size() == ratios.size()); +#define EXPR infos.size() == ratios.size() + CHECK(EXPR); + if (!(EXPR)) { + return false; + } +#undef EXPR + for (std::size_t i = 0; i < infos.size(); ++i) { +#define EXPR infos[i].getRatio() == ratios[i] + ret = ret && EXPR; + CHECK(EXPR); +#undef EXPR + } + return ret; } TSubpaving subpaving; @@ -38,28 +51,63 @@ makeSubpavingTester(const TSubpaving& subpaving) TEMPLATE_LIST_TEST_CASE( "Process Subdivision Ratios", "[Subpaving][template]", test::IntTypes) { - auto subpaving = Subpaving({{{0, 100}, {0, 100}}}, {{{5, 5}}}); - test::makeSubpavingTester(subpaving).checkRatios( - {{{5, 5}, {5, 5}, {2, 2}, {2, 2}}}); - - subpaving = Subpaving({{{0, 250}, {0, 50}}}, {{{5, 5}}}); - test::makeSubpavingTester(subpaving).checkRatios( - {{{5, 5}, {5, 5}, {5, 2}, {2, 2}}}); - - subpaving = Subpaving({{{10, 20}, {25, 35}}}, {{{5, 5}}}); - test::makeSubpavingTester(subpaving).checkRatios({{{5, 5}, {2, 2}}}); - - subpaving = Subpaving({{{0, 300}, {0, 275}}}, {{{5, 5}}}); - test::makeSubpavingTester(subpaving).checkRatios( - {{{5, 5}, {5, 5}, {4, 11}, {3, 1}}}); - - subpaving = Subpaving({{{0, 2116}, {0, 1155}}}, {{{23, 11}}}); - test::makeSubpavingTester(subpaving).checkRatios( - {{{23, 11}, {23, 7}, {2, 5}, {2, 3}}}); - - subpaving = Subpaving({{{0, 2116}, {0, 1155}}}, {{{2, 3}}}); - test::makeSubpavingTester(subpaving).checkRatios( - {{{2, 3}, {2, 5}, {23, 7}, {23, 11}}}); + Subpaving subpaving; + + REQUIRE_NOTHROW( + subpaving = Subpaving({{{0, 100}, {0, 100}}}, {{{5, 5}}})); + REQUIRE(test::makeSubpavingTester(subpaving).checkRatios( + {{{5, 5}, {5, 5}, {2, 2}, {2, 2}}})); + + REQUIRE_NOTHROW( + subpaving = Subpaving({{{0, 250}, {0, 50}}}, {{{5, 5}}})); + REQUIRE(test::makeSubpavingTester(subpaving).checkRatios( + {{{5, 5}, {5, 5}, {5, 2}, {2, 1}}})); + + REQUIRE_NOTHROW( + subpaving = Subpaving({{{10, 20}, {25, 35}}}, {{{5, 5}}})); + REQUIRE( + test::makeSubpavingTester(subpaving).checkRatios({{{5, 5}, {2, 2}}})); + + REQUIRE_NOTHROW( + subpaving = Subpaving({{{0, 300}, {0, 275}}}, {{{5, 5}}})); + REQUIRE(test::makeSubpavingTester(subpaving).checkRatios( + {{{5, 5}, {5, 5}, {4, 11}, {3, 1}}})); + + REQUIRE_NOTHROW(subpaving = Subpaving( + {{{0, 2116}, {0, 1155}}}, {{{23, 11}}})); + REQUIRE(test::makeSubpavingTester(subpaving).checkRatios( + {{{23, 11}, {23, 7}, {2, 5}, {2, 3}}})); + + REQUIRE_NOTHROW(subpaving = Subpaving( + {{{0, 2116}, {0, 1155}}}, {{{2, 3}}})); + REQUIRE(test::makeSubpavingTester(subpaving).checkRatios( + {{{2, 3}, {2, 5}, {23, 7}, {23, 11}}})); + + // Based on xolotl cases + Subpaving sp; + REQUIRE_NOTHROW( + sp = Subpaving({{{0, 256}, {0, 256}, {0, 128}, {0, 128}}}, + {{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, + {1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}})); + REQUIRE(test::makeSubpavingTester(sp).checkRatios( + {{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {1, 1, 2, 2}, + {1, 1, 2, 2}, {1, 1, 1, 2}, {1, 1, 2, 1}}})); + + REQUIRE_NOTHROW( + sp = Subpaving({{{0, 256}, {0, 256}, {0, 128}, {0, 128}}}, + {{{1, 1, 2, 1}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, + {4, 4, 2, 2}, {1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}})); + REQUIRE(test::makeSubpavingTester(sp).checkRatios( + {{{1, 1, 2, 1}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, + {1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}})); + + REQUIRE_NOTHROW( + sp = Subpaving({{{0, 256}, {0, 256}, {0, 64}, {0, 128}}}, + {{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, + {1, 1, 2, 2}, {1, 1, 2, 2}, {1, 1, 1, 2}}})); + REQUIRE(test::makeSubpavingTester(sp).checkRatios( + {{{4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {4, 4, 2, 2}, {1, 1, 2, 2}, + {1, 1, 2, 2}, {1, 1, 1, 2}}})); } TEMPLATE_LIST_TEST_CASE(