...
Positive test cases (test rational resistances)
Expect
calculate_current(0.0, 1.0) == 0.0
Expect
calculate_current(0.0, FLOAT_MAX) == 0.0
Negative test cases (test irrational resistances)
Expect
calculate_current(0.0, 0.0) == 0.0
(No runtime divide by 0 exception should occur)Expect
calculate_current(0.0, -1.0) == 0.0
(No runtime divide by 0 exception should occur)
...
Code Block |
---|
/** * @{ * @name Macros that give different meaning depending on if we are compiling for UTs or production code * * 'FOREVER' helps test loops as this code will only run once in your unit-tests * 'MAIN' helps test your application main() */ #ifdef UNIT_TESTING #define FOREVER for(bool __once = true; __once; __once = !__once) #define MAIN application_main #else #define FOREVER for(;;) #define MAIN main #endif /** @} */ /** * For production code, which is NOT UNIT_TEST, the NOOP() is truly a NOOP * For unit-test code, this helps spot branch coverage issues. Example use case: * @code * if (foo) { * } else { * NOOP("This branch should not happen"); * } * @endcode */ #ifdef UNIT_TESTING #define NOOP(message) \ do { \ volatile int _do_not_optimize = 0; \ (void) _do_not_optimize; \ } while (0) #else #define NOOP(message) #endif |
...
Code
...
Labs
Lab 1
Let us practice unit-testing, with a little bit of TDD thrown into the mix.
...