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 <stdarg.h>
10 #include <stddef.h>
11 #include <setjmp.h>
12 #include <stdint.h>
13 #include <cmocka.h>
14
test_math_numbers_find_equal_int16_for_5_123_5_10_123_500_123_n_123_equals_1_4_and_6(void ** state)15 static void test_math_numbers_find_equal_int16_for_5_123_5_10_123_500_123_n_123_equals_1_4_and_6
16 (void **state)
17 {
18 (void)state;
19
20 int16_t r[4];
21 int16_t vec[] = {5, 123, 5, 10, 123, 500, 123};
22 int16_t template[] = {1, 4, 6};
23
24 int r_num = find_equal_int16(r, vec, 123, 7, 4);
25
26 assert_int_equal(r_num, 3);
27 assert_memory_equal(r, template, sizeof(int16_t) * 3);
28 }
29
test_math_numbers_find_equal_int16_for_1_2_3_4_5_n_0_equals_nothing(void ** state)30 static void test_math_numbers_find_equal_int16_for_1_2_3_4_5_n_0_equals_nothing
31 (void **state)
32 {
33 (void)state;
34
35 int16_t r[4];
36 int16_t vec[] = {1, 2, 3, 4, 5};
37
38 int r_num = find_equal_int16(r, vec, 0, 5, 4);
39
40 assert_int_equal(r_num, 0);
41 }
42
main(void)43 int main(void)
44 {
45 const struct CMUnitTest tests[] = {
46 cmocka_unit_test
47 (test_math_numbers_find_equal_int16_for_5_123_5_10_123_500_123_n_123_equals_1_4_and_6),
48 cmocka_unit_test
49 (test_math_numbers_find_equal_int16_for_1_2_3_4_5_n_0_equals_nothing)
50 };
51
52 cmocka_set_message_output(CM_OUTPUT_TAP);
53
54 return cmocka_run_group_tests(tests, NULL, NULL);
55 }
56