diff --git a/src/clue-matches-tests.c b/src/clue-matches-tests.c index 74964215f700dc45745a6a3ea67fd5d707a73875..4ac587313a37b9cbafe253440f45200577fb27b6 100644 --- a/src/clue-matches-tests.c +++ b/src/clue-matches-tests.c @@ -22,39 +22,15 @@ #include #include "crosswords-misc.h" #include "clue-matches.h" +#include "word-list-test-utils.h" #include "test-utils.h" // #define _TEST_FILE "tests/clue-matches/.ipuz" -#define BRODA_RESOURCE "../word-lists/broda.gresource" #define EGG_IPUZ_FILE_PATH "tests/clue-matches/egg.ipuz" #define VALID_INTERSECTION_IPUZ_FILE_PATH "tests/clue-matches/valid-intersection.ipuz" #define INVALID_INTERSECTION_IPUZ_FILE_PATH "tests/clue-matches/invalid-intersection.ipuz" -/* FIXME(tests): Duplicate code in word-list-tests.c. */ -static WordList * -get_word_list (const gchar *resource_path) -{ - g_autofree gchar *path = NULL; - g_autoptr (WordListResource) resource = NULL; - WordList *word_list = 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, - "resource", resource, - NULL); - - return word_list; -} - -static WordList * -get_broda_word_list (void) -{ - return get_word_list (BRODA_RESOURCE); -} - static IpuzGrid* create_grid (const gchar* filename) { diff --git a/src/clue-matches.c b/src/clue-matches.c index 0d30f0ce865a68020cfed339ddbc86a03e7c2635..4a156a3b9f93b474b061dc184bae55e55c743699 100644 --- a/src/clue-matches.c +++ b/src/clue-matches.c @@ -33,8 +33,8 @@ filter_is_unconstrained (const gchar *filter) return TRUE; } -/* FIXME(clue-matches): Caching. */ -/* Combine get filter and get offset +/* FIXME(lookahead): Caching. */ +/* FIXME(lookahead): Combine get filter and get offset * into a single loop function? */ static guint get_filter_offset (const IpuzClue *clue, @@ -86,7 +86,7 @@ word_list_find_clue_matches (WordList *word_list, g_assert (current_clue_n_coords > 1); current_filter = clue_get_filter (current_clue, grid); - /* FIXME(editor): Add support for other directions. */ + /* FIXME(lookahead): Add support for other directions. */ current_clue_direction = ipuz_clue_get_direction (current_clue); intersecting_clue_direction = ipuz_clue_direction_switch (current_clue_direction); diff --git a/src/meson.build b/src/meson.build index 73fbff81da97a7458f661689592d413c1706bd2f..ea540d27929ebffef018a40f7d609b185180a2a9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -422,9 +422,14 @@ test( # Tests with wordlist +clue_matches_tests_sources = [ + 'word-list-tests.c', + 'word-list-test-utils.c' +] + word_list_tests = executable( 'word-list-tests', - [ 'word-list-tests.c' ], + clue_matches_tests_sources, dependencies: crosswords_deps, install: false ) @@ -441,6 +446,7 @@ test( clue_matches_tests_sources = [ 'clue-matches-tests.c', + 'word-list-test-utils.c', 'test-utils.c', 'clue-matches.c' ] + common_sources diff --git a/src/word-list-misc.c b/src/word-list-misc.c index 17215ca6334148fe1216dae981f9cafe2bb325b2..124c552d19c3d27fdb26d666231c175bc8e161ba 100644 --- a/src/word-list-misc.c +++ b/src/word-list-misc.c @@ -433,6 +433,7 @@ static gboolean word_not_in_set (gpointer key, return !g_hash_table_contains (word_set, word_index); } +/* FIXME(lookahead): Attempt the optimization again. */ void word_set_remove_unique (WordSet *word_set1, WordSet *word_set2) { diff --git a/src/word-list-test-utils.c b/src/word-list-test-utils.c new file mode 100644 index 0000000000000000000000000000000000000000..7e496b509892afda7661b69d48eaa0a3de02562a --- /dev/null +++ b/src/word-list-test-utils.c @@ -0,0 +1,54 @@ +/* word-list-test-utils.c + * + * Copyright 2025 Victor Ma + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "word-list-test-utils.h" + +#define TEST_RESOURCE "../word-lists/test.gresource" +#define BRODA_RESOURCE "../word-lists/broda.gresource" + +/* FIXME(test): Intersection function generates bad results with TEST_RESOURCE. */ +static WordList * +get_word_list (const gchar *resource_path) +{ + g_autofree gchar *path = NULL; + g_autoptr (WordListResource) resource = NULL; + WordList *word_list = 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, + "resource", resource, + NULL); + + return word_list; +} + +WordList * +get_test_word_list (void) +{ + return get_word_list (TEST_RESOURCE); +} + +WordList * +get_broda_word_list (void) +{ + return get_word_list (BRODA_RESOURCE); +} \ No newline at end of file diff --git a/src/word-list-test-utils.h b/src/word-list-test-utils.h new file mode 100644 index 0000000000000000000000000000000000000000..705aed9b87870299fc05335c31f9bad293dea766 --- /dev/null +++ b/src/word-list-test-utils.h @@ -0,0 +1,26 @@ +/* word-list-test-utils.h + * + * Copyright 2025 Victor Ma + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "word-list.h" + +WordList *get_test_word_list (void); +WordList *get_broda_word_list (void); \ No newline at end of file diff --git a/src/word-list-tests.c b/src/word-list-tests.c index 107311948d44574382dda72d1605d2367b732d56..fe920be834e727ee30ae7ef3802707da94b74a3f 100644 --- a/src/word-list-tests.c +++ b/src/word-list-tests.c @@ -23,11 +23,7 @@ #include "crosswords-stats.h" #include "gen-word-list.h" #include "word-list.h" - - -#define TEST_RESOURCE "../word-lists/test.gresource" -#define BRODA_RESOURCE "../word-lists/broda.gresource" - +#include "word-list-test-utils.h" /* Uncommenting this will enable the profile test. This test will run * word-list matches in an infinite loop and never complete. That can @@ -44,37 +40,6 @@ */ //#define PROFILE_TEST - -/* FIXME(test): Intersection function generates bad results with TEST_RESOURCE. */ -static WordList * -get_word_list (const gchar *resource_path) -{ - g_autofree gchar *path = NULL; - g_autoptr (WordListResource) resource = NULL; - WordList *word_list = 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, - "resource", resource, - NULL); - - 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) @@ -477,16 +442,9 @@ frequency_test (void) static void profile_test (void) { - g_autofree gchar *path = NULL; - g_autoptr (WordListResource) resource = NULL; - WordList *word_list = NULL; - - path = g_test_build_filename (G_TEST_BUILT, BRODA_RESOURCE, NULL); - resource = word_list_resource_new_from_file (path); + g_autoptr (WordList) word_list = NULL; - word_list = g_object_new (WORD_TYPE_LIST, - "resource", resource, - NULL); + word_list = get_broda_word_list (); while (TRUE) {