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
This commit is contained in:
Codex instance
2026-07-30 16:43:29 +01:00
parent 0b65501c73
commit 912d59fdd9
3 changed files with 39 additions and 1 deletions
+36
View File
@@ -138,6 +138,16 @@ namespace {
};
}
auto renderable_result(std::uint64_t side,
std::vector<Placement> const &placements) -> Results {
std::vector<Square> 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<Placement> placements)
-> std::vector<Placement> {
@@ -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<std::uint64_t, 2>{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();
}