Skip to content

Commit 4b77cbd

Browse files
committed
tests for fequal dequal
1 parent ca9bac0 commit 4b77cbd

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

misc/force-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7.12-dev:::2024-07-18_12:07:19
1+
3.7.12-dev:::2024-07-18_13:26:45

src/unit-testing/test_utils-cl.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,39 @@ void setUp(void) { }
66

77
void tearDown(void) { }
88

9+
void test_fequal_Should_ReturnTrue_ForEqualFloats(void) {
10+
TEST_ASSERT_TRUE(fequal(1.0f, 1.0f));
11+
TEST_ASSERT_TRUE(fequal(0.0f, 0.0f));
12+
TEST_ASSERT_TRUE(fequal(-1.0f, -1.0f));
13+
}
14+
15+
void test_fequal_Should_ReturnTrue_ForNearlyEqualFloats(void) {
16+
TEST_ASSERT_TRUE(fequal(1.0f, 1.0f + FLT_EPSILON / 2.0));
17+
TEST_ASSERT_TRUE(fequal(1.0f, 1.0f - FLT_EPSILON / 2.0));
18+
}
19+
20+
void test_fequal_Should_ReturnFalse_ForDifferentFloats(void) {
21+
TEST_ASSERT_FALSE(fequal(1.0f, 2.0f));
22+
TEST_ASSERT_FALSE(fequal(0.0f, FLT_EPSILON));
23+
}
24+
25+
void test_dequal_Should_ReturnTrue_ForEqualDoubles(void) {
26+
TEST_ASSERT_TRUE(dequal(1.0, 1.0));
27+
TEST_ASSERT_TRUE(dequal(0.0, 0.0));
28+
TEST_ASSERT_TRUE(dequal(-1.0, -1.0));
29+
}
30+
31+
void test_dequal_Should_ReturnTrue_ForNearlyEqualDoubles(void) {
32+
TEST_ASSERT_TRUE(dequal(1.0, 1.0 + DBL_EPSILON / 2.0));
33+
TEST_ASSERT_TRUE(dequal(1.0, 1.0 - DBL_EPSILON / 2.0));
34+
}
35+
36+
void test_dequal_Should_ReturnFalse_ForDifferentDoubles(void) {
37+
TEST_ASSERT_FALSE(dequal(1.0, 2.0));
38+
TEST_ASSERT_FALSE(dequal(0.0, DBL_EPSILON));
39+
}
40+
41+
942
void test_num_decimal_places_SingleDigit(void) {
1043
TEST_ASSERT_EQUAL_INT(1, num_decimal_places(0));
1144
TEST_ASSERT_EQUAL_INT(1, num_decimal_places(5));
@@ -34,6 +67,14 @@ int main(void) {
3467

3568
UNITY_BEGIN();
3669

70+
RUN_TEST(test_fequal_Should_ReturnTrue_ForEqualFloats);
71+
RUN_TEST(test_fequal_Should_ReturnTrue_ForNearlyEqualFloats);
72+
RUN_TEST(test_fequal_Should_ReturnFalse_ForDifferentFloats);
73+
74+
RUN_TEST(test_dequal_Should_ReturnTrue_ForEqualDoubles);
75+
RUN_TEST(test_dequal_Should_ReturnTrue_ForNearlyEqualDoubles);
76+
RUN_TEST(test_dequal_Should_ReturnFalse_ForDifferentDoubles);
77+
3778
RUN_TEST(test_num_decimal_places_SingleDigit);
3879
RUN_TEST(test_num_decimal_places_MultipleDigit);
3980
RUN_TEST(test_num_decimal_places_NegativeNumbers);

0 commit comments

Comments
 (0)