solver: check completion before probing square #19
@@ -15,4 +15,5 @@ if(BUILD_TESTING)
|
||||
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)
|
||||
add_test(NAME solver-completion COMMAND partridge_tests solver-completion)
|
||||
endif()
|
||||
|
||||
@@ -297,10 +297,11 @@ namespace {
|
||||
sqs.push_back(sq);
|
||||
|
||||
pos = grid.next_pos(pos + idx);
|
||||
idx = grid.largest_square(pos, n);
|
||||
|
||||
// Have we reached the end? If so success!
|
||||
if (pos == grid.end()) { break; }
|
||||
|
||||
idx = grid.largest_square(pos, n);
|
||||
}
|
||||
|
||||
return {length, sqs};
|
||||
|
||||
@@ -280,6 +280,19 @@ namespace {
|
||||
"result adapter did not convert encoded placement coordinates");
|
||||
return failures;
|
||||
}
|
||||
|
||||
auto test_solver_completion() -> int {
|
||||
int failures = 0;
|
||||
for (auto const order: std::array<std::uint64_t, 2>{1, 8}) {
|
||||
auto const solution = find_solution(order);
|
||||
auto const validation = validate(order, solution);
|
||||
failures += expect(
|
||||
validation.valid(),
|
||||
"solver returned an invalid order-" + std::to_string(order) +
|
||||
" solution:\n" + validation.text());
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -301,6 +314,9 @@ int main(int argc, char **argv) {
|
||||
if (test == "solver-small") {
|
||||
return test_small_solver();
|
||||
}
|
||||
if (test == "solver-completion") {
|
||||
return test_solver_completion();
|
||||
}
|
||||
std::cerr << "unknown test: " << test << '\n';
|
||||
return 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user