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_norm_int32_for_0_equals_31(void ** state)15 static void test_math_numbers_norm_int32_for_0_equals_31(void **state)
16 {
17 	(void)state;
18 
19 	int r = norm_int32(0);
20 
21 	assert_int_equal(r, 31);
22 }
23 
test_math_numbers_norm_int32_for_35_equals_10(void ** state)24 static void test_math_numbers_norm_int32_for_35_equals_10(void **state)
25 {
26 	(void)state;
27 
28 	int r = norm_int32(35);
29 
30 	assert_int_equal(r, 25);
31 }
32 
test_math_numbers_norm_int32_for_2147483647_equals_0(void ** state)33 static void test_math_numbers_norm_int32_for_2147483647_equals_0(void **state)
34 {
35 	(void)state;
36 
37 	int r = norm_int32(2147483647);
38 
39 	assert_int_equal(r, 0);
40 }
41 
main(void)42 int main(void)
43 {
44 	const struct CMUnitTest tests[] = {
45 		cmocka_unit_test(test_math_numbers_norm_int32_for_0_equals_31),
46 		cmocka_unit_test
47 			(test_math_numbers_norm_int32_for_35_equals_10),
48 		cmocka_unit_test
49 			(test_math_numbers_norm_int32_for_2147483647_equals_0)
50 	};
51 
52 	cmocka_set_message_output(CM_OUTPUT_TAP);
53 
54 	return cmocka_run_group_tests(tests, NULL, NULL);
55 }
56