forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gcd_ztest.c
More file actions
120 lines (102 loc) · 2.5 KB
/
test_gcd_ztest.c
File metadata and controls
120 lines (102 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2025 Intel Corporation. All rights reserved.
//
// These contents may have been developed with support from one or more Intel-operated
// generative artificial intelligence solutions.
//
// Converted from CMock to Ztest
#include <zephyr/ztest.h>
#include <sof/math/numbers.h>
/**
* @brief Test GCD function with typical case
*
* Tests that gcd(5083, 391) returns 391
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_5083_and_391_equals_391)
{
int r;
r = gcd(5083, 391);
zassert_equal(r, 391, "gcd(5083, 391) should equal 391");
}
/**
* @brief Test GCD function with small positive numbers
*
* Tests that gcd(12, 9) returns 3
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_12_and_9_equals_3)
{
int r;
r = gcd(12, 9);
zassert_equal(r, 3, "gcd(12, 9) should equal 3");
}
/**
* @brief Test GCD function with zero second argument
*
* Tests that gcd(5, 0) returns 5
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_5_and_0_equals_5)
{
int r;
r = gcd(5, 0);
zassert_equal(r, 5, "gcd(5, 0) should equal 5");
}
/**
* @brief Test GCD function with zero first argument
*
* Tests that gcd(0, 5) returns 5
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_0_and_5_equals_5)
{
int r;
r = gcd(0, 5);
zassert_equal(r, 5, "gcd(0, 5) should equal 5");
}
/**
* @brief Test GCD function with both arguments zero
*
* Tests that gcd(0, 0) returns 0
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_0_and_0_equals_0)
{
int r;
r = gcd(0, 0);
zassert_equal(r, 0, "gcd(0, 0) should equal 0");
}
/**
* @brief Test GCD function with negative first argument
*
* Tests that gcd(-4, 14) returns 2
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_neg_4_and_14_equals_2)
{
int r;
r = gcd(-4, 14);
zassert_equal(r, 2, "gcd(-4, 14) should equal 2");
}
/**
* @brief Test GCD function with negative second argument
*
* Tests that gcd(4, -14) returns 2
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_4_and_neg_14_equals_2)
{
int r;
r = gcd(4, -14);
zassert_equal(r, 2, "gcd(4, -14) should equal 2");
}
/**
* @brief Test GCD function with both arguments negative
*
* Tests that gcd(-4, -14) returns 2
*/
ZTEST(math_arithmetic_suite, test_math_numbers_gcd_for_neg_4_and_neg_14_equals_2)
{
int r;
r = gcd(-4, -14);
zassert_equal(r, 2, "gcd(-4, -14) should equal 2");
}
/**
* @brief Define and initialize the math arithmetic test suite
*/
ZTEST_SUITE(math_arithmetic_suite, NULL, NULL, NULL, NULL, NULL);