From 912d59fdd9ddcef0fba28131fb69c643d6a717cb Mon Sep 17 00:00:00 2001 From: Codex instance Date: Thu, 30 Jul 2026 16:42:51 +0100 Subject: [PATCH 1/2] test: cover rendering a valid solution Exercise Results::output() with the known order-8 fixture so Debug builds compile and run the rendering assertions. Check the output dimensions and ensure the valid tiling leaves no unrendered cells. The test passes in Release and currently fails to compile in Debug because Results::set() refers to the nonexistent grid_ member. Refs: #7 --- CMakeLists.txt | 1 + TESTING.md | 3 ++- tests/tests.cc | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe680ec..56c52d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,5 +13,6 @@ if(BUILD_TESTING) tests/tests.cc) add_test(NAME validator COMMAND partridge_tests validator) add_test(NAME construction COMMAND partridge_tests construction) + add_test(NAME rendering COMMAND partridge_tests rendering) add_test(NAME solver-small COMMAND partridge_tests solver-small) endif() diff --git a/TESTING.md b/TESTING.md index 7a1ccef..997bd28 100644 --- a/TESTING.md +++ b/TESTING.md @@ -12,7 +12,8 @@ ctest --test-dir build --output-on-failure The tests independently check board dimensions, square multiplicities, bounds, overlap, and complete coverage. They cover small unsatisfiable solver inputs, a known order-8 solution, invalid placement diagnostics, and construction of an -order-9 solution from the order-8 fixture. +order-9 solution from the order-8 fixture. The rendering test also formats the +known order-8 solution and checks the resulting grid dimensions and coverage. ## Debug and sanitizers diff --git a/tests/tests.cc b/tests/tests.cc index e683d3b..e022ecc 100644 --- a/tests/tests.cc +++ b/tests/tests.cc @@ -138,6 +138,16 @@ namespace { }; } + auto renderable_result(std::uint64_t side, + std::vector const &placements) -> Results { + std::vector squares; + squares.reserve(placements.size()); + for (auto const &placement: placements) { + squares.emplace_back(placement.x + placement.y * side, placement.side); + } + return Results(side, std::move(squares)); + } + auto construct_next_odd(std::uint64_t even_order, std::vector placements) -> std::vector { @@ -221,6 +231,29 @@ namespace { "even-to-odd construction was rejected:\n" + validation.text()); } + auto test_rendering() -> int { + auto const result = renderable_result(36, known_order_8()); + std::ostringstream rendered; + auto *const original_buffer = std::cout.rdbuf(rendered.rdbuf()); + result.output(); + std::cout.rdbuf(original_buffer); + + int failures = 0; + std::istringstream lines(rendered.str()); + std::string line; + std::uint64_t line_count = 0; + while (std::getline(lines, line)) { + ++line_count; + failures += expect(line.size() == result.length(), + "rendered row has incorrect width"); + failures += expect(line.find('.') == std::string::npos, + "valid solution left an unrendered cell"); + } + failures += expect(line_count == result.length(), + "rendered output has incorrect height"); + return failures; + } + auto test_small_solver() -> int { int failures = 0; for (auto const order: std::array{2, 3}) { @@ -262,6 +295,9 @@ int main(int argc, char **argv) { if (test == "construction") { return test_construction(); } + if (test == "rendering") { + return test_rendering(); + } if (test == "solver-small") { return test_small_solver(); } -- 2.54.0 From ebfc80546a4ebb31a7c0190eb3ef12e8fe06ac2e Mon Sep 17 00:00:00 2001 From: Codex instance Date: Thu, 30 Jul 2026 16:43:50 +0100 Subject: [PATCH 2/2] results: fix Debug rendering assertion Check the character in the output string instead of referring to a nonexistent grid_ member. This restores Debug compilation while preserving the intended invariant that rendering must not write an identical character twice. Size labels intentionally replace interior spaces, so requiring an entirely unwritten destination would reject valid solutions. Update the testing notes now that Debug builds pass. Tests: Debug and Release CTest suites (4 passed each) Refs: #7 --- TESTING.md | 6 +++--- main.cc | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TESTING.md b/TESTING.md index 997bd28..2f5bc97 100644 --- a/TESTING.md +++ b/TESTING.md @@ -38,6 +38,6 @@ ctest --test-dir build-ubsan --output-on-failure ``` The sanitizer flags shown are supported by Clang and GCC. Other compilers may -require different flags. Debug compilation and a feasible solver run currently -expose the pre-existing defects tracked by issues #7 and #14 respectively; the -test additions deliberately do not include fixes for those separate issues. +require different flags. A feasible solver run currently exposes the +pre-existing defect tracked by issue #14; the test additions deliberately do +not include its separate fix. diff --git a/main.cc b/main.cc index ee2c9bd..c71cae1 100644 --- a/main.cc +++ b/main.cc @@ -85,7 +85,8 @@ namespace { auto set(std::string &s, size_t x, size_t y, char c) const noexcept -> void { assert(x < length_); assert(y < length_); - assert(grid_[x + y * length_] != c); + // Size labels may replace interior spaces, but must not duplicate a write. + assert(s[x + y * length_] != c); s[x + y * length_] = c; } -- 2.54.0