Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
testing.cpp
- Committer:
- sbouber1
- Date:
- 2016-06-14
- Revision:
- 30:cf12566013a5
- Parent:
- 28:f4a4ee58d57e
- Child:
- 31:1c50d2d8c155
File content as of revision 30:cf12566013a5:
#include "mbed.h" #include "MockSensorController.h" #include "AlarmController.h" #include "testing.h" #define NUMBER_OF_SEC_BEFORE_CRITICAL_ALARM 30 #define NUMBER_OF_SEC_BEFORE_UNDESIRED_ALARM 300 void TestCase::assertTrue(bool b, const char *error) { if(!b) { printf("[%s] ASSERTION FAILED: %s\r\n", this->name, error); this->failed = true; } } MOCK(temp_mock_steady, 35.0); MOCK(salt_mock_steady, 6.1); MOCK(prox_mock_steady, 10.0); MOCK(temp_mock1, 40.1+(t/1000.0)); ALARM_TEST(testTempDangerousHighAlarm, temp_mock1, salt_mock_steady, prox_mock_steady, NUMBER_OF_SEC_BEFORE_CRITICAL_ALARM+1); MOCK(temp_mock2, 29.9-(t/1000.0)); ALARM_TEST(testTempDangerousLowAlarm, temp_mock2, salt_mock_steady, prox_mock_steady, NUMBER_OF_SEC_BEFORE_CRITICAL_ALARM+1); MOCK(temp_mock3, 30+t*0.000001); ALARM_TEST(testTempLowRangeAlarm, temp_mock3, salt_mock_steady, prox_mock_steady, NUMBER_OF_SEC_BEFORE_UNDESIRED_ALARM+1); MOCK(temp_mock4, 38+t*0.000001); ALARM_TEST(testTempHighRangeAlarm, temp_mock4, salt_mock_steady, prox_mock_steady, NUMBER_OF_SEC_BEFORE_UNDESIRED_ALARM+1); MOCK(overflow_undesired_mock, 900+(t/4000.0)); ALARM_TEST(testAlarmWaterOverflowUndesired, temp_mock_steady, salt_mock_steady, overflow_undesired_mock, NUMBER_OF_SEC_BEFORE_UNDESIRED_ALARM+1); MOCK(overflow_critical_mock, 1001+(t/4000.0)); ALARM_TEST(testAlarmWaterOverflowCritical, temp_mock_steady, salt_mock_steady, overflow_critical_mock, NUMBER_OF_SEC_BEFORE_CRITICAL_ALARM+1); MOCK(leak_undesired_mock, 1+(t/4000.0)); ALARM_TEST(testAlarmWaterLeakUndesired, temp_mock_steady, salt_mock_steady, leak_undesired_mock, NUMBER_OF_SEC_BEFORE_UNDESIRED_ALARM+1); MOCK(leak_critical_mock, -1-(t/4000.0)); ALARM_TEST(testAlarmWaterLeakCritical, temp_mock_steady, salt_mock_steady, leak_critical_mock, NUMBER_OF_SEC_BEFORE_UNDESIRED_ALARM+1); bool testTemperatureHeater(TestCase *tc) { // TODO return true; } int test_main() { TestCase("Test if alarm is raised when temp > 40 for 30 seconds", testTempDangerousHighAlarm); TestCase("Test if alarm is raised when temp < 30 for 30 seconds", testTempDangerousLowAlarm); TestCase("Test if alarm is raised when temp > 30 and < 32 for 300 seconds", testTempLowRangeAlarm); TestCase("Test if alarm is raised when temp > 38 and < 40 for 300 seconds", testTempHighRangeAlarm); //TestCase("Test if heater gets enabled at < 32 and disabled at 32+", testTemperatureHeater); TestCase("Test if alarm is raised when water tank level in range 900-1000 ml for 5 minutes", testAlarmWaterOverflowUndesired); TestCase("Test if alarm is raised when water tank level is 1001 for 30 seconds", testAlarmWaterOverflowCritical); TestCase("Test if alarm is raised when water tank level is in range 0-100 ml for 5 minutes", testAlarmWaterLeakUndesired); TestCase("Test if alarm is raised when water tank level is < 0 for 30 seconds", testAlarmWaterLeakCritical); return 0; }