xref: /aosp_15_r20/external/coreboot/tests/commonlib/bsd/gcd-test.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <commonlib/bsd/gcd.h>
4 #include <tests/test.h>
5 
test_gcd(void ** state)6 static void test_gcd(void **state)
7 {
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);
23 }
24 
main(void)25 int main(void)
26 {
27 	const struct CMUnitTest tests[] = {
28 		cmocka_unit_test(test_gcd),
29 	};
30 
31 	return cb_run_group_tests(tests, NULL, NULL);
32 }
33