Skip to content

Commit

Permalink
added blackbox tests formedium difficulty boards
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGAzed committed Jun 16, 2024
1 parent f9442b4 commit 7a46681
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 11 deletions.
6 changes: 2 additions & 4 deletions program/include/structures/abstract/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ typedef struct queue_list_array {
#endif /* FINITE_QUEUE */

typedef struct queue {
size_t size;
size_t current;
size_t size, current;

#ifdef FINITE_QUEUE
size_t max;
QUEUE_DATA_TYPE * elements;
#else
QLArray * head;
QLArray * tail;
QLArray * head, tail;
#endif /* FINITE_QUEUE */

} Queue;
Expand Down
10 changes: 3 additions & 7 deletions program/include/structures/concrete/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ typedef enum kakuro_grid_sizes { ROW = 0, COLUMN = 1, } KGSizes;
typedef struct kakuro_grid {
lookup_t **grids[GRID_DIMENTIONS];

ksize_t size[GRID_DIMENTIONS];
ksize_t count;
ksize_t empty_count;
ksize_t size[GRID_DIMENTIONS], count, empty_count;
} KGrid;

#define U_LOOKUP_COUNT 3
Expand All @@ -36,10 +34,8 @@ typedef struct kakuro {
} Kakuro;

typedef enum check {
UNCHECKED = 0,
ROWCHECK = 1,
COLCHECK = 2,
CHEKCED = 3,
UNCHECKED = 0, ROWCHECK = 1,
COLCHECK = 2, CHEKCED = 3,
} Check;

Kakuro init_kakuro(FILE * kakuro_file);
Expand Down
3 changes: 3 additions & 0 deletions test/blackbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ target_sources(BLACK_BOX_LIB
suites/easy/easy_arc_consistency_forward_check.c
suites/easy/easy_arc_consistency_backtrack.c
suites/easy/easy_arc_consistency_backtrack_forward_check.c

suites/medium/medium_backtrack_forward_check.c
suites/medium/medium_arc_consistency_backtrack_forward_check.c
)

target_include_directories(BLACK_BOX_LIB
Expand Down
6 changes: 6 additions & 0 deletions test/blackbox/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ extern SUITE(easy_arc_consistency_forward_check);
extern SUITE(easy_arc_consistency_backtrack);
extern SUITE(easy_arc_consistency_backtrack_forward_check);

extern SUITE(medium_backtrack_forward_check);
extern SUITE(medium_arc_consistency_backtrack_forward_check);

GREATEST_MAIN_DEFS();

int main(int argc, char **argv) {
Expand All @@ -23,6 +26,9 @@ int main(int argc, char **argv) {
RUN_SUITE(easy_arc_consistency_backtrack);
RUN_SUITE(easy_arc_consistency_backtrack_forward_check);

RUN_SUITE(medium_backtrack_forward_check);
RUN_SUITE(medium_arc_consistency_backtrack_forward_check);

GREATEST_MAIN_END();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#include <greatest.h>

#include <instance/settings.h>
#include <algorithms/depth_first_search.h>

#define MEDIUM_PUZZLE_PATH "./test/puzzles/medium/"

TEST medium_arc_consistency_backtrack_forward_check_one(void) {
ksize_t expected_solution[] = {
7, 9, 3, 1, 8, 9, 8, 6,
2, 5, 1, 2, 4, 3, 8, 7, 9, 5,
3, 7, 9, 3, 7, 8, 1, 9, 5, 1,
1, 8, 4, 3, 5, 9, 7, 8, 7, 3,
5, 1, 1, 2,
4, 8, 7, 3, 1, 4, 7, 9, 8, 2,
7, 9, 4, 9, 7, 6, 8, 1, 6, 3,
1, 6, 8, 2, 7, 7, 9, 8, 3, 1,
2, 1, 4, 1, 2, 4, 9, 7,
};

get_settings_singleton()->filepath = MEDIUM_PUZZLE_PATH"1.kkr";
get_settings_singleton()->is_arc_consistency = true;
get_settings_singleton()->is_backtrack = true;
get_settings_singleton()->is_forward_check = true;

FILE * fp = fopen(get_settings_singleton()->filepath, "rb");
ASSERTm("COULDN'T OPEN FILE", fp);

Kakuro board = init_kakuro(fp);
fclose(fp);

SArray solution = depth_first_search(board);
free_kakuro(&board);

ASSERTm("NO SOLUTION FOUND", solution.size);
ASSERTm("LENGTHS DON'T ADD UP", solution.size == (sizeof(expected_solution) / sizeof(ksize_t)));

for (ksize_t i = 0; i < solution.size; i++) {
ASSERTm("INVALID SOLUTION", get_one_value(solution.elements[i]) == expected_solution[i]);
}

destroy_state_array(&solution);

PASS();
}

TEST medium_arc_consistency_backtrack_forward_check_two(void) {
ksize_t expected_solution[] = {
9, 8, 4, 3, 6, 8, 3, 9,
7, 4, 2, 1, 9, 2, 3, 1, 5,
9, 7, 7, 2, 8, 4, 1,
2, 8, 3, 1, 9, 8, 9, 1, 9, 3,
8, 9, 7, 8, 2, 6, 3, 4, 1, 2,
1, 2, 4, 7, 9, 5, 2, 6, 3, 1,
2, 3, 5, 1, 8, 4, 9,
8, 9, 4, 6, 5, 9, 3, 1, 8,
4, 7, 1, 2, 7, 1, 2, 4,
};

get_settings_singleton()->filepath = MEDIUM_PUZZLE_PATH"2.kkr";
get_settings_singleton()->is_arc_consistency = true;
get_settings_singleton()->is_backtrack = true;
get_settings_singleton()->is_forward_check = true;

FILE * fp = fopen(get_settings_singleton()->filepath, "rb");
ASSERTm("COULDN'T OPEN FILE", fp);

Kakuro board = init_kakuro(fp);
fclose(fp);

SArray solution = depth_first_search(board);
free_kakuro(&board);

ASSERTm("NO SOLUTION FOUND", solution.size);
ASSERTm("LENGTHS DON'T ADD UP", solution.size == (sizeof(expected_solution) / sizeof(ksize_t)));

for (ksize_t i = 0; i < solution.size; i++) {
ASSERTm("INVALID SOLUTION", get_one_value(solution.elements[i]) == expected_solution[i]);
}

destroy_state_array(&solution);

PASS();
}

TEST medium_arc_consistency_backtrack_forward_check_three(void) {
ksize_t expected_solution[] = {
2, 4, 1, 2, 4, 1, 7,
8, 6, 5, 7, 3, 7, 6, 8, 3, 9,
5, 1, 3, 2, 3, 1, 6,
9, 7, 1, 2, 4, 9, 7,
5, 7, 1, 2, 9, 3, 3, 6, 1, 2,
1, 3, 3, 9, 7, 9, 7,
3, 1, 5, 3, 1, 2, 5,
4, 9, 7, 6, 8, 9, 6, 7, 4, 8,
1, 7, 2, 4, 3, 1, 2,
};

get_settings_singleton()->filepath = MEDIUM_PUZZLE_PATH"3.kkr";
get_settings_singleton()->is_arc_consistency = true;
get_settings_singleton()->is_backtrack = true;
get_settings_singleton()->is_forward_check = true;

FILE * fp = fopen(get_settings_singleton()->filepath, "rb");
ASSERTm("COULDN'T OPEN FILE", fp);

Kakuro board = init_kakuro(fp);
fclose(fp);

SArray solution = depth_first_search(board);
free_kakuro(&board);

ASSERTm("NO SOLUTION FOUND", solution.size);
ASSERTm("LENGTHS DON'T ADD UP", solution.size == (sizeof(expected_solution) / sizeof(ksize_t)));

for (ksize_t i = 0; i < solution.size; i++) {
ASSERTm("INVALID SOLUTION", get_one_value(solution.elements[i]) == expected_solution[i]);
}

destroy_state_array(&solution);

PASS();
}

TEST medium_arc_consistency_backtrack_forward_check_four(void) {
ksize_t expected_solution[] = {
5, 9, 7, 8, 9, 4, 2, 3, 1,
1, 3, 1, 2, 8, 8, 7, 9, 6, 2,
3, 5, 1, 2, 4, 9, 8, 6,
2, 7, 3, 1, 2, 6,
8, 6, 9, 9, 3, 9, 3, 8,
6, 1, 5, 1, 5, 2,
9, 8, 6, 3, 6, 2, 7, 4,
8, 9, 3, 4, 2, 9, 6, 8, 3, 1,
4, 7, 1, 2, 2, 1, 4, 9, 7,
};

get_settings_singleton()->filepath = MEDIUM_PUZZLE_PATH"4.kkr";
get_settings_singleton()->is_arc_consistency = true;
get_settings_singleton()->is_backtrack = true;
get_settings_singleton()->is_forward_check = true;

FILE * fp = fopen(get_settings_singleton()->filepath, "rb");
ASSERTm("COULDN'T OPEN FILE", fp);

Kakuro board = init_kakuro(fp);
fclose(fp);

SArray solution = depth_first_search(board);
free_kakuro(&board);

ASSERTm("NO SOLUTION FOUND", solution.size);
ASSERTm("LENGTHS DON'T ADD UP", solution.size == (sizeof(expected_solution) / sizeof(ksize_t)));

for (ksize_t i = 0; i < solution.size; i++) {
ASSERTm("INVALID SOLUTION", get_one_value(solution.elements[i]) == expected_solution[i]);
}

destroy_state_array(&solution);

PASS();
}

TEST medium_arc_consistency_backtrack_forward_check_five(void) {
ksize_t expected_solution[] = {
6, 8, 9, 2, 1, 4, 9, 4, 7,
2, 4, 3, 7, 8, 5, 9, 8, 6, 9,
1, 2, 9, 3, 5, 4, 1, 2,
7, 9, 7, 2, 2, 3, 8, 4,
2, 3, 4, 9, 2, 1, 7, 3, 1, 7,
8, 1, 6, 4, 8, 2, 8, 9,
7, 9, 3, 9, 6, 4, 8, 7,
9, 2, 6, 9, 8, 7, 5, 2, 4, 1,
7, 1, 3, 1, 4, 2, 6, 9, 3,
};

get_settings_singleton()->filepath = MEDIUM_PUZZLE_PATH"5.kkr";
get_settings_singleton()->is_arc_consistency = true;
get_settings_singleton()->is_backtrack = true;
get_settings_singleton()->is_forward_check = true;

FILE * fp = fopen(get_settings_singleton()->filepath, "rb");
ASSERTm("COULDN'T OPEN FILE", fp);

Kakuro board = init_kakuro(fp);
fclose(fp);

SArray solution = depth_first_search(board);
free_kakuro(&board);

ASSERTm("NO SOLUTION FOUND", solution.size);
ASSERTm("LENGTHS DON'T ADD UP", solution.size == (sizeof(expected_solution) / sizeof(ksize_t)));

for (ksize_t i = 0; i < solution.size; i++) {
ASSERTm("INVALID SOLUTION", get_one_value(solution.elements[i]) == expected_solution[i]);
}

destroy_state_array(&solution);

PASS();
}

SUITE (medium_arc_consistency_backtrack_forward_check) {
// 10 x 13
RUN_TEST(medium_arc_consistency_backtrack_forward_check_one);
RUN_TEST(medium_arc_consistency_backtrack_forward_check_two);
RUN_TEST(medium_arc_consistency_backtrack_forward_check_three);
RUN_TEST(medium_arc_consistency_backtrack_forward_check_four);
RUN_TEST(medium_arc_consistency_backtrack_forward_check_five);
}
Loading

0 comments on commit 7a46681

Please sign in to comment.