aboutsummaryrefslogtreecommitdiff
path: root/test/api/test-set.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/api/test-set.c')
-rw-r--r--test/api/test-set.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/test/api/test-set.c b/test/api/test-set.c
index f2f9419bc..6ad11d331 100644
--- a/test/api/test-set.c
+++ b/test/api/test-set.c
@@ -1067,6 +1067,130 @@ test_set_inverted_operations (void)
g_assert (all_succeeded);
}
+static void
+test_hb_set_add_sorted_array (void)
+{
+ hb_set_t *set = hb_set_create ();
+ hb_codepoint_t array[7] = {1, 2, 3, 1000, 2000, 2001, 2002};
+ hb_set_add_sorted_array (set, array, 7);
+ g_assert_cmpint (hb_set_get_population (set), ==, 7);
+ g_assert (hb_set_has (set, 1));
+ g_assert (hb_set_has (set, 2));
+ g_assert (hb_set_has (set, 3));
+ g_assert (hb_set_has (set, 1000));
+ g_assert (hb_set_has (set, 2000));
+ g_assert (hb_set_has (set, 2001));
+ g_assert (hb_set_has (set, 2002));
+ hb_set_destroy (set);
+}
+
+static void
+test_set_next_many (void)
+{
+ hb_set_t *set = hb_set_create ();
+ for (unsigned i=0; i<600; i++)
+ hb_set_add (set, i);
+ for (unsigned i=6000; i<6100; i++)
+ hb_set_add (set, i);
+ g_assert (hb_set_get_population (set) == 700);
+ hb_codepoint_t array[700];
+
+ unsigned int n = hb_set_next_many (set, HB_SET_VALUE_INVALID, array, 700);
+
+ g_assert_cmpint(n, ==, 700);
+ for (unsigned i=0; i<600; i++)
+ g_assert_cmpint (array[i], ==, i);
+ for (unsigned i=0; i<100; i++)
+ g_assert (array[600 + i] == 6000u + i);
+
+ // Try skipping initial values.
+ for (unsigned i = 0; i < 700; i++)
+ array[i] = 0;
+
+ n = hb_set_next_many (set, 42, array, 700);
+
+ g_assert_cmpint (n, ==, 657);
+ g_assert_cmpint (array[0], ==, 43);
+ g_assert_cmpint (array[n - 1], ==, 6099);
+
+ hb_set_destroy (set);
+}
+
+static void
+test_set_next_many_restricted (void)
+{
+ hb_set_t *set = hb_set_create ();
+ for (int i=0; i<600; i++)
+ hb_set_add (set, i);
+ for (int i=6000; i<6100; i++)
+ hb_set_add (set, i);
+ g_assert (hb_set_get_population (set) == 700);
+ hb_codepoint_t array[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ hb_set_next_many (set, HB_SET_VALUE_INVALID, array, 9);
+
+ for (int i=0; i<9; i++)
+ g_assert_cmpint (array[i], ==, i);
+ g_assert_cmpint (array[9], ==, 0);
+ hb_set_destroy (set);
+}
+
+static void
+test_set_next_many_inverted (void)
+{
+ hb_set_t *set = hb_set_create ();
+ hb_set_add (set, 1);
+ hb_set_add (set, 3);
+ hb_set_invert (set);
+
+ hb_codepoint_t array[] = {0, 0, 0, 0, 0, 999};
+
+ // Single page.
+ hb_set_next_many (set, HB_SET_VALUE_INVALID, array, 5);
+
+ g_assert_cmpint (array[0], ==, 0);
+ g_assert_cmpint (array[1], ==, 2);
+ g_assert_cmpint (array[2], ==, 4);
+ g_assert_cmpint (array[3], ==, 5);
+ g_assert_cmpint (array[4], ==, 6);
+ g_assert_cmpint (array[5], ==, 999);
+
+ // Multiple pages.
+ hb_set_invert (set);
+ hb_set_add (set, 1000);
+ hb_set_invert (set);
+
+ hb_codepoint_t array2[1000];
+ hb_set_next_many (set, HB_SET_VALUE_INVALID, array2, 1000);
+ g_assert_cmpint (array2[0], ==, 0);
+ g_assert_cmpint (array2[1], ==, 2);
+ g_assert_cmpint (array2[2], ==, 4);
+ g_assert_cmpint (array2[3], ==, 5);
+ for (int i=4; i<997; i++)
+ {
+ g_assert_cmpint (array2[i], ==, i + 2);
+ }
+ g_assert_cmpint (array2[997], ==, 999);
+ // Value 1000 skipped.
+ g_assert_cmpint (array2[998], ==, 1001);
+ g_assert_cmpint (array2[999], ==, 1002);
+
+ hb_set_destroy (set);
+}
+
+static void
+test_set_next_many_out_of_order_pages (void) {
+ hb_set_t* set = hb_set_create();
+ hb_set_add(set, 1957);
+ hb_set_add(set, 69);
+ hb_codepoint_t results[2];
+ unsigned int result_size = hb_set_next_many(set, HB_SET_VALUE_INVALID, results, 2);
+ g_assert_cmpint(result_size, == , 2);
+ g_assert_cmpint(results[0], == , 69);
+ g_assert_cmpint(results[1], == , 1957);
+ hb_set_destroy(set);
+}
+
int
main (int argc, char **argv)
{
@@ -1090,5 +1214,11 @@ main (int argc, char **argv)
hb_test_add (test_set_inverted_equality);
hb_test_add (test_set_inverted_operations);
+ hb_test_add (test_hb_set_add_sorted_array);
+ hb_test_add (test_set_next_many);
+ hb_test_add (test_set_next_many_restricted);
+ hb_test_add (test_set_next_many_inverted);
+ hb_test_add (test_set_next_many_out_of_order_pages);
+
return hb_test_run();
}