1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2018 Intel Corporation. All rights reserved.
4 //
5 // Author: Slawomir Blauciak <slawomir.blauciak@linux.intel.com>
6
7 #include <sof/math/numbers.h>
8
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include <stddef.h>
12 #include <setjmp.h>
13 #include <math.h>
14 #include <stdint.h>
15 #include <cmocka.h>
16
test_math_numbers_ceil_divide(void ** state)17 static void test_math_numbers_ceil_divide(void **state)
18 {
19 (void)state;
20
21 int params[8] = {
22 -1000,
23 300,
24 123,
25 -10,
26 1337,
27 -6,
28 999,
29 -2
30 };
31
32 int i, j;
33
34 for (i = 0; i < 8; ++i) {
35 for (j = 0; j < 8; ++j) {
36 int ref = ceilf((float)params[i] / (float)params[j]);
37 int r = ceil_divide(params[i], params[j]);
38
39 if (r != ref) {
40 printf("%s: %d / %d = %d (ref: %d)\n", __func__,
41 params[i], params[j], r, ref);
42 }
43
44 assert_int_equal(r, ref);
45 }
46 }
47
48 }
49
main(void)50 int main(void)
51 {
52 const struct CMUnitTest tests[] = {
53 cmocka_unit_test(test_math_numbers_ceil_divide)
54 };
55
56 cmocka_set_message_output(CM_OUTPUT_TAP);
57
58 return cmocka_run_group_tests(tests, NULL, NULL);
59 }
60