From: Slawomir Blauciak slawomir.blauciak@linux.intel.com
Tests provided: ceil_divide, find_equal_int16, find_min_int16, find_max_abs_int32, norm_int32, sin_fixed
Signed-off-by: Slawomir Blauciak slawomir.blauciak@linux.intel.com --- test/cmocka/Makefile.am | 24 +++ test/cmocka/src/math/numbers/ceil_divide.c | 82 +++++++++ .../src/math/numbers/find_equal_int16.c | 78 ++++++++ .../src/math/numbers/find_max_abs_int32.c | 72 ++++++++ test/cmocka/src/math/numbers/find_min_int16.c | 71 ++++++++ test/cmocka/src/math/numbers/gcd.c | 3 +- test/cmocka/src/math/numbers/norm_int32.c | 78 ++++++++ test/cmocka/src/math/trig/sin_fixed.c | 169 ++++++++++++++++++ 8 files changed, 576 insertions(+), 1 deletion(-) create mode 100644 test/cmocka/src/math/numbers/ceil_divide.c create mode 100644 test/cmocka/src/math/numbers/find_equal_int16.c create mode 100644 test/cmocka/src/math/numbers/find_max_abs_int32.c create mode 100644 test/cmocka/src/math/numbers/find_min_int16.c create mode 100644 test/cmocka/src/math/numbers/norm_int32.c create mode 100644 test/cmocka/src/math/trig/sin_fixed.c
diff --git a/test/cmocka/Makefile.am b/test/cmocka/Makefile.am index 565fb80..bca9f56 100644 --- a/test/cmocka/Makefile.am +++ b/test/cmocka/Makefile.am @@ -50,5 +50,29 @@ check_PROGRAMS += gcd gcd_SOURCES = src/math/numbers/gcd.c gcd_LDADD = ../../src/math/libsof_math.a $(LDADD)
+check_PROGRAMS += ceil_divide +ceil_divide_SOURCES = src/math/numbers/ceil_divide.c +ceil_divide_LDADD = ../../src/math/libsof_math.a -lm $(LDADD) + +check_PROGRAMS += find_equal_int16 +find_equal_int16_SOURCES = src/math/numbers/find_equal_int16.c +find_equal_int16_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += find_min_int16 +find_min_int16_SOURCES = src/math/numbers/find_min_int16.c +find_min_int16_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += find_max_abs_int32 +find_max_abs_int32_SOURCES = src/math/numbers/find_max_abs_int32.c +find_max_abs_int32_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += norm_int32 +norm_int32_SOURCES = src/math/numbers/norm_int32.c +norm_int32_LDADD = ../../src/math/libsof_math.a $(LDADD) + +check_PROGRAMS += sin_fixed +sin_fixed_SOURCES = src/math/trig/sin_fixed.c +sin_fixed_LDADD = ../../src/math/libsof_math.a $(LDADD) + # all our binaries are test cases TESTS = $(check_PROGRAMS) diff --git a/test/cmocka/src/math/numbers/ceil_divide.c b/test/cmocka/src/math/numbers/ceil_divide.c new file mode 100644 index 0000000..f20514e --- /dev/null +++ b/test/cmocka/src/math/numbers/ceil_divide.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak slawomir.blauciak@linux.intel.com + */ + +#include <sof/math/numbers.h> + +#include <stdio.h> +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <math.h> +#include <cmocka.h> + +static void test_math_numbers_ceil_divide(void **state) +{ + (void)state; + + int params[8] = { + -1000, + 300, + 123, + -10, + 1337, + -6, + 999, + -2 + }; + + int i, j; + + for (i = 0; i < 8; ++i) { + for (j = 0; j < 8; ++j) { + int ref = ceilf((float)params[i] / (float)params[j]); + int r = ceil_divide(params[i], params[j]); + + if (r != ref) { + printf("%s: %d / %d = %d (ref: %d)\n", __func__, + params[i], params[j], r, ref); + } + + assert_int_equal(r, ref); + } + } + +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_math_numbers_ceil_divide) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/find_equal_int16.c b/test/cmocka/src/math/numbers/find_equal_int16.c new file mode 100644 index 0000000..84e06de --- /dev/null +++ b/test/cmocka/src/math/numbers/find_equal_int16.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak slawomir.blauciak@linux.intel.com + */ + +#include <sof/math/numbers.h> + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +static void test_math_numbers_find_equal_int16_for_5_123_5_10_123_500_123_n_123_equals_1_4_and_6 + (void **state) +{ + (void)state; + + int16_t r[4]; + int16_t vec[] = {5, 123, 5, 10, 123, 500, 123}; + int16_t template[] = {1, 4, 6}; + + int r_num = find_equal_int16(r, vec, 123, 7, 4); + + assert_int_equal(r_num, 3); + assert_memory_equal(r, template, sizeof(int16_t) * 3); +} + +static void test_math_numbers_find_equal_int16_for_1_2_3_4_5_n_0_equals_nothing + (void **state) +{ + (void)state; + + int16_t r[4]; + int16_t vec[] = {1, 2, 3, 4, 5}; + + int r_num = find_equal_int16(r, vec, 0, 5, 4); + + assert_int_equal(r_num, 0); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_math_numbers_find_equal_int16_for_5_123_5_10_123_500_123_n_123_equals_1_4_and_6), + cmocka_unit_test + (test_math_numbers_find_equal_int16_for_1_2_3_4_5_n_0_equals_nothing) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/find_max_abs_int32.c b/test/cmocka/src/math/numbers/find_max_abs_int32.c new file mode 100644 index 0000000..1a88263 --- /dev/null +++ b/test/cmocka/src/math/numbers/find_max_abs_int32.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak slawomir.blauciak@linux.intel.com + */ + +#include <sof/math/numbers.h> + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +static void test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_equals_100 + (void **state) +{ + (void)state; + + int32_t vec[] = {-100, 99, 98, 50}; + int r = find_max_abs_int32(vec, sizeof(vec) / sizeof(int32_t)); + + assert_int_equal(r, 100); +} + +static void test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_101_equals_101 + (void **state) +{ + (void)state; + + int32_t vec[] = {-100, 99, 98, 50, 101}; + int r = find_max_abs_int32(vec, sizeof(vec) / sizeof(int32_t)); + + assert_int_equal(r, 101); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_equals_100), + cmocka_unit_test + (test_math_numbers_find_max_abs_int32_for_neg100_99_98_50_101_equals_101) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/find_min_int16.c b/test/cmocka/src/math/numbers/find_min_int16.c new file mode 100644 index 0000000..744ed12 --- /dev/null +++ b/test/cmocka/src/math/numbers/find_min_int16.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak slawomir.blauciak@linux.intel.com + */ + +#include <sof/math/numbers.h> + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +static void test_math_numbers_find_min_int16_for_2_equals_2(void **state) +{ + (void)state; + + int16_t vec[] = {2}; + int r = find_min_int16(vec, sizeof(vec) / sizeof(int16_t)); + + assert_int_equal(r, 2); +} + +static void test_math_numbers_find_min_int16_for_5_2_3_4_1_equals_1 + (void **state) +{ + (void)state; + + int16_t vec[] = {5, 2, 3, 4, 1}; + int r = find_min_int16(vec, sizeof(vec) / sizeof(int16_t)); + + assert_int_equal(r, 1); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test + (test_math_numbers_find_min_int16_for_2_equals_2), + cmocka_unit_test + (test_math_numbers_find_min_int16_for_5_2_3_4_1_equals_1) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/numbers/gcd.c b/test/cmocka/src/math/numbers/gcd.c index 7a8329e..dab9fa3 100644 --- a/test/cmocka/src/math/numbers/gcd.c +++ b/test/cmocka/src/math/numbers/gcd.c @@ -59,7 +59,8 @@ static void test_math_numbers_gcd_for_12_and_9_equals_3(void **state) int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test_math_numbers_gcd_for_5083_and_391_equals_391), + cmocka_unit_test + (test_math_numbers_gcd_for_5083_and_391_equals_391), cmocka_unit_test(test_math_numbers_gcd_for_12_and_9_equals_3), };
diff --git a/test/cmocka/src/math/numbers/norm_int32.c b/test/cmocka/src/math/numbers/norm_int32.c new file mode 100644 index 0000000..772f74b --- /dev/null +++ b/test/cmocka/src/math/numbers/norm_int32.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak slawomir.blauciak@linux.intel.com + */ + +#include <sof/math/numbers.h> + +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +static void test_math_numbers_norm_int32_for_0_equals_31(void **state) +{ + (void)state; + + int r = norm_int32(0); + + assert_int_equal(r, 31); +} + +static void test_math_numbers_norm_int32_for_35_equals_10(void **state) +{ + (void)state; + + int r = norm_int32(35); + + assert_int_equal(r, 25); +} + +static void test_math_numbers_norm_int32_for_2147483648_equals_0(void **state) +{ + (void)state; + + int r = norm_int32(2147483648); + + assert_int_equal(r, 0); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_math_numbers_norm_int32_for_0_equals_31), + cmocka_unit_test + (test_math_numbers_norm_int32_for_35_equals_10), + cmocka_unit_test + (test_math_numbers_norm_int32_for_2147483648_equals_0) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/src/math/trig/sin_fixed.c b/test/cmocka/src/math/trig/sin_fixed.c new file mode 100644 index 0000000..de0bd41 --- /dev/null +++ b/test/cmocka/src/math/trig/sin_fixed.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2018, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Intel Corporation nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Author: Slawomir Blauciak slawomir.blauciak@linux.intel.com + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <math.h> +#include <cmocka.h> + +#include <sof/audio/format.h> +#include <sof/math/trig.h> + +#define CMP_TOLERANCE 0.000005 + +/* Reference table generated by sin(), gcc-4.3.2 */ +static const float sin_ref_table[] = { + 0.0000000000, 0.0174524064, 0.0348994967, 0.0523359562, + 0.0697564737, 0.0871557427, 0.1045284633, 0.1218693434, + 0.1391731010, 0.1564344650, 0.1736481777, 0.1908089954, + 0.2079116908, 0.2249510543, 0.2419218956, 0.2588190451, + 0.2756373558, 0.2923717047, 0.3090169944, 0.3255681545, + 0.3420201433, 0.3583679495, 0.3746065934, 0.3907311285, + 0.4067366431, 0.4226182617, 0.4383711468, 0.4539904997, + 0.4694715628, 0.4848096202, 0.5000000000, 0.5150380749, + 0.5299192642, 0.5446390350, 0.5591929035, 0.5735764364, + 0.5877852523, 0.6018150232, 0.6156614753, 0.6293203910, + 0.6427876097, 0.6560590290, 0.6691306064, 0.6819983601, + 0.6946583705, 0.7071067812, 0.7193398003, 0.7313537016, + 0.7431448255, 0.7547095802, 0.7660444431, 0.7771459615, + 0.7880107536, 0.7986355100, 0.8090169944, 0.8191520443, + 0.8290375726, 0.8386705679, 0.8480480962, 0.8571673007, + 0.8660254038, 0.8746197071, 0.8829475929, 0.8910065242, + 0.8987940463, 0.9063077870, 0.9135454576, 0.9205048535, + 0.9271838546, 0.9335804265, 0.9396926208, 0.9455185756, + 0.9510565163, 0.9563047560, 0.9612616959, 0.9659258263, + 0.9702957263, 0.9743700648, 0.9781476007, 0.9816271834, + 0.9848077530, 0.9876883406, 0.9902680687, 0.9925461516, + 0.9945218954, 0.9961946981, 0.9975640503, 0.9986295348, + 0.9993908270, 0.9998476952, 1.0000000000, 0.9998476952, + 0.9993908270, 0.9986295348, 0.9975640503, 0.9961946981, + 0.9945218954, 0.9925461516, 0.9902680687, 0.9876883406, + 0.9848077530, 0.9816271834, 0.9781476007, 0.9743700648, + 0.9702957263, 0.9659258263, 0.9612616959, 0.9563047560, + 0.9510565163, 0.9455185756, 0.9396926208, 0.9335804265, + 0.9271838546, 0.9205048535, 0.9135454576, 0.9063077870, + 0.8987940463, 0.8910065242, 0.8829475929, 0.8746197071, + 0.8660254038, 0.8571673007, 0.8480480962, 0.8386705679, + 0.8290375726, 0.8191520443, 0.8090169944, 0.7986355100, + 0.7880107536, 0.7771459615, 0.7660444431, 0.7547095802, + 0.7431448255, 0.7313537016, 0.7193398003, 0.7071067812, + 0.6946583705, 0.6819983601, 0.6691306064, 0.6560590290, + 0.6427876097, 0.6293203910, 0.6156614753, 0.6018150232, + 0.5877852523, 0.5735764364, 0.5591929035, 0.5446390350, + 0.5299192642, 0.5150380749, 0.5000000000, 0.4848096202, + 0.4694715628, 0.4539904997, 0.4383711468, 0.4226182617, + 0.4067366431, 0.3907311285, 0.3746065934, 0.3583679495, + 0.3420201433, 0.3255681545, 0.3090169944, 0.2923717047, + 0.2756373558, 0.2588190451, 0.2419218956, 0.2249510543, + 0.2079116908, 0.1908089954, 0.1736481777, 0.1564344650, + 0.1391731010, 0.1218693434, 0.1045284633, 0.0871557427, + 0.0697564737, 0.0523359562, 0.0348994967, 0.0174524064, + 0.0000000000, -0.0174524064, -0.0348994967, -0.0523359562, + -0.0697564737, -0.0871557427, -0.1045284633, -0.1218693434, + -0.1391731010, -0.1564344650, -0.1736481777, -0.1908089954, + -0.2079116908, -0.2249510543, -0.2419218956, -0.2588190451, + -0.2756373558, -0.2923717047, -0.3090169944, -0.3255681545, + -0.3420201433, -0.3583679495, -0.3746065934, -0.3907311285, + -0.4067366431, -0.4226182617, -0.4383711468, -0.4539904997, + -0.4694715628, -0.4848096202, -0.5000000000, -0.5150380749, + -0.5299192642, -0.5446390350, -0.5591929035, -0.5735764364, + -0.5877852523, -0.6018150232, -0.6156614753, -0.6293203910, + -0.6427876097, -0.6560590290, -0.6691306064, -0.6819983601, + -0.6946583705, -0.7071067812, -0.7193398003, -0.7313537016, + -0.7431448255, -0.7547095802, -0.7660444431, -0.7771459615, + -0.7880107536, -0.7986355100, -0.8090169944, -0.8191520443, + -0.8290375726, -0.8386705679, -0.8480480962, -0.8571673007, + -0.8660254038, -0.8746197071, -0.8829475929, -0.8910065242, + -0.8987940463, -0.9063077870, -0.9135454576, -0.9205048535, + -0.9271838546, -0.9335804265, -0.9396926208, -0.9455185756, + -0.9510565163, -0.9563047560, -0.9612616959, -0.9659258263, + -0.9702957263, -0.9743700648, -0.9781476007, -0.9816271834, + -0.9848077530, -0.9876883406, -0.9902680687, -0.9925461516, + -0.9945218954, -0.9961946981, -0.9975640503, -0.9986295348, + -0.9993908270, -0.9998476952, -1.0000000000, -0.9998476952, + -0.9993908270, -0.9986295348, -0.9975640503, -0.9961946981, + -0.9945218954, -0.9925461516, -0.9902680687, -0.9876883406, + -0.9848077530, -0.9816271834, -0.9781476007, -0.9743700648, + -0.9702957263, -0.9659258263, -0.9612616959, -0.9563047560, + -0.9510565163, -0.9455185756, -0.9396926208, -0.9335804265, + -0.9271838546, -0.9205048535, -0.9135454576, -0.9063077870, + -0.8987940463, -0.8910065242, -0.8829475929, -0.8746197071, + -0.8660254038, -0.8571673007, -0.8480480962, -0.8386705679, + -0.8290375726, -0.8191520443, -0.8090169944, -0.7986355100, + -0.7880107536, -0.7771459615, -0.7660444431, -0.7547095802, + -0.7431448255, -0.7313537016, -0.7193398003, -0.7071067812, + -0.6946583705, -0.6819983601, -0.6691306064, -0.6560590290, + -0.6427876097, -0.6293203910, -0.6156614753, -0.6018150232, + -0.5877852523, -0.5735764364, -0.5591929035, -0.5446390350, + -0.5299192642, -0.5150380749, -0.5000000000, -0.4848096202, + -0.4694715628, -0.4539904997, -0.4383711468, -0.4226182617, + -0.4067366431, -0.3907311285, -0.3746065934, -0.3583679495, + -0.3420201433, -0.3255681545, -0.3090169944, -0.2923717047, + -0.2756373558, -0.2588190451, -0.2419218956, -0.2249510543, + -0.2079116908, -0.1908089954, -0.1736481777, -0.1564344650, + -0.1391731010, -0.1218693434, -0.1045284633, -0.0871557427, + -0.0697564737, -0.0523359562, -0.0348994967, -0.0174524064 +}; + +static void test_math_trig_sin_fixed(void **state) +{ + (void)state; + + int theta; + + for (theta = 0; theta < 360; ++theta) { + double rad = M_PI / (180.0 / theta); + int32_t rad_q28 = Q_CONVERT_FLOAT(rad, 28); + + float r = Q_CONVERT_QTOF(sin_fixed(rad_q28), 31); + float diff = fabsf(sin_ref_table[theta] - r); + + if (diff > CMP_TOLERANCE) { + printf("%s: diff for %d deg = %.10f\n", __func__, + theta, diff); + } + + assert_true(diff <= CMP_TOLERANCE); + } +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_math_trig_sin_fixed) + }; + + cmocka_set_message_output(CM_OUTPUT_TAP); + + return cmocka_run_group_tests(tests, NULL, NULL); +}