From e00f3a9ede1b8e46b480bd68daf48da0bb08acae Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Thu, 4 Sep 2025 01:11:11 +0200 Subject: Initial --- test/rtt_test.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/rtt_test.c (limited to 'test/rtt_test.c') 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 @@ +#include +#include + +#define SENT_TIME_1_MS 1000 +#define NOW_TIME_1_MS 1500 +#define RTT_POSITIVE_EXPECTED 500 + +#define SENT_TIME_2_MS 2000 +#define NOW_TIME_2_MS 2000 +#define RTT_ZERO_EXPECTED 0 + +#define SENT_TIME_3_MS 3000 +#define NOW_TIME_3_MS 2500 +#define RTT_NEGATIVE_EXPECTED (-500) + +/* + * calculate_rtt - calculate round-trip time + * @sent_ms: time when message was sent (ms) + * @now_ms: current time (ms) + * + * Return: RTT in milliseconds (now_ms - sent_ms) + */ +static int32_t calculate_rtt(int32_t sent_ms, int32_t now_ms) +{ + return now_ms - sent_ms; +} + +static void test_rtt_positive_difference(void) +{ + TEST_ASSERT_EQUAL_INT32(RTT_POSITIVE_EXPECTED, + calculate_rtt(SENT_TIME_1_MS, NOW_TIME_1_MS)); +} + +static void test_rtt_zero_difference(void) +{ + TEST_ASSERT_EQUAL_INT32(RTT_ZERO_EXPECTED, + calculate_rtt(SENT_TIME_2_MS, NOW_TIME_2_MS)); +} + +static void test_rtt_negative_difference(void) +{ + TEST_ASSERT_EQUAL_INT32(RTT_NEGATIVE_EXPECTED, + calculate_rtt(SENT_TIME_3_MS, NOW_TIME_3_MS)); +} + +int app_main(void) +{ + UNITY_BEGIN(); + + RUN_TEST(test_rtt_positive_difference); + RUN_TEST(test_rtt_zero_difference); + RUN_TEST(test_rtt_negative_difference); + + return UNITY_END(); +} -- cgit v1.2.3