From a0612586694229e0ee80bb93a5956f671dd7d151 Mon Sep 17 00:00:00 2001 From: jakeg00dwin Date: Sat, 27 Jul 2024 09:42:40 -0700 Subject: [PATCH] Moved static helper function to top of tests. Extracted now uneeded expectations from tests. --- .../test_zero_cross_detection.cpp | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/tests/zero_cross_detection/test_zero_cross_detection.cpp b/tests/zero_cross_detection/test_zero_cross_detection.cpp index 197d336..b3876b0 100644 --- a/tests/zero_cross_detection/test_zero_cross_detection.cpp +++ b/tests/zero_cross_detection/test_zero_cross_detection.cpp @@ -32,40 +32,6 @@ TEST_GROUP(test_zero_cross_detection) } }; -TEST(test_zero_cross_detection, ZCD_SetupCallsCorrectFuncs) -{ - mock().expectOneCall("ADC_Init") - .withUnsignedIntParameter("pin_num", 7); - - mock().expectOneCall("ADC_Enable") - .withUnsignedIntParameter("pin_num", 7); - - ZCD_Setup(); -} - -TEST(test_zero_cross_detection, ZCD_IsTriggeredCallsCorrectFunctions) -{ - MockADC_ZeroIndex(); - - mock().expectNCalls(2, "ADC_ReadValue_Impl") - .withUnsignedIntParameter("pin_num", 7); - - CHECK_FALSE(ZCD_IsTriggered()); -} - - -TEST(test_zero_cross_detection, ZCD_IsTriggerdTrueWhenRising) -{ - MockADC_ZeroIndex(); - MockADC_PushValue(512); - MockADC_PushValue(450); - - mock().expectNCalls(2, "ADC_ReadValue_Impl") - .withUnsignedIntParameter("pin_num", 7) - .ignoreOtherParameters(); - - CHECK_TRUE(ZCD_IsTriggered()); -} static void PollIterationExpectations(void) { @@ -95,6 +61,41 @@ static void PollIterationExpectations(void) } +TEST(test_zero_cross_detection, ZCD_SetupCallsCorrectFuncs) +{ + mock().expectOneCall("ADC_Init") + .withUnsignedIntParameter("pin_num", 7); + + mock().expectOneCall("ADC_Enable") + .withUnsignedIntParameter("pin_num", 7); + + ZCD_Setup(); +} + + +TEST(test_zero_cross_detection, ZCD_IsTriggeredCallsCorrectFunctions) +{ + MockADC_ZeroIndex(); + + PollIterationExpectations(); + + CHECK_FALSE(ZCD_IsTriggered()); +} + + +TEST(test_zero_cross_detection, ZCD_IsTriggerdTrueWhenRising) +{ + MockADC_ZeroIndex(); + + MockADC_PushValue(512); + MockADC_PushValue(450); + + PollIterationExpectations(); + + CHECK_TRUE(ZCD_IsTriggered()); +} + + TEST(test_zero_cross_detection, ZCD_PollWorksAfterCalls) { MockADC_ZeroIndex();