[libdazzle] tests: add test for mutable index scoring
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] tests: add test for mutable index scoring
- Date: Tue, 16 Jul 2019 22:53:05 +0000 (UTC)
commit fc852ee88c4bdd8b07253e09fcd4373c48589e20
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 15 11:33:45 2019 -0700
tests: add test for mutable index scoring
This helps us ensure that we are matching later in the string so that
we can potentially gain a higher score (due to penalties in distance
between match characters).
tests/meson.build | 7 +++++
tests/test-mutable-scoring.c | 69 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 6dafd29..a202bbd 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -403,4 +403,11 @@ test_fuzzy_highlight = executable('test-fuzzy-highlight', 'test-fuzzy-highlight.
)
test('test-fuzzy-highlight', test_fuzzy_highlight, env: test_env)
+test_mutable_scoring = executable('test-mutable-scoring', 'test-mutable-scoring.c',
+ c_args: test_cflags,
+ link_args: test_link_args,
+ dependencies: libdazzle_deps + [libdazzle_dep],
+)
+test('test-mutable-scoring', test_mutable_scoring, env: test_env)
+
endif
diff --git a/tests/test-mutable-scoring.c b/tests/test-mutable-scoring.c
new file mode 100644
index 0000000..b2bf00a
--- /dev/null
+++ b/tests/test-mutable-scoring.c
@@ -0,0 +1,69 @@
+/* test-mutable-scoring.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include <dazzle.h>
+
+static void
+test_scoring_1 (void)
+{
+ g_autoptr(DzlFuzzyMutableIndex) index = dzl_fuzzy_mutable_index_new (FALSE);
+ g_autoptr(GArray) all = NULL;
+ DzlFuzzyMutableIndexMatch *m;
+
+ static const gchar *words[] = {
+ "plugins/flatpak/gs-flatpak.c",
+ "plugins/flatpak/gs-flatpak.h",
+ "plugins/flatpak/gs-flatpak-app.c",
+ "plugins/flatpak/gs-flatpak-app.h",
+ "plugins/flatpak/gs-flatpak-utils.c",
+ "plugins/flatpak/gs-flatpak-utils.h",
+ "plugins/flatpak/gs-plugin-flatpak.c",
+ "plugins/flatpak/gs-flatpak-transaction.c",
+ "plugins/flatpak/gs-flatpak-transaction.h",
+ };
+
+ dzl_fuzzy_mutable_index_begin_bulk_insert (index);
+ for (guint i = 0; i < G_N_ELEMENTS (words); i++)
+ dzl_fuzzy_mutable_index_insert (index, words[i], (gchar *)words[i]);
+ dzl_fuzzy_mutable_index_end_bulk_insert (index);
+
+ all = dzl_fuzzy_mutable_index_match (index, "plugin-flatpak", G_N_ELEMENTS (words));
+ g_assert_cmpint (all->len, ==, G_N_ELEMENTS (words));
+
+#if 0
+ for (guint i = 0; i < all->len; i++)
+ {
+ m = &g_array_index (all, DzlFuzzyMutableIndexMatch, i);
+ g_print ("%d: %s %lf\n", i, m->key, m->score);
+ }
+#endif
+
+ m = &g_array_index (all, DzlFuzzyMutableIndexMatch, 0);
+ g_assert_cmpstr (m->key, ==, "plugins/flatpak/gs-plugin-flatpak.c");
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/Dazzle/FuzzyMutableIndex/scoring-1", test_scoring_1);
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]