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 <iulianolaru249@yahoo.com>
This commit is contained in:
Iulian Olaru 2020-02-22 11:32:34 +02:00 committed by Liam Girdwood
parent ea9aebfa7a
commit 303ed59e87
1 changed files with 71 additions and 2 deletions

View File

@ -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);