aboutsummaryrefslogtreecommitdiffstats
path: root/test/rtt_test.c
diff options
context:
space:
mode:
authorFilip Wandzio <contact@philw.dev>2025-09-04 01:11:11 +0200
committerFilip Wandzio <contact@philw.dev>2025-09-04 01:11:11 +0200
commite00f3a9ede1b8e46b480bd68daf48da0bb08acae (patch)
treef666b9aa4d0a03246ab9880e11802d91a23ab1e7 /test/rtt_test.c
downloade1-e00f3a9ede1b8e46b480bd68daf48da0bb08acae.tar.gz
e1-e00f3a9ede1b8e46b480bd68daf48da0bb08acae.zip
Initial
Diffstat (limited to 'test/rtt_test.c')
-rw-r--r--test/rtt_test.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/rtt_test.c b/test/rtt_test.c
new file mode 100644
index 0000000..cdedabd
--- /dev/null
+++ b/test/rtt_test.c
@@ -0,0 +1,55 @@
1#include <stdint.h>
2#include <unity.h>
3
4#define SENT_TIME_1_MS 1000
5#define NOW_TIME_1_MS 1500
6#define RTT_POSITIVE_EXPECTED 500
7
8#define SENT_TIME_2_MS 2000
9#define NOW_TIME_2_MS 2000
10#define RTT_ZERO_EXPECTED 0
11
12#define SENT_TIME_3_MS 3000
13#define NOW_TIME_3_MS 2500
14#define RTT_NEGATIVE_EXPECTED (-500)
15
16/*
17 * calculate_rtt - calculate round-trip time
18 * @sent_ms: time when message was sent (ms)
19 * @now_ms: current time (ms)
20 *
21 * Return: RTT in milliseconds (now_ms - sent_ms)
22 */
23static int32_t calculate_rtt(int32_t sent_ms, int32_t now_ms)
24{
25 return now_ms - sent_ms;
26}
27
28static void test_rtt_positive_difference(void)
29{
30 TEST_ASSERT_EQUAL_INT32(RTT_POSITIVE_EXPECTED,
31 calculate_rtt(SENT_TIME_1_MS, NOW_TIME_1_MS));
32}
33
34static void test_rtt_zero_difference(void)
35{
36 TEST_ASSERT_EQUAL_INT32(RTT_ZERO_EXPECTED,
37 calculate_rtt(SENT_TIME_2_MS, NOW_TIME_2_MS));
38}
39
40static void test_rtt_negative_difference(void)
41{
42 TEST_ASSERT_EQUAL_INT32(RTT_NEGATIVE_EXPECTED,
43 calculate_rtt(SENT_TIME_3_MS, NOW_TIME_3_MS));
44}
45
46int app_main(void)
47{
48 UNITY_BEGIN();
49
50 RUN_TEST(test_rtt_positive_difference);
51 RUN_TEST(test_rtt_zero_difference);
52 RUN_TEST(test_rtt_negative_difference);
53
54 return UNITY_END();
55}