From 2fa05a06bad7036f7b94cbb57e6448804d78fb84 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 22 Sep 2025 13:04:25 -0400 Subject: [PATCH 01/23] Break egg test into simple across and down tests --- src/clue-matches-tests.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index e7dd49e0..16d64830 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -25,7 +25,8 @@ #include "word-list-test-utils.h" #include "test-utils.h" -#define EGG_IPUZ "tests/clue-matches/egg.ipuz" +#define SIMPLE_ACROSS_IPUZ "tests/clue-matches/simple-across.ipuz" +#define SIMPLE_DOWN_IPUZ "tests/clue-matches/simple-down.ipuz" #define VALID_INTERSECTION_IPUZ "tests/clue-matches/valid-intersection.ipuz" #define INVALID_INTERSECTION_IPUZ "tests/clue-matches/invalid-intersection.ipuz" @@ -106,7 +107,7 @@ test_clue_matches (WordList *word_list, } static void -test_egg_ipuz (Fixture *fixture, gconstpointer user_data) +test_simple_across_ipuz (Fixture *fixture, gconstpointer user_data) { test_clue_matches (fixture->word_list, fixture->grid, @@ -115,6 +116,16 @@ test_egg_ipuz (Fixture *fixture, gconstpointer user_data) (const gchar*[]){"EGGS", "EGGO", "EGGY", NULL}); } +static void +test_simple_down_ipuz (Fixture *fixture, gconstpointer user_data) +{ + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_DOWN, + 2, + (const gchar*[]){"EGGS", "EGGO", "EGGY", NULL}); +} + static void test_valid_intersection_ipuz (Fixture *fixture, gconstpointer user_data) { @@ -151,11 +162,17 @@ int main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); - g_test_add ("/clue_matches/test_egg_ipuz", + g_test_add ("/clue_matches/test_simple_across_ipuz", + Fixture, + SIMPLE_ACROSS_IPUZ, + fixture_set_up, + test_simple_across_ipuz, + fixture_tear_down); + g_test_add ("/clue_matches/test_simple_down_ipuz", Fixture, - EGG_IPUZ, + SIMPLE_DOWN_IPUZ, fixture_set_up, - test_egg_ipuz, + test_simple_down_ipuz, fixture_tear_down); g_test_add ("/clue_matches/valid_intersection_ipuz", Fixture, -- GitLab From b09d519cd2eb6b441925bc66331c98b1d0638912 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 22 Sep 2025 13:10:17 -0400 Subject: [PATCH 02/23] Create simple across and down ipuz files --- src/clue-matches-tests.c | 2 +- .../{egg.ipuz => simple-across.ipuz} | 0 src/tests/clue-matches/simple-down.ipuz | 106 ++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) rename src/tests/clue-matches/{egg.ipuz => simple-across.ipuz} (100%) create mode 100644 src/tests/clue-matches/simple-down.ipuz diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 16d64830..d96cfe17 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -122,7 +122,7 @@ test_simple_down_ipuz (Fixture *fixture, gconstpointer user_data) test_clue_matches (fixture->word_list, fixture->grid, IPUZ_CLUE_DIRECTION_DOWN, - 2, + 3, (const gchar*[]){"EGGS", "EGGO", "EGGY", NULL}); } diff --git a/src/tests/clue-matches/egg.ipuz b/src/tests/clue-matches/simple-across.ipuz similarity index 100% rename from src/tests/clue-matches/egg.ipuz rename to src/tests/clue-matches/simple-across.ipuz diff --git a/src/tests/clue-matches/simple-down.ipuz b/src/tests/clue-matches/simple-down.ipuz new file mode 100644 index 00000000..b7953ed1 --- /dev/null +++ b/src/tests/clue-matches/simple-down.ipuz @@ -0,0 +1,106 @@ +{ + "kind" : [ + "http://ipuz.org/crossword#1" + ], + "version" : "http://ipuz.org/v2", + "title" : "My Crossword-1", + "charset-str" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "origin" : "GNOME Crosswords Editor (0.3.16)", + "block" : "#", + "empty" : "0", + "dimensions" : { + "width" : 4, + "height" : 4 + }, + "puzzle" : [ + [ + 1, + 2, + 3, + 4 + ], + [ + 5, + 0, + 0, + 0 + ], + [ + 6, + 0, + 0, + 0 + ], + [ + 7, + 0, + 0, + 0 + ] + ], + "solution" : [ + [ + null, + null, + null, + "E" + ], + [ + null, + null, + null, + "G" + ], + [ + null, + null, + null, + "G" + ], + [ + null, + null, + null, + null + ] + ], + "showenumerations" : false, + "clues" : { + "Across:Across" : [ + [ + 1, + null + ], + [ + 5, + null + ], + [ + 6, + null + ], + [ + 7, + null + ] + ], + "Down:Down" : [ + [ + 1, + null + ], + [ + 2, + null + ], + [ + 3, + null + ], + [ + 4, + null + ] + ] + } +} \ No newline at end of file -- GitLab From 654e532dcbac88cd4634b4c869bcee731c7c280e Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 22 Sep 2025 20:28:54 -0400 Subject: [PATCH 03/23] Add test_dense_ipuz --- src/clue-matches-tests.c | 47 +++++++++++++ src/tests/clue-matches/dense.ipuz | 106 ++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 src/tests/clue-matches/dense.ipuz diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 67170021..a5716d33 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -106,6 +106,7 @@ test_clue_matches (WordList *word_list, clue_matches = word_list_find_clue_matches (word_list, clue, grid); expected_word_array = str_array_to_word_array (expected_words, word_list); + word_array_print (clue_matches); g_assert_true (word_array_equals (clue_matches, expected_word_array)); } @@ -159,6 +160,51 @@ test_invalid_intersection_ipuz (Fixture *fixture, gconstpointer user_data) (const gchar*[]){NULL}); } +static void +test_dense_ipuz (Fixture *fixture, gconstpointer user_data) +{ + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_ACROSS, + 0, + (const gchar*[]){"WORD", NULL}); + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_ACROSS, + 1, + (const gchar*[]){"ARIA", NULL}); + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_ACROSS, + 2, + (const gchar*[]){"LINT", NULL}); + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_ACROSS, + 3, + (const gchar*[]){"LAKE", NULL}); + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_DOWN, + 0, + (const gchar*[]){"WALL", NULL}); + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_DOWN, + 1, + (const gchar*[]){"ORIA", NULL}); + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_DOWN, + 2, + (const gchar*[]){"RINK", NULL}); + test_clue_matches (fixture->word_list, + fixture->grid, + IPUZ_CLUE_DIRECTION_DOWN, + 3, + (const gchar*[]){"DATE", NULL}); +} + /* FIXME(tests): Measure performance. */ /* FIXME(tests): Add more tests. */ int @@ -169,5 +215,6 @@ main (int argc, char **argv) ADD_IPUZ_TEST (test_simple_down_ipuz, simple-down.ipuz); ADD_IPUZ_TEST (test_valid_intersection_ipuz, valid-intersection.ipuz); ADD_IPUZ_TEST (test_invalid_intersection_ipuz, invalid-intersection.ipuz); + ADD_IPUZ_TEST (test_dense_ipuz, dense.ipuz); return g_test_run (); } diff --git a/src/tests/clue-matches/dense.ipuz b/src/tests/clue-matches/dense.ipuz new file mode 100644 index 00000000..69917d5b --- /dev/null +++ b/src/tests/clue-matches/dense.ipuz @@ -0,0 +1,106 @@ +{ + "kind" : [ + "http://ipuz.org/crossword#1" + ], + "version" : "http://ipuz.org/v2", + "title" : "My Crossword-1", + "charset-str" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "origin" : "GNOME Crosswords Editor (0.3.16)", + "block" : "#", + "empty" : "0", + "dimensions" : { + "width" : 4, + "height" : 4 + }, + "puzzle" : [ + [ + 1, + 2, + 3, + 4 + ], + [ + 5, + 0, + 0, + 0 + ], + [ + 6, + 0, + 0, + 0 + ], + [ + 7, + 0, + 0, + 0 + ] + ], + "solution" : [ + [ + "W", + "O", + "R", + "D" + ], + [ + "A", + "R", + "I", + "A" + ], + [ + "L", + "I", + "N", + "T" + ], + [ + "L", + "A", + "K", + "E" + ] + ], + "showenumerations" : false, + "clues" : { + "Across:Across" : [ + [ + 1, + null + ], + [ + 5, + null + ], + [ + 6, + null + ], + [ + 7, + null + ] + ], + "Down:Down" : [ + [ + 1, + null + ], + [ + 2, + null + ], + [ + 3, + null + ], + [ + 4, + null + ] + ] + } +} \ No newline at end of file -- GitLab From 470d38de7cbe2aa6349b5be68f13c81cd5f95682 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 18:37:44 -0400 Subject: [PATCH 04/23] Move word-list-misc print commands --- src/word-list-misc.c | 44 ------------------------------------------ src/word-list-misc.h | 2 -- src/word-list.c | 46 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 024417e4..8ed4faf7 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -339,50 +339,6 @@ word_array_equals (WordArray *word_array1, WordArray *word_array2) return TRUE; } -static void -word_index_print (WordIndex word_index) -{ - g_message ("\t(index: %2d, length: %2d)", - word_index.index, - word_index.length); -} - -#define MAX_WORDS 10 -static void -word_array_print_helper (WordArray *word_array) -{ - /* FIXME(debugging): Print first 5 and last 5 words instead of first 10. */ - for (guint i = 0; i < MIN (word_array->len, MAX_WORDS); i++) - { - WordIndex word_index = word_array_index (word_array, i); - word_index_print (word_index); - } -} - -void -word_array_print (WordArray *word_array) -{ - if (word_array == NULL) - { - g_warning ("word_array_print: WordArray is NULL."); - return; - } - g_message ("WordArray %p:", word_array); - word_array_print_helper (word_array); -} - -void -word_set_print (WordSet *word_set) -{ - if (word_set == NULL) - { - g_warning ("word_set_print: WordSet is NULL."); - return; - } - g_message ("WordSet %p:", word_set); - word_array_print_helper (word_set_to_array (word_set)); -} - gboolean word_index_equals (WordIndex word_index1, WordIndex word_index2) diff --git a/src/word-list-misc.h b/src/word-list-misc.h index 50536cf6..dd085106 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -111,7 +111,6 @@ gboolean word_array_find (WordArray *word_array, void word_array_sort (WordArray *word_array); gboolean word_array_equals (WordArray *word_array1, WordArray *word_array2); -void word_array_print (WordArray *word_array); #define word_array_len(wa) (((GArray*)wa)->len) #define word_array_index(wa,i) (g_array_index((GArray*)wa,WordIndex,i)) @@ -126,7 +125,6 @@ void word_set_remove_unique (WordSet *word_set1, void word_set_add_array (WordSet *word_set, WordArray *word_array); WordArray *word_set_to_array (WordSet *word_set); -void word_set_print (WordSet *word_set); #define word_set_add(ws,wi) (g_hash_table_add(ws,wi)) diff --git a/src/word-list.c b/src/word-list.c index a88fe93a..403659a2 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1527,4 +1527,48 @@ word_list_find_intersection (WordList *word_list, *intersecting_chars = ipuz_charset_ref (charset2); PUSH_TIMER ("word_list_find_intersection()"); -} \ No newline at end of file +} + +static void +word_index_print (WordIndex word_index) +{ + g_message ("\t(index: %2d, length: %2d)", + word_index.index, + word_index.length); +} + +#define MAX_WORDS 10 +static void +word_array_print_helper (WordArray *word_array) +{ + /* FIXME(debugging): Print first 5 and last 5 words instead of first 10. */ + for (guint i = 0; i < MIN (word_array->len, MAX_WORDS); i++) + { + WordIndex word_index = word_array_index (word_array, i); + word_index_print (word_index); + } +} + +void +word_array_print (WordArray *word_array) +{ + if (word_array == NULL) + { + g_warning ("word_array_print: WordArray is NULL."); + return; + } + g_message ("WordArray %p:", word_array); + word_array_print_helper (word_array); +} + +void +word_set_print (WordSet *word_set) +{ + if (word_set == NULL) + { + g_warning ("word_set_print: WordSet is NULL."); + return; + } + g_message ("WordSet %p:", word_set); + word_array_print_helper (word_set_to_array (word_set)); +} -- GitLab From e7ce00112780e014a3db55f1f81e029975fca1b5 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 18:56:24 -0400 Subject: [PATCH 05/23] Add print functions to word-list.h --- src/word-list.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/word-list.h b/src/word-list.h index 8d49c763..4311ff10 100644 --- a/src/word-list.h +++ b/src/word-list.h @@ -108,7 +108,11 @@ void word_list_find_intersection (WordList *word WordArray **filter2_words); - +/* Debugging functions */ +void word_list_print_word_array (WordList *word_list, + WordArray *word_array); +void word_list_print_word_set (WordList *word_list, + WordSet *word_set); G_END_DECLS -- GitLab From d1a2ded9fc591ba5e313991bdc736ff9ecf2e4b7 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 19:01:02 -0400 Subject: [PATCH 06/23] Fix function names --- src/clue-matches.c | 2 ++ src/word-list.c | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/clue-matches.c b/src/clue-matches.c index a974eb43..e05b68af 100644 --- a/src/clue-matches.c +++ b/src/clue-matches.c @@ -162,10 +162,12 @@ word_list_find_clue_matches (WordList *word_list, current_filter_offset++; intersection_word_set = word_set_new (); + // word_list_print_word_array (word_list, intersection_word_array); word_set_add_array (intersection_word_set, intersection_word_array); word_set_remove_unique (clue_matches_set, intersection_word_set); word_array_unref (intersection_word_array); } + word_list_print_word_set (word_list, clue_matches_set); return word_set_to_array (clue_matches_set); } diff --git a/src/word-list.c b/src/word-list.c index 403659a2..d4831c7e 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1549,24 +1549,22 @@ word_array_print_helper (WordArray *word_array) } } -void -word_array_print (WordArray *word_array) +void word_list_print_word_array (WordList *word_list, WordArray *word_array) { if (word_array == NULL) { - g_warning ("word_array_print: WordArray is NULL."); + g_warning ("word_list_print_word_array: WordArray is NULL."); return; } g_message ("WordArray %p:", word_array); word_array_print_helper (word_array); } -void -word_set_print (WordSet *word_set) +void word_list_print_word_set (WordList *word_list, WordSet *word_set) { if (word_set == NULL) { - g_warning ("word_set_print: WordSet is NULL."); + g_warning ("word_list_print_word_set: WordSet is NULL."); return; } g_message ("WordSet %p:", word_set); -- GitLab From 96f9c40bcb34aac8c2145fb6b44c3033f71acffd Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 19:23:28 -0400 Subject: [PATCH 07/23] Print the actual words instead of indexes --- src/word-list.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/word-list.c b/src/word-list.c index d4831c7e..5468bfad 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1529,23 +1529,15 @@ word_list_find_intersection (WordList *word_list, PUSH_TIMER ("word_list_find_intersection()"); } -static void -word_index_print (WordIndex word_index) -{ - g_message ("\t(index: %2d, length: %2d)", - word_index.index, - word_index.length); -} - #define MAX_WORDS 10 static void -word_array_print_helper (WordArray *word_array) +word_array_print_helper (WordList *word_list, WordArray *word_array) { /* FIXME(debugging): Print first 5 and last 5 words instead of first 10. */ for (guint i = 0; i < MIN (word_array->len, MAX_WORDS); i++) { WordIndex word_index = word_array_index (word_array, i); - word_index_print (word_index); + g_message ("\t%s", word_list_get_indexed_word (word_list, word_index)); } } @@ -1557,7 +1549,7 @@ void word_list_print_word_array (WordList *word_list, WordArray *word_array) return; } g_message ("WordArray %p:", word_array); - word_array_print_helper (word_array); + word_array_print_helper (word_list, word_array); } void word_list_print_word_set (WordList *word_list, WordSet *word_set) @@ -1568,5 +1560,5 @@ void word_list_print_word_set (WordList *word_list, WordSet *word_set) return; } g_message ("WordSet %p:", word_set); - word_array_print_helper (word_set_to_array (word_set)); + word_array_print_helper (word_list, word_set_to_array (word_set)); } -- GitLab From 7d3e703a495b388a081546a300cf648646bbed86 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 19:34:56 -0400 Subject: [PATCH 08/23] Add #ifdef DEVELOPMENT_BUILD --- src/word-list.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/word-list.c b/src/word-list.c index 5468bfad..34706636 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1529,6 +1529,9 @@ word_list_find_intersection (WordList *word_list, PUSH_TIMER ("word_list_find_intersection()"); } + +#ifdef DEVELOPMENT_BUILD + #define MAX_WORDS 10 static void word_array_print_helper (WordList *word_list, WordArray *word_array) @@ -1562,3 +1565,5 @@ void word_list_print_word_set (WordList *word_list, WordSet *word_set) g_message ("WordSet %p:", word_set); word_array_print_helper (word_list, word_set_to_array (word_set)); } + +#endif \ No newline at end of file -- GitLab From a6723941ec926e353b6a6ba110b8c796154591b5 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 22:50:44 -0400 Subject: [PATCH 09/23] Print first and last 5 words --- src/clue-matches-tests.c | 1 + src/clue-matches.c | 3 +-- src/word-list.c | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 18fb7c8c..09f7fc69 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -22,6 +22,7 @@ #include #include "crosswords-misc.h" #include "clue-matches.h" +#include "word-list.c" #include "word-list-test-utils.h" #include "test-utils.h" diff --git a/src/clue-matches.c b/src/clue-matches.c index e05b68af..9e1e1843 100644 --- a/src/clue-matches.c +++ b/src/clue-matches.c @@ -162,12 +162,11 @@ word_list_find_clue_matches (WordList *word_list, current_filter_offset++; intersection_word_set = word_set_new (); - // word_list_print_word_array (word_list, intersection_word_array); word_set_add_array (intersection_word_set, intersection_word_array); word_set_remove_unique (clue_matches_set, intersection_word_set); word_array_unref (intersection_word_array); } - word_list_print_word_set (word_list, clue_matches_set); + word_list_print_word_array (word_list, word_set_to_array (clue_matches_set)); return word_set_to_array (clue_matches_set); } diff --git a/src/word-list.c b/src/word-list.c index 34706636..9b1767c0 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1536,8 +1536,23 @@ word_list_find_intersection (WordList *word_list, static void word_array_print_helper (WordList *word_list, WordArray *word_array) { - /* FIXME(debugging): Print first 5 and last 5 words instead of first 10. */ - for (guint i = 0; i < MIN (word_array->len, MAX_WORDS); i++) + g_assert (word_array != NULL); + + const guint len = word_array_len (word_array); + const guint first_loop_end = MIN (4, len - 1); + const guint second_loop_start = MAX (first_loop_end + 1, len - 5); + const guint second_loop_end = MIN (second_loop_start + 4, len - 1); + + if (len == 0) + return; + for (guint i = 0; i <= first_loop_end; i++) + { + WordIndex word_index = word_array_index (word_array, i); + g_message ("\t%s", word_list_get_indexed_word (word_list, word_index)); + } + if (second_loop_start <= first_loop_end) + return; + for (guint i = second_loop_start; i <= second_loop_end; i++) { WordIndex word_index = word_array_index (word_array, i); g_message ("\t%s", word_list_get_indexed_word (word_list, word_index)); -- GitLab From b6c8948f5c4cbd42385591b2ec89b0cc4e0324e3 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 22:53:23 -0400 Subject: [PATCH 10/23] Remove print function call --- src/clue-matches.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clue-matches.c b/src/clue-matches.c index 9e1e1843..a974eb43 100644 --- a/src/clue-matches.c +++ b/src/clue-matches.c @@ -167,6 +167,5 @@ word_list_find_clue_matches (WordList *word_list, word_array_unref (intersection_word_array); } - word_list_print_word_array (word_list, word_set_to_array (clue_matches_set)); return word_set_to_array (clue_matches_set); } -- GitLab From bb0cacf4a609e2929b108381575f70074d8b28d1 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 23:16:12 -0400 Subject: [PATCH 11/23] Use ellipsis to denote omitted words --- src/clue-matches.c | 1 + src/word-list.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/clue-matches.c b/src/clue-matches.c index a974eb43..c8efd50a 100644 --- a/src/clue-matches.c +++ b/src/clue-matches.c @@ -167,5 +167,6 @@ word_list_find_clue_matches (WordList *word_list, word_array_unref (intersection_word_array); } + word_list_print_word_set (word_list, clue_matches_set); return word_set_to_array (clue_matches_set); } diff --git a/src/word-list.c b/src/word-list.c index 9b1767c0..3a19381b 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1532,6 +1532,7 @@ word_list_find_intersection (WordList *word_list, #ifdef DEVELOPMENT_BUILD +// TODO: Use MAX_WORDS. #define MAX_WORDS 10 static void word_array_print_helper (WordList *word_list, WordArray *word_array) @@ -1545,13 +1546,18 @@ word_array_print_helper (WordList *word_list, WordArray *word_array) if (len == 0) return; + for (guint i = 0; i <= first_loop_end; i++) { WordIndex word_index = word_array_index (word_array, i); g_message ("\t%s", word_list_get_indexed_word (word_list, word_index)); } - if (second_loop_start <= first_loop_end) + + if (first_loop_end == len - 1) return; + else if (second_loop_start != first_loop_end + 1) + g_message ("\t..."); + for (guint i = second_loop_start; i <= second_loop_end; i++) { WordIndex word_index = word_array_index (word_array, i); -- GitLab From 43e1c5daa9d335bcd0bcfbb7d7b0c1f6746fa89f Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 23:23:47 -0400 Subject: [PATCH 12/23] Use MAX_WORDS macro --- src/word-list.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/word-list.c b/src/word-list.c index 3a19381b..368c283f 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1532,17 +1532,17 @@ word_list_find_intersection (WordList *word_list, #ifdef DEVELOPMENT_BUILD -// TODO: Use MAX_WORDS. #define MAX_WORDS 10 +#define HALF_MAX MAX_WORDS / 2 static void word_array_print_helper (WordList *word_list, WordArray *word_array) { g_assert (word_array != NULL); const guint len = word_array_len (word_array); - const guint first_loop_end = MIN (4, len - 1); - const guint second_loop_start = MAX (first_loop_end + 1, len - 5); - const guint second_loop_end = MIN (second_loop_start + 4, len - 1); + const guint first_loop_end = MIN (HALF_MAX - 1, len - 1); + const guint second_loop_start = MAX (first_loop_end + 1, len - HALF_MAX); + const guint second_loop_end = MIN (second_loop_start + HALF_MAX - 1, len - 1); if (len == 0) return; -- GitLab From e7c6714d5ce3f966a7760571bdd38420c3deca36 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 23:25:24 -0400 Subject: [PATCH 13/23] Remove unnecessary calculation --- src/word-list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/word-list.c b/src/word-list.c index 368c283f..bbc7e63d 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1542,7 +1542,7 @@ word_array_print_helper (WordList *word_list, WordArray *word_array) const guint len = word_array_len (word_array); const guint first_loop_end = MIN (HALF_MAX - 1, len - 1); const guint second_loop_start = MAX (first_loop_end + 1, len - HALF_MAX); - const guint second_loop_end = MIN (second_loop_start + HALF_MAX - 1, len - 1); + const guint second_loop_end = len - 1; if (len == 0) return; -- GitLab From 8fccfce014a3e754e66e15e42c436a4360fb2994 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 23 Sep 2025 23:29:47 -0400 Subject: [PATCH 14/23] Remove print function call --- src/clue-matches.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clue-matches.c b/src/clue-matches.c index c8efd50a..a974eb43 100644 --- a/src/clue-matches.c +++ b/src/clue-matches.c @@ -167,6 +167,5 @@ word_list_find_clue_matches (WordList *word_list, word_array_unref (intersection_word_array); } - word_list_print_word_set (word_list, clue_matches_set); return word_set_to_array (clue_matches_set); } -- GitLab From e4638afbde8628a9e012db054a52bbf8016bdf5d Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 00:35:19 -0400 Subject: [PATCH 15/23] Move ADD_IPUZ_TEST macro --- src/clue-matches-tests.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 8998d50f..4f8f52f6 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -26,14 +26,6 @@ #include "word-list-test-utils.h" #include "test-utils.h" -#define ADD_IPUZ_TEST(test_name, file_name) \ - g_test_add ("/clue_matches/" #test_name, \ - Fixture, \ - "tests/clue-matches/" #file_name, \ - fixture_set_up, \ - test_name, \ - fixture_tear_down) - typedef struct { WordList *word_list; IpuzGrid *grid; @@ -107,7 +99,6 @@ test_clue_matches (WordList *word_list, clue_matches = word_list_find_clue_matches (word_list, clue, grid); expected_word_array = str_array_to_word_array (expected_words, word_list); - word_array_print (clue_matches); g_assert_true (word_array_equals (clue_matches, expected_word_array)); } @@ -198,8 +189,15 @@ test_dense_ipuz (Fixture *fixture, gconstpointer user_data) (const gchar*[]){"DATE", NULL}); } +#define ADD_IPUZ_TEST(test_name, file_name) \ + g_test_add ("/clue_matches/" #test_name, \ + Fixture, \ + "tests/clue-matches/" #file_name, \ + fixture_set_up, \ + test_name, \ + fixture_tear_down) + /* FIXME(tests): Measure performance. */ -/* FIXME(tests): Add more tests. */ int main (int argc, char **argv) { -- GitLab From 8a998625f23259a537b1f68661ffb9c697fd253d Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 00:38:36 -0400 Subject: [PATCH 16/23] Use ASSERT_CLUE_MATCHES macro --- src/clue-matches-tests.c | 54 +++++++--------------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 4f8f52f6..9d680064 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -123,11 +123,7 @@ test_simple_across_ipuz (Fixture *fixture, gconstpointer user_data) static void test_simple_down_ipuz (Fixture *fixture, gconstpointer user_data) { - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_DOWN, - 3, - (const gchar*[]){"EGGS", "EGGO", "EGGY", NULL}); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 3, "EGGS", "EGGO", "EGGY"); } static void @@ -147,46 +143,14 @@ test_invalid_intersection_ipuz (Fixture *fixture, gconstpointer user_data) static void test_dense_ipuz (Fixture *fixture, gconstpointer user_data) { - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_ACROSS, - 0, - (const gchar*[]){"WORD", NULL}); - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_ACROSS, - 1, - (const gchar*[]){"ARIA", NULL}); - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_ACROSS, - 2, - (const gchar*[]){"LINT", NULL}); - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_ACROSS, - 3, - (const gchar*[]){"LAKE", NULL}); - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_DOWN, - 0, - (const gchar*[]){"WALL", NULL}); - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_DOWN, - 1, - (const gchar*[]){"ORIA", NULL}); - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_DOWN, - 2, - (const gchar*[]){"RINK", NULL}); - test_clue_matches (fixture->word_list, - fixture->grid, - IPUZ_CLUE_DIRECTION_DOWN, - 3, - (const gchar*[]){"DATE", NULL}); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 0, "WORD"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 1, "ARIA"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 2, "LINT"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 3, "LAKE"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 0, "WALL"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 1, "ORIA"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 2, "RINK"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 3, "DATE"); } #define ADD_IPUZ_TEST(test_name, file_name) \ -- GitLab From a9af8da6f2de8d6b5a9e6d1657b7534e74fe6313 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 00:40:41 -0400 Subject: [PATCH 17/23] Align code --- src/clue-matches-tests.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 9d680064..3e75f8db 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -130,14 +130,14 @@ static void test_valid_intersection_ipuz (Fixture *fixture, gconstpointer user_data) { ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 1, "WORD", "WORM"); - ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 3, "EDIT", "EMIT"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 3, "EDIT", "EMIT"); } static void test_invalid_intersection_ipuz (Fixture *fixture, gconstpointer user_data) { ASSERT_CLUE_MATCHES_EMPTY (IPUZ_CLUE_DIRECTION_ACROSS, 3); - ASSERT_CLUE_MATCHES_EMPTY (IPUZ_CLUE_DIRECTION_DOWN, 3); + ASSERT_CLUE_MATCHES_EMPTY (IPUZ_CLUE_DIRECTION_DOWN, 3); } static void @@ -166,10 +166,12 @@ int main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); - ADD_IPUZ_TEST (test_simple_across_ipuz, simple-across.ipuz); - ADD_IPUZ_TEST (test_simple_down_ipuz, simple-down.ipuz); - ADD_IPUZ_TEST (test_valid_intersection_ipuz, valid-intersection.ipuz); + + ADD_IPUZ_TEST (test_simple_across_ipuz, simple-across.ipuz); + ADD_IPUZ_TEST (test_simple_down_ipuz, simple-down.ipuz); + ADD_IPUZ_TEST (test_valid_intersection_ipuz, valid-intersection.ipuz); ADD_IPUZ_TEST (test_invalid_intersection_ipuz, invalid-intersection.ipuz); - ADD_IPUZ_TEST (test_dense_ipuz, dense.ipuz); + ADD_IPUZ_TEST (test_dense_ipuz, dense.ipuz); + return g_test_run (); } -- GitLab From 45938a8299fe1f6083b021be8ae8f70a67d98460 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 00:52:50 -0400 Subject: [PATCH 18/23] Add test_block_cells_ipuz() --- src/clue-matches-tests.c | 8 ++ src/tests/clue-matches/block-cells.ipuz | 106 ++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/tests/clue-matches/block-cells.ipuz diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 3e75f8db..c4c9fbe5 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -153,6 +153,13 @@ test_dense_ipuz (Fixture *fixture, gconstpointer user_data) ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 3, "DATE"); } +static void +test_block_cells_ipuz (Fixture *fixture, gconstpointer user_data) +{ + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 0, "ADD", "AID", "AND", "AMD"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 0, "AXES", "AXIS"); +} + #define ADD_IPUZ_TEST(test_name, file_name) \ g_test_add ("/clue_matches/" #test_name, \ Fixture, \ @@ -172,6 +179,7 @@ main (int argc, char **argv) ADD_IPUZ_TEST (test_valid_intersection_ipuz, valid-intersection.ipuz); ADD_IPUZ_TEST (test_invalid_intersection_ipuz, invalid-intersection.ipuz); ADD_IPUZ_TEST (test_dense_ipuz, dense.ipuz); + ADD_IPUZ_TEST (test_block_cells_ipuz, block-cells.ipuz); return g_test_run (); } diff --git a/src/tests/clue-matches/block-cells.ipuz b/src/tests/clue-matches/block-cells.ipuz new file mode 100644 index 00000000..7b938d00 --- /dev/null +++ b/src/tests/clue-matches/block-cells.ipuz @@ -0,0 +1,106 @@ +{ + "kind" : [ + "http://ipuz.org/crossword#1" + ], + "version" : "http://ipuz.org/v2", + "title" : "My Crossword-1", + "charset-str" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "origin" : "GNOME Crosswords Editor (0.3.16)", + "block" : "#", + "empty" : "0", + "dimensions" : { + "width" : 4, + "height" : 4 + }, + "puzzle" : [ + [ + 1, + 0, + 2, + "#" + ], + [ + 0, + "#", + 3, + 4 + ], + [ + 5, + 6, + "#", + 0 + ], + [ + 7, + 0, + "#", + 0 + ] + ], + "solution" : [ + [ + "A", + null, + "D", + null + ], + [ + "X", + null, + null, + null + ], + [ + null, + null, + null, + null + ], + [ + "S", + null, + null, + null + ] + ], + "showenumerations" : false, + "clues" : { + "Across:Across" : [ + [ + 1, + null + ], + [ + 3, + null + ], + [ + 5, + null + ], + [ + 7, + null + ] + ], + "Down:Down" : [ + [ + 1, + null + ], + [ + 2, + null + ], + [ + 4, + null + ], + [ + 6, + null + ] + ] + } +} \ No newline at end of file -- GitLab From 11956272328c8a920bc60736f6f3c07dee0a277f Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 00:57:34 -0400 Subject: [PATCH 19/23] Add comment --- src/clue-matches-tests.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index c4c9fbe5..389c02db 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -26,6 +26,9 @@ #include "word-list-test-utils.h" #include "test-utils.h" + +/* Helper code */ + typedef struct { WordList *word_list; IpuzGrid *grid; @@ -102,6 +105,7 @@ test_clue_matches (WordList *word_list, g_assert_true (word_array_equals (clue_matches, expected_word_array)); } + /* Tests */ #define ASSERT_CLUE_MATCHES(DIRECTION, INDEX, ...) \ -- GitLab From 6d3e51343d6d4717cb8a43ca17b4226adae44c18 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 01:02:43 -0400 Subject: [PATCH 20/23] Add test_rebus_ipuz() --- src/clue-matches-tests.c | 8 +++ src/tests/clue-matches/rebus.ipuz | 106 ++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/tests/clue-matches/rebus.ipuz diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 389c02db..46ea0d5d 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -164,6 +164,13 @@ test_block_cells_ipuz (Fixture *fixture, gconstpointer user_data) ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 0, "AXES", "AXIS"); } +static void +test_rebus_ipuz (Fixture *fixture, gconstpointer user_data) +{ + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 0, "REBUS", "REMUS"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 2, "BANANA", "MANANA"); +} + #define ADD_IPUZ_TEST(test_name, file_name) \ g_test_add ("/clue_matches/" #test_name, \ Fixture, \ @@ -184,6 +191,7 @@ main (int argc, char **argv) ADD_IPUZ_TEST (test_invalid_intersection_ipuz, invalid-intersection.ipuz); ADD_IPUZ_TEST (test_dense_ipuz, dense.ipuz); ADD_IPUZ_TEST (test_block_cells_ipuz, block-cells.ipuz); + ADD_IPUZ_TEST (test_rebus_ipuz, rebus.ipuz); return g_test_run (); } diff --git a/src/tests/clue-matches/rebus.ipuz b/src/tests/clue-matches/rebus.ipuz new file mode 100644 index 00000000..b0dd7534 --- /dev/null +++ b/src/tests/clue-matches/rebus.ipuz @@ -0,0 +1,106 @@ +{ + "kind" : [ + "http://ipuz.org/crossword#1" + ], + "version" : "http://ipuz.org/v2", + "title" : "My Crossword-1", + "charset-str" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "origin" : "GNOME Crosswords Editor (0.3.16)", + "block" : "#", + "empty" : "0", + "dimensions" : { + "width" : 4, + "height" : 4 + }, + "puzzle" : [ + [ + 1, + 2, + 3, + 4 + ], + [ + 5, + 0, + 0, + 0 + ], + [ + 6, + 0, + 0, + 0 + ], + [ + 7, + 0, + 0, + 0 + ] + ], + "solution" : [ + [ + "R", + "E", + null, + "US" + ], + [ + null, + null, + "ANA", + null + ], + [ + null, + null, + "N", + null + ], + [ + null, + null, + null, + null + ] + ], + "showenumerations" : false, + "clues" : { + "Across:Across" : [ + [ + 1, + null + ], + [ + 5, + null + ], + [ + 6, + null + ], + [ + 7, + null + ] + ], + "Down:Down" : [ + [ + 1, + null + ], + [ + 2, + null + ], + [ + 3, + null + ], + [ + 4, + null + ] + ] + } +} \ No newline at end of file -- GitLab From feb4d074cc6b8b86a61a114ca0af981e32facff1 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 01:04:30 -0400 Subject: [PATCH 21/23] Add test_null_cells_ipuz() --- src/clue-matches-tests.c | 8 ++ src/tests/clue-matches/null-cells.ipuz | 106 +++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/tests/clue-matches/null-cells.ipuz diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 46ea0d5d..92d7ae37 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -164,6 +164,13 @@ test_block_cells_ipuz (Fixture *fixture, gconstpointer user_data) ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 0, "AXES", "AXIS"); } +static void +test_null_cells_ipuz (Fixture *fixture, gconstpointer user_data) +{ + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 0, "ADD", "AID", "AND", "AMD"); + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 0, "AXES", "AXIS"); +} + static void test_rebus_ipuz (Fixture *fixture, gconstpointer user_data) { @@ -191,6 +198,7 @@ main (int argc, char **argv) ADD_IPUZ_TEST (test_invalid_intersection_ipuz, invalid-intersection.ipuz); ADD_IPUZ_TEST (test_dense_ipuz, dense.ipuz); ADD_IPUZ_TEST (test_block_cells_ipuz, block-cells.ipuz); + ADD_IPUZ_TEST (test_null_cells_ipuz, null-cells.ipuz); ADD_IPUZ_TEST (test_rebus_ipuz, rebus.ipuz); return g_test_run (); diff --git a/src/tests/clue-matches/null-cells.ipuz b/src/tests/clue-matches/null-cells.ipuz new file mode 100644 index 00000000..6987dfd4 --- /dev/null +++ b/src/tests/clue-matches/null-cells.ipuz @@ -0,0 +1,106 @@ +{ + "kind" : [ + "http://ipuz.org/crossword#1" + ], + "version" : "http://ipuz.org/v2", + "title" : "My Crossword-1", + "charset-str" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "origin" : "GNOME Crosswords Editor (0.3.16)", + "block" : "#", + "empty" : "0", + "dimensions" : { + "width" : 4, + "height" : 4 + }, + "puzzle" : [ + [ + 1, + 0, + 2, + null + ], + [ + 0, + null, + 3, + 4 + ], + [ + 5, + 6, + null, + 0 + ], + [ + 7, + 0, + null, + 0 + ] + ], + "solution" : [ + [ + "A", + null, + "D", + null + ], + [ + "X", + null, + null, + null + ], + [ + null, + null, + null, + null + ], + [ + "S", + null, + null, + null + ] + ], + "showenumerations" : false, + "clues" : { + "Across:Across" : [ + [ + 1, + null + ], + [ + 3, + null + ], + [ + 5, + null + ], + [ + 7, + null + ] + ], + "Down:Down" : [ + [ + 1, + null + ], + [ + 2, + null + ], + [ + 4, + null + ], + [ + 6, + null + ] + ] + } +} \ No newline at end of file -- GitLab From 317bb8c42b0aba85b65babdcb2e4fadb10b3e76b Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 01:12:48 -0400 Subject: [PATCH 22/23] Add test_duplicate_words_ipuz() --- src/clue-matches-tests.c | 9 ++ src/tests/clue-matches/duplicate-words.ipuz | 106 ++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 src/tests/clue-matches/duplicate-words.ipuz diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 92d7ae37..204f1beb 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -178,6 +178,15 @@ test_rebus_ipuz (Fixture *fixture, gconstpointer user_data) ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_DOWN, 2, "BANANA", "MANANA"); } +/* FIXME(tests): See https://gitlab.gnome.org/jrb/crosswords/-/issues/313. +static void +test_duplicate_words_ipuz (Fixture *fixture, gconstpointer user_data) +{ + ASSERT_CLUE_MATCHES (IPUZ_CLUE_DIRECTION_ACROSS, 0, "ZERO"); + ASSERT_CLUE_MATCHES_EMPTY (IPUZ_CLUE_DIRECTION_DOWN, 0); +} +*/ + #define ADD_IPUZ_TEST(test_name, file_name) \ g_test_add ("/clue_matches/" #test_name, \ Fixture, \ diff --git a/src/tests/clue-matches/duplicate-words.ipuz b/src/tests/clue-matches/duplicate-words.ipuz new file mode 100644 index 00000000..75ebc9c8 --- /dev/null +++ b/src/tests/clue-matches/duplicate-words.ipuz @@ -0,0 +1,106 @@ +{ + "kind" : [ + "http://ipuz.org/crossword#1" + ], + "version" : "http://ipuz.org/v2", + "title" : "My Crossword-1", + "charset-str" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + "origin" : "GNOME Crosswords Editor (0.3.16)", + "block" : "#", + "empty" : "0", + "dimensions" : { + "width" : 4, + "height" : 4 + }, + "puzzle" : [ + [ + 1, + 2, + 3, + 4 + ], + [ + 5, + 0, + 0, + 0 + ], + [ + 6, + 0, + 0, + 0 + ], + [ + 7, + 0, + 0, + 0 + ] + ], + "solution" : [ + [ + "Z", + "E", + "R", + "O" + ], + [ + "E", + null, + null, + null + ], + [ + "R", + null, + null, + null + ], + [ + null, + null, + null, + null + ] + ], + "showenumerations" : false, + "clues" : { + "Across:Across" : [ + [ + 1, + null + ], + [ + 5, + null + ], + [ + 6, + null + ], + [ + 7, + null + ] + ], + "Down:Down" : [ + [ + 1, + null + ], + [ + 2, + null + ], + [ + 3, + null + ], + [ + 4, + null + ] + ] + } +} \ No newline at end of file -- GitLab From 314ca21fcf038d0bd7b136e318ed6425055d76ce Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 24 Sep 2025 01:24:26 -0400 Subject: [PATCH 23/23] Revert "Merge branch 'wa-print' into more-tests" This reverts commit dcc0b07f120a805f60bbf84034040ed190847663, reversing changes made to 363d8fc7cfd74d92cda735a5e546407e0c307cc1. --- src/clue-matches-tests.c | 1 - src/word-list-misc.c | 44 ++++++++++++++++++++++++++++ src/word-list-misc.h | 2 ++ src/word-list.c | 62 +--------------------------------------- src/word-list.h | 6 +--- 5 files changed, 48 insertions(+), 67 deletions(-) diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 204f1beb..dc283545 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -22,7 +22,6 @@ #include #include "crosswords-misc.h" #include "clue-matches.h" -#include "word-list.c" #include "word-list-test-utils.h" #include "test-utils.h" diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 8ed4faf7..024417e4 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -339,6 +339,50 @@ word_array_equals (WordArray *word_array1, WordArray *word_array2) return TRUE; } +static void +word_index_print (WordIndex word_index) +{ + g_message ("\t(index: %2d, length: %2d)", + word_index.index, + word_index.length); +} + +#define MAX_WORDS 10 +static void +word_array_print_helper (WordArray *word_array) +{ + /* FIXME(debugging): Print first 5 and last 5 words instead of first 10. */ + for (guint i = 0; i < MIN (word_array->len, MAX_WORDS); i++) + { + WordIndex word_index = word_array_index (word_array, i); + word_index_print (word_index); + } +} + +void +word_array_print (WordArray *word_array) +{ + if (word_array == NULL) + { + g_warning ("word_array_print: WordArray is NULL."); + return; + } + g_message ("WordArray %p:", word_array); + word_array_print_helper (word_array); +} + +void +word_set_print (WordSet *word_set) +{ + if (word_set == NULL) + { + g_warning ("word_set_print: WordSet is NULL."); + return; + } + g_message ("WordSet %p:", word_set); + word_array_print_helper (word_set_to_array (word_set)); +} + gboolean word_index_equals (WordIndex word_index1, WordIndex word_index2) diff --git a/src/word-list-misc.h b/src/word-list-misc.h index dd085106..50536cf6 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -111,6 +111,7 @@ gboolean word_array_find (WordArray *word_array, void word_array_sort (WordArray *word_array); gboolean word_array_equals (WordArray *word_array1, WordArray *word_array2); +void word_array_print (WordArray *word_array); #define word_array_len(wa) (((GArray*)wa)->len) #define word_array_index(wa,i) (g_array_index((GArray*)wa,WordIndex,i)) @@ -125,6 +126,7 @@ void word_set_remove_unique (WordSet *word_set1, void word_set_add_array (WordSet *word_set, WordArray *word_array); WordArray *word_set_to_array (WordSet *word_set); +void word_set_print (WordSet *word_set); #define word_set_add(ws,wi) (g_hash_table_add(ws,wi)) diff --git a/src/word-list.c b/src/word-list.c index bbc7e63d..a88fe93a 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1527,64 +1527,4 @@ word_list_find_intersection (WordList *word_list, *intersecting_chars = ipuz_charset_ref (charset2); PUSH_TIMER ("word_list_find_intersection()"); -} - - -#ifdef DEVELOPMENT_BUILD - -#define MAX_WORDS 10 -#define HALF_MAX MAX_WORDS / 2 -static void -word_array_print_helper (WordList *word_list, WordArray *word_array) -{ - g_assert (word_array != NULL); - - const guint len = word_array_len (word_array); - const guint first_loop_end = MIN (HALF_MAX - 1, len - 1); - const guint second_loop_start = MAX (first_loop_end + 1, len - HALF_MAX); - const guint second_loop_end = len - 1; - - if (len == 0) - return; - - for (guint i = 0; i <= first_loop_end; i++) - { - WordIndex word_index = word_array_index (word_array, i); - g_message ("\t%s", word_list_get_indexed_word (word_list, word_index)); - } - - if (first_loop_end == len - 1) - return; - else if (second_loop_start != first_loop_end + 1) - g_message ("\t..."); - - for (guint i = second_loop_start; i <= second_loop_end; i++) - { - WordIndex word_index = word_array_index (word_array, i); - g_message ("\t%s", word_list_get_indexed_word (word_list, word_index)); - } -} - -void word_list_print_word_array (WordList *word_list, WordArray *word_array) -{ - if (word_array == NULL) - { - g_warning ("word_list_print_word_array: WordArray is NULL."); - return; - } - g_message ("WordArray %p:", word_array); - word_array_print_helper (word_list, word_array); -} - -void word_list_print_word_set (WordList *word_list, WordSet *word_set) -{ - if (word_set == NULL) - { - g_warning ("word_list_print_word_set: WordSet is NULL."); - return; - } - g_message ("WordSet %p:", word_set); - word_array_print_helper (word_list, word_set_to_array (word_set)); -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/word-list.h b/src/word-list.h index 4311ff10..8d49c763 100644 --- a/src/word-list.h +++ b/src/word-list.h @@ -108,11 +108,7 @@ void word_list_find_intersection (WordList *word WordArray **filter2_words); -/* Debugging functions */ -void word_list_print_word_array (WordList *word_list, - WordArray *word_array); -void word_list_print_word_set (WordList *word_list, - WordSet *word_set); + G_END_DECLS -- GitLab