1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/bsd/gcd.h>
4 #include <tests/test.h>
6 static void test_gcd(void **state
)
8 assert_int_equal(gcd(17, 11), 1);
9 assert_int_equal(gcd(64, 36), 4);
10 assert_int_equal(gcd(90, 123), 3);
11 assert_int_equal(gcd(65536, 339584), 128);
12 assert_int_equal(gcd(1, 1), 1);
13 assert_int_equal(gcd(1, 123), 1);
14 assert_int_equal(gcd(123, 1), 1);
15 assert_int_equal(gcd(1, UINT32_MAX
), 1);
16 assert_int_equal(gcd(UINT32_MAX
, 1), 1);
17 assert_int_equal(gcd(UINT32_MAX
, UINT32_MAX
), UINT32_MAX
);
18 assert_int_equal(gcd(1, UINT64_MAX
), 1);
19 assert_int_equal(gcd(UINT64_MAX
, 1), 1);
20 assert_int_equal(gcd(UINT64_MAX
, UINT64_MAX
), UINT64_MAX
);
21 assert_int_equal(gcd((uint64_t)UINT32_MAX
+ 1, UINT64_MAX
/ 2 + 1),
22 (uint64_t)UINT32_MAX
+ 1);
27 const struct CMUnitTest tests
[] = {
28 cmocka_unit_test(test_gcd
),
31 return cb_run_group_tests(tests
, NULL
, NULL
);