From 303ed59e8755b1006a08f7e18e61fe745dc6c07c Mon Sep 17 00:00:00 2001 From: Iulian Olaru Date: Sat, 22 Feb 2020 11:32:34 +0200 Subject: [PATCH] test: Add extra tests fot gcd This patch adds extra tests for the gcd of (0, 0), (a, 0), (0, b), (-a, -b), (-a, b), (a, -b) Signed-off-by: Iulian Olaru --- test/cmocka/src/math/numbers/gcd.c | 73 +++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/test/cmocka/src/math/numbers/gcd.c b/test/cmocka/src/math/numbers/gcd.c index 8fcab94fc..23f2dad21 100644 --- a/test/cmocka/src/math/numbers/gcd.c +++ b/test/cmocka/src/math/numbers/gcd.c @@ -17,7 +17,7 @@ static void test_math_numbers_gcd_for_5083_and_391_equals_391(void **state) { int r; - (void) state; + (void)state; r = gcd(5083, 391); assert_int_equal(r, 391); @@ -27,18 +27,87 @@ static void test_math_numbers_gcd_for_12_and_9_equals_3(void **state) { int r; - (void) state; + (void)state; r = gcd(12, 9); assert_int_equal(r, 3); } +static void test_math_numbers_gcd_for_5_and_0_equals_5(void **state) +{ + int r; + + (void)state; + + r = gcd(5, 0); + assert_int_equal(r, 5); +} + +static void test_math_numbers_gcd_for_0_and_5_equals_5(void **state) +{ + int r; + + (void)state; + + r = gcd(0, 5); + assert_int_equal(r, 5); +} + +static void test_math_numbers_gcd_for_0_and_0_equals_0(void **state) +{ + int r; + + (void)state; + + r = gcd(0, 0); + assert_int_equal(r, 0); +} + +static void test_math_numbers_gcd_for_neg_4_and_14_equals_2(void **state) +{ + int r; + + (void)state; + + r = gcd(-4, 14); + assert_int_equal(r, 2); +} + +static void test_math_numbers_gcd_for_4_and_neg_14_equals_2(void **state) +{ + int r; + + (void)state; + + r = gcd(4, -14); + assert_int_equal(r, 2); +} + +static void test_math_numbers_gcd_for_neg_4_and_neg_14_equals_2(void **state) +{ + int r; + + (void)state; + + r = gcd(-4, -14); + assert_int_equal(r, 2); +} + 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_12_and_9_equals_3), + cmocka_unit_test(test_math_numbers_gcd_for_5_and_0_equals_5), + cmocka_unit_test(test_math_numbers_gcd_for_0_and_5_equals_5), + cmocka_unit_test(test_math_numbers_gcd_for_0_and_0_equals_0), + cmocka_unit_test + (test_math_numbers_gcd_for_neg_4_and_14_equals_2), + cmocka_unit_test + (test_math_numbers_gcd_for_4_and_neg_14_equals_2), + cmocka_unit_test + (test_math_numbers_gcd_for_neg_4_and_neg_14_equals_2) }; cmocka_set_message_output(CM_OUTPUT_TAP);