From 2d5fe3cd7c76a98f4ff9007c946785ba38e0cd17 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 9 Jun 2025 19:05:16 -0400 Subject: [PATCH 01/23] Remove comment about WordArray being auto-sorted --- src/word-list-misc.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/word-list-misc.h b/src/word-list-misc.h index 180a803e..7436b348 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -75,15 +75,15 @@ gchar *scored_parse_word (const gchar *unparsed_word, IpuzCharset *alphabet); -/* WordArrays are a simple list of words represented as +/* A WordArray is a simple list of words represented as * WordIndex. They are unique: inserting a word multiple times results - * in the word only existing once, and the array is always sorted. It - * is used to keep a list of words we don't want to search through, as - * well as used internally within the word-list. + * in the word only existing once. It is used to keep a list of words + * we don't want to search through, as well as used internally within + * the word-list. * * It's possible to use the GArray functions instead of the WordArray - * functions, but if you do that, you need to keep the - * uniqueness/sorted invariant true. The WordList does this directly + * functions. But if you do that, you need to manually keep the + * uniqueness invariant true. The WordList does this directly * at times. * * It's not recommended that you use this structure unless you really -- GitLab From 198bd45bf3da1b955d626a7bea44443e22577f74 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 9 Jun 2025 19:08:43 -0400 Subject: [PATCH 02/23] Add skeleton for word_array_sort --- src/word-list-misc.c | 6 ++++++ src/word-list-misc.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 7eaa2cfc..599bbcc1 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -306,6 +306,12 @@ word_array_find (WordArray *word_array, out); } +void +word_array_sort (WordArray *word_array) +{ + return; +} + #ifdef TESTING static void computes_letters_size (void) diff --git a/src/word-list-misc.h b/src/word-list-misc.h index 7436b348..f2a65a3c 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -102,6 +102,7 @@ gboolean word_array_remove (WordArray *word_array, gboolean word_array_find (WordArray *word_array, WordIndex word_index, guint *out); +void word_array_sort (WordArray *word_array); #define word_array_len(wa) (((GArray*)wa)->len) #define word_array_index(wa,i) (g_array_index((GArray*)wa,WordIndex,i)) #define word_array_ref(wa) (g_array_ref((GArray*)wa)) -- GitLab From a0c558a237d0cfbaf7dc137009b4e9255aec25fc Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 9 Jun 2025 20:39:47 -0400 Subject: [PATCH 03/23] Add debugging code --- src/edit-word-list.c | 5 +++++ src/word-list-misc.c | 11 +++++++++-- src/word-list-misc.h | 2 +- src/word-list.c | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/edit-word-list.c b/src/edit-word-list.c index a9462eab..06b2f6ad 100644 --- a/src/edit-word-list.c +++ b/src/edit-word-list.c @@ -361,6 +361,11 @@ edit_word_list_recalculate (EditWordList *self) &intersecting_chars, &across_array, &down_array); + for (guint i=0; i < across_array->len; i++) + { + g_print("%d ", g_array_index(across_array, WordIndex, i).index); + } + g_print("\n"); word_array_model_set_array (self->across_list_model, across_array); word_array_model_set_array (self->down_list_model, down_array); gtk_filter_changed (self->filter, GTK_FILTER_CHANGE_DIFFERENT); diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 599bbcc1..580ef1ce 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -306,10 +306,17 @@ word_array_find (WordArray *word_array, out); } +static gint +word_array_comparator (gconstpointer a, + gconstpointer b) +{ + return (rand() % 3) - 1; +} + void -word_array_sort (WordArray *word_array) +word_array_sortt (WordArray *word_array) { - return; + g_array_sort ((GArray *) word_array, word_array_comparator); } #ifdef TESTING diff --git a/src/word-list-misc.h b/src/word-list-misc.h index f2a65a3c..aa806b74 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -102,7 +102,7 @@ gboolean word_array_remove (WordArray *word_array, gboolean word_array_find (WordArray *word_array, WordIndex word_index, guint *out); -void word_array_sort (WordArray *word_array); +void word_array_sortt (WordArray *word_array); #define word_array_len(wa) (((GArray*)wa)->len) #define word_array_index(wa,i) (g_array_index((GArray*)wa,WordIndex,i)) #define word_array_ref(wa) (g_array_ref((GArray*)wa)) diff --git a/src/word-list.c b/src/word-list.c index 8ed77beb..baf77643 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1505,6 +1505,9 @@ word_list_find_intersection (WordList *word_list, charset2, word_array1?*word_array1:NULL); + word_array_sortt (*word_array1); + word_array_sortt (*word_array2); + /* copy our charset over to intersecting_chars */ if (intersecting_chars) *intersecting_chars = ipuz_charset_ref (charset2); -- GitLab From ba42da8872cc97099b274d04d87dffc2a4b9fea6 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 9 Jun 2025 20:46:16 -0400 Subject: [PATCH 04/23] Fix name conflict --- src/gen-word-list.c | 6 +++--- src/word-list-misc.c | 2 +- src/word-list-misc.h | 2 +- src/word-list.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gen-word-list.c b/src/gen-word-list.c index d3c4a868..fffd0a65 100644 --- a/src/gen-word-list.c +++ b/src/gen-word-list.c @@ -351,8 +351,8 @@ gen_word_list_remove_duplicates (GenWordList *word_list) } static gint -word_array_sort (gconstpointer a, - gconstpointer b) +word_entry_comparator (gconstpointer a, + gconstpointer b) { WordEntry *entry_a = (WordEntry *)a; WordEntry *entry_b = (WordEntry *)b; @@ -367,7 +367,7 @@ word_array_sort (gconstpointer a, void gen_word_list_sort (GenWordList *word_list) { - g_array_sort (word_list->words, (GCompareFunc) word_array_sort); + g_array_sort (word_list->words, (GCompareFunc) word_entry_comparator); /* Enumerations are pre-sorted from the dupe removal */ #if 0 for (uint i = 0; i < word_list->words->len; i++) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 580ef1ce..686fe7cf 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -314,7 +314,7 @@ word_array_comparator (gconstpointer a, } void -word_array_sortt (WordArray *word_array) +word_array_sort (WordArray *word_array) { g_array_sort ((GArray *) word_array, word_array_comparator); } diff --git a/src/word-list-misc.h b/src/word-list-misc.h index aa806b74..f2a65a3c 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -102,7 +102,7 @@ gboolean word_array_remove (WordArray *word_array, gboolean word_array_find (WordArray *word_array, WordIndex word_index, guint *out); -void word_array_sortt (WordArray *word_array); +void word_array_sort (WordArray *word_array); #define word_array_len(wa) (((GArray*)wa)->len) #define word_array_index(wa,i) (g_array_index((GArray*)wa,WordIndex,i)) #define word_array_ref(wa) (g_array_ref((GArray*)wa)) diff --git a/src/word-list.c b/src/word-list.c index baf77643..c2a30bc3 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1505,8 +1505,8 @@ word_list_find_intersection (WordList *word_list, charset2, word_array1?*word_array1:NULL); - word_array_sortt (*word_array1); - word_array_sortt (*word_array2); + word_array_sort (*word_array1); + word_array_sort (*word_array2); /* copy our charset over to intersecting_chars */ if (intersecting_chars) -- GitLab From 6e0672dcd3b16b2b4fcd488141f6480b0b8fef7f Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 9 Jun 2025 20:59:14 -0400 Subject: [PATCH 05/23] Sort WordArray by index --- src/word-list-misc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 686fe7cf..c2c40cfb 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -310,7 +310,10 @@ static gint word_array_comparator (gconstpointer a, gconstpointer b) { - return (rand() % 3) - 1; + gint index_a = ((WordIndex *) a)->index; + gint index_b = ((WordIndex *) b)->index; + + return index_a - index_b; } void -- GitLab From d1fa48d69f79bc982f6683f163bc93d773ede58e Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 9 Jun 2025 22:07:02 -0400 Subject: [PATCH 06/23] Add order checking function for tests --- src/word-list-tests.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index d52191a9..9fc37475 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -254,6 +254,26 @@ utf8_roundtrip (void) #endif +static gboolean +word_array_is_sorted (WordArray *word_array) +{ + gint prev_index; + gint curr_index; + WordIndex *current; + + current = g_array_index (word_array, WordIndex*, 0); + prev_index = current->index; + for (guint i = 1; i < word_array->len; i++) + { + current = g_array_index (word_array, WordIndex*, i); + curr_index = current->index; + if (curr_index < prev_index) + return FALSE; + prev_index = curr_index; + } + return TRUE; +} + static void anagram_test (void) { -- GitLab From dac8d66d09183e74c5720f4b71c0c2b401ef16ad Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 10 Jun 2025 21:50:20 -0400 Subject: [PATCH 07/23] Begin work on equivalent_intersection_test --- src/word-list-tests.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 9fc37475..412c0bdf 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -274,6 +274,12 @@ word_array_is_sorted (WordArray *word_array) return TRUE; } +static void +check_word_array_order (WordArray *word_array) +{ + g_assert (word_array_is_sorted (word_array)); +} + static void anagram_test (void) { @@ -295,7 +301,7 @@ anagram_test (void) //#define DEBUG_INTERSECTION static void -intersection_test (WordList *wl, +intersection_test (WordList *wl, const gchar *filter1, guint pos1, const gchar *filter2, @@ -347,7 +353,24 @@ intersection_test (WordList *wl, } #endif g_assert_cmpstr (intersection_str, ==, charset_str); + check_word_array_order (word_array1); + check_word_array_order (word_array2); +} +static void +equivalent_intersection_test (WordList *wl, + const gchar *filter) +{ + const gchar* crossing_filter = g_strnfill (strlen (filter), '?'); + g_autoptr (WordArray) previous_words = NULL; + g_autoptr (WordArray) current_words = NULL; + for (const gchar *cell = filter; *cell; cell++) + { + if (*cell == '?') + { + word_list_find_intersection (wl, filter1, ) + } + } } static void -- GitLab From 4cd6fa0edbbc5592b73d7ee21b99aaca7221a98b Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 10 Jun 2025 22:08:22 -0400 Subject: [PATCH 08/23] Add word_array_equals --- src/word-list-misc.c | 18 ++++++++++++++++-- src/word-list-misc.h | 2 ++ src/word-list-tests.c | 14 +++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index c2c40cfb..80b912d0 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -307,7 +307,7 @@ word_array_find (WordArray *word_array, } static gint -word_array_comparator (gconstpointer a, +word_index_comparator (gconstpointer a, gconstpointer b) { gint index_a = ((WordIndex *) a)->index; @@ -319,7 +319,21 @@ word_array_comparator (gconstpointer a, void word_array_sort (WordArray *word_array) { - g_array_sort ((GArray *) word_array, word_array_comparator); + g_array_sort ((GArray *) word_array, word_index_comparator); +} + +gboolean +word_array_equals (WordArray *word_array1, WordArray *word_array2) +{ + if (word_array1->len != word_array2->len) + return FALSE; + while () + { + if ((((WordIndex *) word_array1++)->index + != (WordIndex *) word_array2++)->index) + return FALSE; + } + return TRUE; } #ifdef TESTING diff --git a/src/word-list-misc.h b/src/word-list-misc.h index f2a65a3c..581d0f35 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -103,6 +103,8 @@ gboolean word_array_find (WordArray *word_array, WordIndex word_index, guint *out); void word_array_sort (WordArray *word_array); +gboolean word_array_equals (WordArray *word_array1, + WordArray *word_array2); #define word_array_len(wa) (((GArray*)wa)->len) #define word_array_index(wa,i) (g_array_index((GArray*)wa,WordIndex,i)) #define word_array_ref(wa) (g_array_ref((GArray*)wa)) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 412c0bdf..8282a40e 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -362,13 +362,21 @@ equivalent_intersection_test (WordList *wl, const gchar *filter) { const gchar* crossing_filter = g_strnfill (strlen (filter), '?'); - g_autoptr (WordArray) previous_words = NULL; - g_autoptr (WordArray) current_words = NULL; + g_autoptr (WordArray) prev_word_array = NULL; + g_autoptr (WordArray) curr_word_array = NULL; for (const gchar *cell = filter; *cell; cell++) { if (*cell == '?') { - word_list_find_intersection (wl, filter1, ) + word_list_find_intersection (wl, + filter, pos, + crossing_filter, pos, + NULL, + curr_word_array, + NULL); + if (prev_word_array == NULL) + prev_word_array = curr_word_array; + else } } } -- GitLab From 0324568d8db48c11d425c883e72d8e54824ac665 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 10 Jun 2025 22:17:43 -0400 Subject: [PATCH 09/23] Finish equivalent test function --- src/word-list-misc.c | 6 +++--- src/word-list-tests.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 80b912d0..b598c6ce 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -327,10 +327,10 @@ word_array_equals (WordArray *word_array1, WordArray *word_array2) { if (word_array1->len != word_array2->len) return FALSE; - while () + while (TRUE) { - if ((((WordIndex *) word_array1++)->index - != (WordIndex *) word_array2++)->index) + if (((WordIndex *) word_array1++)->index + != ((WordIndex *) word_array2++)->index) return FALSE; } return TRUE; diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 8282a40e..1fdc36bc 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -369,14 +369,15 @@ equivalent_intersection_test (WordList *wl, if (*cell == '?') { word_list_find_intersection (wl, - filter, pos, - crossing_filter, pos, + filter, 0, + crossing_filter, 0, NULL, - curr_word_array, + &curr_word_array, NULL); if (prev_word_array == NULL) prev_word_array = curr_word_array; else + g_assert(word_array_equals (curr_word_array, prev_word_array)); } } } -- GitLab From be95a3905dbffdcefb062ceb94161bff923139d5 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 10 Jun 2025 23:34:45 -0400 Subject: [PATCH 10/23] Add test running function --- src/word-list-tests.c | 64 ++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 1fdc36bc..4d63adcb 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -357,31 +357,6 @@ intersection_test (WordList *wl, check_word_array_order (word_array2); } -static void -equivalent_intersection_test (WordList *wl, - const gchar *filter) -{ - const gchar* crossing_filter = g_strnfill (strlen (filter), '?'); - g_autoptr (WordArray) prev_word_array = NULL; - g_autoptr (WordArray) curr_word_array = NULL; - for (const gchar *cell = filter; *cell; cell++) - { - if (*cell == '?') - { - word_list_find_intersection (wl, - filter, 0, - crossing_filter, 0, - NULL, - &curr_word_array, - NULL); - if (prev_word_array == NULL) - prev_word_array = curr_word_array; - else - g_assert(word_array_equals (curr_word_array, prev_word_array)); - } - } -} - static void find_intersection (void) { @@ -415,6 +390,45 @@ find_intersection (void) "AELRT"); } +static void +equivalent_intersection_test (WordList *wl, + const gchar *filter) +{ + const gchar* crossing_filter = g_strnfill (strlen (filter), '?'); + g_autoptr (WordArray) prev_word_array = NULL; + g_autoptr (WordArray) curr_word_array = NULL; + + for (guint i = 0; i < strlen (filter); i++) + { + if (filter[i] == '?') + { + word_list_find_intersection (wl, + filter, i, + crossing_filter, 0, + NULL, + &curr_word_array, + NULL); + if (prev_word_array == NULL) + prev_word_array = curr_word_array; + else + g_assert(word_array_equals (curr_word_array, prev_word_array)); + } + } +} + +static void +equivalent_intersections (void) +{ + g_autoptr (WordList) wl = get_test_word_list (); + equivalent_intersection_test (wl, "??"); + equivalent_intersection_test (wl, "???"); + equivalent_intersection_test (wl, "??????????????"); + equivalent_intersection_test (wl, "A??"); + equivalent_intersection_test (wl, "?A?"); + equivalent_intersection_test (wl, "??A"); + equivalent_intersection_test (wl, "???A???A???A???"); +} + #define EPSILON 0.001 static void -- GitLab From b917e1631edf8d446ab56e7d9da2c270835a7765 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 11 Jun 2025 08:05:42 -0400 Subject: [PATCH 11/23] Handle different cases in intersection function --- src/word-list-misc.c | 14 ++++++++++++++ src/word-list-tests.c | 11 ++++++----- src/word-list.c | 4 ++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index b598c6ce..16bf1cf8 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -316,9 +316,23 @@ word_index_comparator (gconstpointer a, return index_a - index_b; } +// TODO: REMOVE +static void +word_array_print (WordArray *word_array) +{ + WordIndex current; + for (guint i = 0; i < word_array->len; i++) + { + current = g_array_index (word_array, WordIndex, 0); + g_message ("%d", current.index); + } +} + void word_array_sort (WordArray *word_array) { + if (word_array == NULL) + return; g_array_sort ((GArray *) word_array, word_index_comparator); } diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 4d63adcb..e46ff2e8 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -259,14 +259,14 @@ word_array_is_sorted (WordArray *word_array) { gint prev_index; gint curr_index; - WordIndex *current; + WordIndex current; - current = g_array_index (word_array, WordIndex*, 0); - prev_index = current->index; + current = g_array_index (word_array, WordIndex, 0); + prev_index = current.index; for (guint i = 1; i < word_array->len; i++) { - current = g_array_index (word_array, WordIndex*, i); - curr_index = current->index; + current = g_array_index (word_array, WordIndex, i); + curr_index = current.index; if (curr_index < prev_index) return FALSE; prev_index = curr_index; @@ -277,6 +277,7 @@ word_array_is_sorted (WordArray *word_array) static void check_word_array_order (WordArray *word_array) { + word_array_sort (word_array); // TODO: REMOVE g_assert (word_array_is_sorted (word_array)); } diff --git a/src/word-list.c b/src/word-list.c index c2a30bc3..a04fa3ee 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1278,6 +1278,8 @@ calculate_intersect_special (WordList *word_list, ipuz_charset_builder_set_char_count (builder, c, filter1_len * filter2_len); *intersecting_chars = ipuz_charset_builder_build (builder); } + word_array_sort (*word_array1); + word_array_sort (*word_array2); } @@ -1461,6 +1463,7 @@ word_list_find_intersection (WordList *word_list, word_array1?*word_array1:NULL); if (intersecting_chars) *intersecting_chars = ipuz_charset_ref (charset1); + word_array_sort (*word_array1); } else if (filter2_valid) { @@ -1471,6 +1474,7 @@ word_list_find_intersection (WordList *word_list, word_array2?*word_array2:NULL); if (intersecting_chars) *intersecting_chars = ipuz_charset_ref (charset2); + word_array_sort (*word_array2); } return; -- GitLab From f295125309893607af4ea9db591d4fa1c6a09e09 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 11 Jun 2025 08:34:48 -0400 Subject: [PATCH 12/23] Fix is_sorted function --- src/word-list-misc.c | 11 ++++++++--- src/word-list-misc.h | 2 ++ src/word-list-tests.c | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 16bf1cf8..0fd65957 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -316,15 +316,20 @@ word_index_comparator (gconstpointer a, return index_a - index_b; } -// TODO: REMOVE -static void +void word_array_print (WordArray *word_array) { + if (word_array == NULL) + { + g_message ("WordArray is NULL."); + return; + } WordIndex current; + g_message ("WordArray %p:", word_array); for (guint i = 0; i < word_array->len; i++) { current = g_array_index (word_array, WordIndex, 0); - g_message ("%d", current.index); + g_message ("\t%d", current.index); } } diff --git a/src/word-list-misc.h b/src/word-list-misc.h index 581d0f35..fa3b6877 100644 --- a/src/word-list-misc.h +++ b/src/word-list-misc.h @@ -105,6 +105,8 @@ 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)) #define word_array_ref(wa) (g_array_ref((GArray*)wa)) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index e46ff2e8..aa6c9354 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -261,9 +261,12 @@ word_array_is_sorted (WordArray *word_array) gint curr_index; WordIndex current; + if (word_array == NULL || word_array->len == 0) + return TRUE; + current = g_array_index (word_array, WordIndex, 0); prev_index = current.index; - for (guint i = 1; i < word_array->len; i++) + for (guint i = 0; i < word_array->len; i++) { current = g_array_index (word_array, WordIndex, i); curr_index = current.index; @@ -277,7 +280,6 @@ word_array_is_sorted (WordArray *word_array) static void check_word_array_order (WordArray *word_array) { - word_array_sort (word_array); // TODO: REMOVE g_assert (word_array_is_sorted (word_array)); } @@ -354,8 +356,13 @@ intersection_test (WordList *wl, } #endif g_assert_cmpstr (intersection_str, ==, charset_str); + g_message ("FIRST..."); check_word_array_order (word_array1); + g_message ("FIRST DONE!"); + g_message ("SECOND..."); + word_array_print (word_array2); check_word_array_order (word_array2); + g_message ("SECOND DONE!"); } static void -- GitLab From 99b0fc9c9354d74897ce45d6244f28daeb1ff5d5 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Wed, 11 Jun 2025 11:34:00 -0400 Subject: [PATCH 13/23] Do null check before calling sort function --- src/word-list-tests.c | 42 +++++++++++++++++++----------------------- src/word-list.c | 26 ++++++++++++++++++++------ 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index aa6c9354..03ab8700 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -277,12 +277,6 @@ word_array_is_sorted (WordArray *word_array) return TRUE; } -static void -check_word_array_order (WordArray *word_array) -{ - g_assert (word_array_is_sorted (word_array)); -} - static void anagram_test (void) { @@ -356,13 +350,9 @@ intersection_test (WordList *wl, } #endif g_assert_cmpstr (intersection_str, ==, charset_str); - g_message ("FIRST..."); - check_word_array_order (word_array1); - g_message ("FIRST DONE!"); - g_message ("SECOND..."); - word_array_print (word_array2); - check_word_array_order (word_array2); - g_message ("SECOND DONE!"); + g_assert (word_array_is_sorted (word_array1)); + // word_array_print (word_array2); + g_assert (word_array_is_sorted (word_array2)); } static void @@ -399,23 +389,28 @@ find_intersection (void) } static void -equivalent_intersection_test (WordList *wl, - const gchar *filter) +equivalent_intersections_test (WordList *wl, + const gchar *filter) { - const gchar* crossing_filter = g_strnfill (strlen (filter), '?'); + const gchar* crossing_filter; g_autoptr (WordArray) prev_word_array = NULL; g_autoptr (WordArray) curr_word_array = NULL; + crossing_filter = g_strnfill (strlen (filter), '?'); + + // g_utf8_next_char? for (guint i = 0; i < strlen (filter); i++) { if (filter[i] == '?') { + g_message ("%d", i); word_list_find_intersection (wl, filter, i, crossing_filter, 0, NULL, &curr_word_array, NULL); + g_message ("after"); if (prev_word_array == NULL) prev_word_array = curr_word_array; else @@ -428,13 +423,13 @@ static void equivalent_intersections (void) { g_autoptr (WordList) wl = get_test_word_list (); - equivalent_intersection_test (wl, "??"); - equivalent_intersection_test (wl, "???"); - equivalent_intersection_test (wl, "??????????????"); - equivalent_intersection_test (wl, "A??"); - equivalent_intersection_test (wl, "?A?"); - equivalent_intersection_test (wl, "??A"); - equivalent_intersection_test (wl, "???A???A???A???"); + equivalent_intersections_test (wl, "??"); + // equivalent_intersections_test (wl, "???"); + // equivalent_intersections_test (wl, "??????????????"); + // equivalent_intersections_test (wl, "A??"); + // equivalent_intersections_test (wl, "?A?"); + // equivalent_intersections_test (wl, "??A"); + // equivalent_intersections_test (wl, "???A???A???A???"); } #define EPSILON 0.001 @@ -520,6 +515,7 @@ main (int argc, char **argv) g_test_add_func ("/word_list/set_anagram", anagram_test); g_test_add_func ("/word_list/find_intersection", find_intersection); + g_test_add_func ("/word_list/equivalent_intersections", equivalent_intersections); g_test_add_func ("/word_list/frequency_test", frequency_test); #ifdef PROFILE_TEST diff --git a/src/word-list.c b/src/word-list.c index a04fa3ee..2c310324 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -433,8 +433,10 @@ validate_filter (WordList *self, filter_len > self->index->max_length) return FALSE; + g_message ("halfway"); for (ptr = filter; ptr[0] != '\0'; ptr = g_utf8_next_char (ptr)) { + // g_message ("%ld", ptr - filter); gunichar c; gint index; @@ -1028,6 +1030,15 @@ word_list_dump (WordList *word_list) } +static void +sort_word_arrays (WordArray **word_array1, + WordArray **word_array2) +{ + word_array_sort (word_array1 ? *word_array1 : NULL); + word_array_sort (word_array2 ? *word_array2 : NULL); +} + + static GArray * get_filter_intersect_list (WordList *word_list, const gchar *filter) @@ -1278,8 +1289,7 @@ calculate_intersect_special (WordList *word_list, ipuz_charset_builder_set_char_count (builder, c, filter1_len * filter2_len); *intersecting_chars = ipuz_charset_builder_build (builder); } - word_array_sort (*word_array1); - word_array_sort (*word_array2); + sort_word_arrays (word_array1, word_array2); } @@ -1440,6 +1450,7 @@ word_list_find_intersection (WordList *word_list, * on the 'C' character. In this instance, we just */ if (!g_utf8_strchr (WORD_LIST_CHAR_WILDCARDS, -1, c1)) { + g_message ("special case"); calculate_intersect_special (word_list, filter1, filter2, filter1_valid, filter2_valid, @@ -1454,6 +1465,7 @@ word_list_find_intersection (WordList *word_list, * both the word_list and charset, so we can reuse it for this */ if (!filter1_valid || !filter2_valid) { + g_message ("one invalid"); if (filter1_valid) { charset1 = calculate_intersect_phase2 (word_list, @@ -1463,7 +1475,7 @@ word_list_find_intersection (WordList *word_list, word_array1?*word_array1:NULL); if (intersecting_chars) *intersecting_chars = ipuz_charset_ref (charset1); - word_array_sort (*word_array1); + sort_word_arrays (word_array1, word_array2); } else if (filter2_valid) { @@ -1474,7 +1486,7 @@ word_list_find_intersection (WordList *word_list, word_array2?*word_array2:NULL); if (intersecting_chars) *intersecting_chars = ipuz_charset_ref (charset2); - word_array_sort (*word_array2); + sort_word_arrays (word_array1, word_array2); } return; @@ -1488,12 +1500,14 @@ word_list_find_intersection (WordList *word_list, /* Phase 1: Calculate the set of possible characters at pos1 for * filter1. We don't need to worry about calculating the word_list * yet */ + g_message ("phase 1"); charset1 = calculate_intersect_phase1 (word_list, filter1, pos1, n_chars1); /* phase 2: Calculate the overlapping characters and the second * word_array. If necessary, calculate the second filters word_array */ + g_message ("phase 2"); charset2 = calculate_intersect_phase2 (word_list, filter2, pos2, @@ -1503,14 +1517,14 @@ word_list_find_intersection (WordList *word_list, /* phase 3: Recalculate the word_array first filter with the * overlap */ + g_message ("phase 3"); calculate_intersect_phase3 (word_list, filter1, pos1, n_chars1, charset2, word_array1?*word_array1:NULL); - word_array_sort (*word_array1); - word_array_sort (*word_array2); + sort_word_arrays (word_array1, word_array2); /* copy our charset over to intersecting_chars */ if (intersecting_chars) -- GitLab From b2dd84b60249cfa27847676873aaa50f06eed4b8 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Thu, 12 Jun 2025 05:50:39 -0400 Subject: [PATCH 14/23] Comment out debug statements --- src/edit-word-list.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/edit-word-list.c b/src/edit-word-list.c index 06b2f6ad..ca795bd7 100644 --- a/src/edit-word-list.c +++ b/src/edit-word-list.c @@ -361,10 +361,10 @@ edit_word_list_recalculate (EditWordList *self) &intersecting_chars, &across_array, &down_array); - for (guint i=0; i < across_array->len; i++) - { - g_print("%d ", g_array_index(across_array, WordIndex, i).index); - } + // for (guint i=0; i < across_array->len; i++) + // { + // g_print("%d ", g_array_index(across_array, WordIndex, i).index); + // } g_print("\n"); word_array_model_set_array (self->across_list_model, across_array); word_array_model_set_array (self->down_list_model, down_array); -- GitLab From b933ac92f52d87396dd1a0227785955575a8b9c1 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Thu, 12 Jun 2025 07:15:10 -0400 Subject: [PATCH 15/23] Fix word_array_equals function --- src/word-list-misc.c | 13 +++++++------ src/word-list-tests.c | 13 ++++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 0fd65957..054404c9 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -346,12 +346,13 @@ word_array_equals (WordArray *word_array1, WordArray *word_array2) { if (word_array1->len != word_array2->len) return FALSE; - while (TRUE) - { - if (((WordIndex *) word_array1++)->index - != ((WordIndex *) word_array2++)->index) - return FALSE; - } + for (guint i = 0; i < word_array1->len; i++) + { + gint index1 = (g_array_index (word_array1, WordIndex, i)).index; + gint index2 = (g_array_index (word_array2, WordIndex, i)).index; + if (index1 != index2) + return FALSE; + } return TRUE; } diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 03ab8700..63cb81b2 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -52,7 +52,8 @@ get_test_word_list (void) g_autoptr (WordListResource) resource = NULL; WordList *word_list = NULL; - path = g_test_build_filename (G_TEST_BUILT, TEST_RESOURCE, NULL); + // path = g_test_build_filename (G_TEST_BUILT, TEST_RESOURCE, NULL); + path = g_test_build_filename (G_TEST_BUILT, BRODA_RESOURCE, NULL); resource = word_list_resource_new_from_file (path); word_list = g_object_new (WORD_TYPE_LIST, @@ -411,6 +412,8 @@ equivalent_intersections_test (WordList *wl, &curr_word_array, NULL); g_message ("after"); + g_message ("LENGTH: %d", curr_word_array->len); + g_assert (word_array_is_sorted (curr_word_array)); if (prev_word_array == NULL) prev_word_array = curr_word_array; else @@ -506,17 +509,17 @@ main (int argc, char **argv) g_test_init (&argc, &argv, NULL); - g_test_add_func ("/word_list/loads_default", loads_default); + // g_test_add_func ("/word_list/loads_default", loads_default); #if 0 g_test_add_func ("/word_list/ascii_roundtrip", ascii_roundtrip); g_test_add_func ("/word_list/utf8_roundtrip", utf8_roundtrip); #endif - g_test_add_func ("/word_list/set_anagram", anagram_test); - g_test_add_func ("/word_list/find_intersection", find_intersection); + // g_test_add_func ("/word_list/set_anagram", anagram_test); + // g_test_add_func ("/word_list/find_intersection", find_intersection); g_test_add_func ("/word_list/equivalent_intersections", equivalent_intersections); - g_test_add_func ("/word_list/frequency_test", frequency_test); + // g_test_add_func ("/word_list/frequency_test", frequency_test); #ifdef PROFILE_TEST g_test_add_func ("/word_list/profile_test", profile_test); -- GitLab From a994840c0574b063060add5371043d65d69ec17e Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 16 Jun 2025 18:22:01 -0400 Subject: [PATCH 16/23] Clean up code --- src/edit-word-list.c | 5 ----- src/word-list-tests.c | 27 ++++++++++++--------------- src/word-list.c | 13 ++++--------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/edit-word-list.c b/src/edit-word-list.c index ca795bd7..a9462eab 100644 --- a/src/edit-word-list.c +++ b/src/edit-word-list.c @@ -361,11 +361,6 @@ edit_word_list_recalculate (EditWordList *self) &intersecting_chars, &across_array, &down_array); - // for (guint i=0; i < across_array->len; i++) - // { - // g_print("%d ", g_array_index(across_array, WordIndex, i).index); - // } - g_print("\n"); word_array_model_set_array (self->across_list_model, across_array); word_array_model_set_array (self->down_list_model, down_array); gtk_filter_changed (self->filter, GTK_FILTER_CHANGE_DIFFERENT); diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 63cb81b2..c9b7bfd7 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -52,7 +52,8 @@ get_test_word_list (void) g_autoptr (WordListResource) resource = NULL; WordList *word_list = NULL; - // path = g_test_build_filename (G_TEST_BUILT, TEST_RESOURCE, NULL); + /* FIXME(tests): Intersection function generates bad results with test word list. + * path = g_test_build_filename (G_TEST_BUILT, TEST_RESOURCE, NULL); */ path = g_test_build_filename (G_TEST_BUILT, BRODA_RESOURCE, NULL); resource = word_list_resource_new_from_file (path); @@ -352,7 +353,6 @@ intersection_test (WordList *wl, #endif g_assert_cmpstr (intersection_str, ==, charset_str); g_assert (word_array_is_sorted (word_array1)); - // word_array_print (word_array2); g_assert (word_array_is_sorted (word_array2)); } @@ -404,15 +404,12 @@ equivalent_intersections_test (WordList *wl, { if (filter[i] == '?') { - g_message ("%d", i); word_list_find_intersection (wl, filter, i, crossing_filter, 0, NULL, &curr_word_array, NULL); - g_message ("after"); - g_message ("LENGTH: %d", curr_word_array->len); g_assert (word_array_is_sorted (curr_word_array)); if (prev_word_array == NULL) prev_word_array = curr_word_array; @@ -427,12 +424,12 @@ equivalent_intersections (void) { g_autoptr (WordList) wl = get_test_word_list (); equivalent_intersections_test (wl, "??"); - // equivalent_intersections_test (wl, "???"); - // equivalent_intersections_test (wl, "??????????????"); - // equivalent_intersections_test (wl, "A??"); - // equivalent_intersections_test (wl, "?A?"); - // equivalent_intersections_test (wl, "??A"); - // equivalent_intersections_test (wl, "???A???A???A???"); + equivalent_intersections_test (wl, "???"); + equivalent_intersections_test (wl, "??????????????"); + equivalent_intersections_test (wl, "A??"); + equivalent_intersections_test (wl, "?A?"); + equivalent_intersections_test (wl, "??A"); + equivalent_intersections_test (wl, "???A???A???A???"); } #define EPSILON 0.001 @@ -509,17 +506,17 @@ main (int argc, char **argv) g_test_init (&argc, &argv, NULL); - // g_test_add_func ("/word_list/loads_default", loads_default); + g_test_add_func ("/word_list/loads_default", loads_default); #if 0 g_test_add_func ("/word_list/ascii_roundtrip", ascii_roundtrip); g_test_add_func ("/word_list/utf8_roundtrip", utf8_roundtrip); #endif - // g_test_add_func ("/word_list/set_anagram", anagram_test); - // g_test_add_func ("/word_list/find_intersection", find_intersection); + g_test_add_func ("/word_list/set_anagram", anagram_test); + g_test_add_func ("/word_list/find_intersection", find_intersection); g_test_add_func ("/word_list/equivalent_intersections", equivalent_intersections); - // g_test_add_func ("/word_list/frequency_test", frequency_test); + g_test_add_func ("/word_list/frequency_test", frequency_test); #ifdef PROFILE_TEST g_test_add_func ("/word_list/profile_test", profile_test); diff --git a/src/word-list.c b/src/word-list.c index 2c310324..60cbefb5 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -433,10 +433,8 @@ validate_filter (WordList *self, filter_len > self->index->max_length) return FALSE; - g_message ("halfway"); for (ptr = filter; ptr[0] != '\0'; ptr = g_utf8_next_char (ptr)) { - // g_message ("%ld", ptr - filter); gunichar c; gint index; @@ -1034,8 +1032,10 @@ static void sort_word_arrays (WordArray **word_array1, WordArray **word_array2) { - word_array_sort (word_array1 ? *word_array1 : NULL); - word_array_sort (word_array2 ? *word_array2 : NULL); + if (word_array1 != NULL) + word_array_sort (*word_array1); + if (word_array2 != NULL) + word_array_sort (*word_array2); } @@ -1450,7 +1450,6 @@ word_list_find_intersection (WordList *word_list, * on the 'C' character. In this instance, we just */ if (!g_utf8_strchr (WORD_LIST_CHAR_WILDCARDS, -1, c1)) { - g_message ("special case"); calculate_intersect_special (word_list, filter1, filter2, filter1_valid, filter2_valid, @@ -1465,7 +1464,6 @@ word_list_find_intersection (WordList *word_list, * both the word_list and charset, so we can reuse it for this */ if (!filter1_valid || !filter2_valid) { - g_message ("one invalid"); if (filter1_valid) { charset1 = calculate_intersect_phase2 (word_list, @@ -1500,14 +1498,12 @@ word_list_find_intersection (WordList *word_list, /* Phase 1: Calculate the set of possible characters at pos1 for * filter1. We don't need to worry about calculating the word_list * yet */ - g_message ("phase 1"); charset1 = calculate_intersect_phase1 (word_list, filter1, pos1, n_chars1); /* phase 2: Calculate the overlapping characters and the second * word_array. If necessary, calculate the second filters word_array */ - g_message ("phase 2"); charset2 = calculate_intersect_phase2 (word_list, filter2, pos2, @@ -1517,7 +1513,6 @@ word_list_find_intersection (WordList *word_list, /* phase 3: Recalculate the word_array first filter with the * overlap */ - g_message ("phase 3"); calculate_intersect_phase3 (word_list, filter1, pos1, n_chars1, -- GitLab From d46744df1f8a571e1e74c356e3965b0d61f1b4a5 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Mon, 16 Jun 2025 20:02:17 -0400 Subject: [PATCH 17/23] Improve word_array_print function --- src/word-list-misc.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 054404c9..5186264d 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -316,23 +316,6 @@ word_index_comparator (gconstpointer a, return index_a - index_b; } -void -word_array_print (WordArray *word_array) -{ - if (word_array == NULL) - { - g_message ("WordArray is NULL."); - return; - } - WordIndex current; - g_message ("WordArray %p:", word_array); - for (guint i = 0; i < word_array->len; i++) - { - current = g_array_index (word_array, WordIndex, 0); - g_message ("\t%d", current.index); - } -} - void word_array_sort (WordArray *word_array) { @@ -356,6 +339,26 @@ word_array_equals (WordArray *word_array1, WordArray *word_array2) return TRUE; } +#define MAX_WORDS 100 +void +word_array_print (WordArray *word_array) +{ + if (word_array == NULL) + { + g_message ("WordArray is NULL."); + return; + } + WordIndex current; + g_message ("WordArray %p:", word_array); + /* FIXME(debugging): Maybe better to print them all in one line. */ + /* FIXME(debugging): Print first 50 and last 50 words instead of first 100. */ + for (guint i = 0; i < MIN (word_array->len, MAX_WORDS); i++) + { + current = g_array_index (word_array, WordIndex, i); + g_message ("\t%d", current.index); + } +} + #ifdef TESTING static void computes_letters_size (void) -- GitLab From e5bc96b22cc1e138f499f1d29e11f5eae1854cd0 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 17 Jun 2025 08:12:01 -0400 Subject: [PATCH 18/23] Use utf8 functions --- src/word-list-tests.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index c9b7bfd7..0bdd73f7 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -394,18 +394,19 @@ equivalent_intersections_test (WordList *wl, const gchar *filter) { const gchar* crossing_filter; + const gchar *ptr; g_autoptr (WordArray) prev_word_array = NULL; g_autoptr (WordArray) curr_word_array = NULL; - crossing_filter = g_strnfill (strlen (filter), '?'); + crossing_filter = g_strnfill (g_utf8_strlen (filter, -1), '?'); - // g_utf8_next_char? - for (guint i = 0; i < strlen (filter); i++) + ptr = filter; + for (guint n = 0; *ptr != '\0'; ptr = g_utf8_next_char (ptr), n++) { - if (filter[i] == '?') + if (*ptr == '?') { word_list_find_intersection (wl, - filter, i, + filter, n, crossing_filter, 0, NULL, &curr_word_array, -- GitLab From 75aae5524af41087f70ba9dfdc52d18bb87e2c36 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 17 Jun 2025 08:32:59 -0400 Subject: [PATCH 19/23] Add function to use Broda resource in tests --- src/word-list-tests.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 0bdd73f7..9bce5be8 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -45,16 +45,15 @@ //#define PROFILE_TEST +/* FIXME(tests): Intersection function generates bad results with test word list. */ static WordList * -get_test_word_list (void) +get_word_list (const gchar *resource_path) { g_autofree gchar *path = NULL; g_autoptr (WordListResource) resource = NULL; WordList *word_list = NULL; - /* FIXME(tests): Intersection function generates bad results with test word list. - * path = g_test_build_filename (G_TEST_BUILT, TEST_RESOURCE, NULL); */ - path = g_test_build_filename (G_TEST_BUILT, BRODA_RESOURCE, NULL); + path = g_test_build_filename (G_TEST_BUILT, resource_path, NULL); resource = word_list_resource_new_from_file (path); word_list = g_object_new (WORD_TYPE_LIST, @@ -64,6 +63,18 @@ get_test_word_list (void) return word_list; } +static WordList * +get_test_word_list (void) +{ + return get_word_list (TEST_RESOURCE); +} + +static WordList * +get_broda_word_list (void) +{ + return get_word_list (BRODA_RESOURCE); +} + #if 0 static void dump_bytes (GBytes *bytes) @@ -359,7 +370,7 @@ intersection_test (WordList *wl, static void find_intersection (void) { - g_autoptr (WordList) wl = get_test_word_list (); + g_autoptr (WordList) wl = get_broda_word_list (); intersection_test (wl, "???", 1, @@ -423,7 +434,7 @@ equivalent_intersections_test (WordList *wl, static void equivalent_intersections (void) { - g_autoptr (WordList) wl = get_test_word_list (); + g_autoptr (WordList) wl = get_broda_word_list (); equivalent_intersections_test (wl, "??"); equivalent_intersections_test (wl, "???"); equivalent_intersections_test (wl, "??????????????"); -- GitLab From a2393d8fe7a9ba439eede3c7a346c8a473b1125a Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 17 Jun 2025 08:44:47 -0400 Subject: [PATCH 20/23] Comment out broken assertion --- src/word-list-tests.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 9bce5be8..7120cbd3 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -362,7 +362,8 @@ intersection_test (WordList *wl, g_print ("%s\n", word_list_get_indexed_word (wl, word_index)); } #endif - g_assert_cmpstr (intersection_str, ==, charset_str); + /* FIXME(tests): This assertion fails when using BRODA_RESOURCE. */ + // g_assert_cmpstr (intersection_str, ==, charset_str); g_assert (word_array_is_sorted (word_array1)); g_assert (word_array_is_sorted (word_array2)); } -- GitLab From 0a0ec4898a893713265d409bc23cba7089dc36e5 Mon Sep 17 00:00:00 2001 From: Victor Ma Date: Tue, 17 Jun 2025 09:11:03 -0400 Subject: [PATCH 21/23] Add test case --- src/word-list-tests.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 7120cbd3..c68d273b 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -45,7 +45,7 @@ //#define PROFILE_TEST -/* FIXME(tests): Intersection function generates bad results with test word list. */ +/* FIXME(tests): Intersection function generates bad results with TEST_RESOURCE. */ static WordList * get_word_list (const gchar *resource_path) { @@ -443,6 +443,7 @@ equivalent_intersections (void) equivalent_intersections_test (wl, "?A?"); equivalent_intersections_test (wl, "??A"); equivalent_intersections_test (wl, "???A???A???A???"); + equivalent_intersections_test (wl, "ABBACCCCBABA"); } #define EPSILON 0.001 -- GitLab From 090ea3962926515a5e700133184176037eef696d Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Tue, 17 Jun 2025 23:56:35 -0700 Subject: [PATCH 22/23] Go back to the test word list --- src/word-list-tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index c68d273b..a0b19fa7 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -371,7 +371,7 @@ intersection_test (WordList *wl, static void find_intersection (void) { - g_autoptr (WordList) wl = get_broda_word_list (); + g_autoptr (WordList) wl = get_test_word_list (); intersection_test (wl, "???", 1, -- GitLab From bdebbc97651d8bcf50d578d88c66f4e490898ece Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Tue, 17 Jun 2025 23:57:02 -0700 Subject: [PATCH 23/23] Bring back the test to make sure the overlap is right --- src/word-list-tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/word-list-tests.c b/src/word-list-tests.c index a0b19fa7..d84ab52d 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -362,8 +362,8 @@ intersection_test (WordList *wl, g_print ("%s\n", word_list_get_indexed_word (wl, word_index)); } #endif - /* FIXME(tests): This assertion fails when using BRODA_RESOURCE. */ - // g_assert_cmpstr (intersection_str, ==, charset_str); + + g_assert_cmpstr (intersection_str, ==, charset_str); g_assert (word_array_is_sorted (word_array1)); g_assert (word_array_is_sorted (word_array2)); } -- GitLab