#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(); }