[libdazzle] tests: sort mutable index search results



commit e1130893ec36c811813c9285c6989e83a9986df1
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jun 3 20:02:30 2017 -0700

    tests: sort mutable index search results

 tests/test-fuzzy-mutable-index.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-fuzzy-mutable-index.c b/tests/test-fuzzy-mutable-index.c
index e097c85..ac1da38 100644
--- a/tests/test-fuzzy-mutable-index.c
+++ b/tests/test-fuzzy-mutable-index.c
@@ -1,6 +1,20 @@
 #include <dazzle.h>
 #include <stdlib.h>
 
+static gint
+compare_match (gconstpointer a,
+               gconstpointer b)
+{
+  const DzlFuzzyMutableIndexMatch *ma = a;
+  const DzlFuzzyMutableIndexMatch *mb = b;
+
+  if (ma->score < mb->score)
+    return 1;
+  else if (ma->score > mb->score)
+    return -1;
+  return 0;
+}
+
 gint
 main (gint   argc,
       gchar *argv[])
@@ -45,6 +59,8 @@ main (gint   argc,
          matches = dzl_fuzzy_mutable_index_match (fuzzy, argv[i], 0);
          end = g_get_monotonic_time();
 
+         g_array_sort (matches, compare_match);
+
          for (guint j = 0; j < matches->len; j++)
            {
              const DzlFuzzyMutableIndexMatch *match = &g_array_index (matches, DzlFuzzyMutableIndexMatch, j);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]