2 * Copyright © 2022 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 * Google Author(s): Garret Rieger
27 #include "gsubgpos-context.hh"
28 #include "classdef-graph.hh"
30 typedef hb_codepoint_pair_t gid_and_class_t;
31 typedef hb_vector_t<gid_and_class_t> gid_and_class_list_t;
34 static bool incremental_size_is (const gid_and_class_list_t& list, unsigned klass,
35 unsigned cov_expected, unsigned class_def_expected)
37 graph::class_def_size_estimator_t estimator (list.iter ());
39 unsigned result = estimator.incremental_coverage_size (klass);
40 if (result != cov_expected)
42 printf ("FAIL: coverage expected size %u but was %u\n", cov_expected, result);
46 result = estimator.incremental_class_def_size (klass);
47 if (result != class_def_expected)
49 printf ("FAIL: class def expected size %u but was %u\n", class_def_expected, result);
56 static void test_class_and_coverage_size_estimates ()
58 gid_and_class_list_t empty = {
60 assert (incremental_size_is (empty, 0, 0, 0));
61 assert (incremental_size_is (empty, 1, 0, 0));
63 gid_and_class_list_t class_zero = {
66 assert (incremental_size_is (class_zero, 0, 2, 0));
68 gid_and_class_list_t consecutive = {
78 assert (incremental_size_is (consecutive, 0, 4, 0));
79 assert (incremental_size_is (consecutive, 1, 4, 4));
80 assert (incremental_size_is (consecutive, 2, 8, 6));
82 gid_and_class_list_t non_consecutive = {
94 assert (incremental_size_is (non_consecutive, 0, 4, 0));
95 assert (incremental_size_is (non_consecutive, 1, 4, 6));
96 assert (incremental_size_is (non_consecutive, 2, 8, 6));
98 gid_and_class_list_t multiple_ranges = {
111 assert (incremental_size_is (multiple_ranges, 0, 4, 0));
112 assert (incremental_size_is (multiple_ranges, 1, 2 * 6, 3 * 6));
116 main (int argc, char **argv)
118 test_class_and_coverage_size_estimates ();