summaryrefslogtreecommitdiff
path: root/test-solver.c
diff options
context:
space:
mode:
Diffstat (limited to 'test-solver.c')
-rw-r--r--test-solver.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/test-solver.c b/test-solver.c
new file mode 100644
index 0000000..4ea14a0
--- /dev/null
+++ b/test-solver.c
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "debug.h"
+#include "update.h"
+#include "cell.h"
+#include "solve.h"
+#include "display.h"
+#include "load.h"
+
+/* FIXME move to another TU */
+int boards_match(struct cell (*lb)[9][9], struct cell (*rb)[9][9])
+{
+ int x = 0;
+ int y = 0;
+
+ for (y = 0; y < 9; y++)
+ for (x = 0; x < 9; x++)
+ if ((*lb)[x][y].val != (*rb)[x][y].val)
+ return -1;
+
+ return 0;
+}
+
+/* FIXME move to another TU, dedup with solver.c */
+int solve(struct cell (*board)[9][9])
+{
+ int i = 0;
+ int total_changes = 0;
+ int change_count = -1;
+ /* 9*9 is worst case */
+ for (i = 0; i < 9*9 && change_count; i++) {
+ change_count = 0;
+ update_not_row_col(board);
+ change_count += not_to_val_cell(board);
+ change_count += solve_row_col(board);
+ change_count += cells_fill_certainties(board);
+ total_changes += change_count;
+ }
+ return total_changes;
+}
+
+int main(int argc, char **argv)
+{
+ struct cell working_board[9][9];
+ struct cell correct_board[9][9];
+ FILE *f = NULL;
+
+ memset(working_board, 0, sizeof(working_board));
+
+ if (!(f = fopen("./in.sku", "r"))) {
+ perror("fopen");
+ return 1;
+ }
+
+ if (load(f, &working_board) < 0) {
+ fclose(f);
+ return 1;
+ }
+
+ fclose(f);
+
+ solve(&working_board);
+
+ if (!(f = fopen("./expected.sku", "r"))) {
+ perror("fopen");
+ return 1;
+ }
+
+ if (load(f, &correct_board) < 0) {
+ fclose(f);
+ return 1;
+ }
+
+ fclose(f);
+
+ return boards_match(&working_board, &correct_board);
+}