Wang Lin 201090174

Dependencies:   mbed Gamepad N5110 FXOS8700Q

Committer:
valavanisalex
Date:
Mon Apr 16 17:53:30 2018 +0000
Revision:
9:6e8964c19459
Added unit test example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
valavanisalex 9:6e8964c19459 1 #ifndef TESTS_H
valavanisalex 9:6e8964c19459 2 #define TESTS_H
valavanisalex 9:6e8964c19459 3
valavanisalex 9:6e8964c19459 4 #include "Ball-test.h"
valavanisalex 9:6e8964c19459 5
valavanisalex 9:6e8964c19459 6 /**
valavanisalex 9:6e8964c19459 7 * @brief Run all the tests for this program
valavanisalex 9:6e8964c19459 8 *
valavanisalex 9:6e8964c19459 9 * @returns The number of tests that failed
valavanisalex 9:6e8964c19459 10 */
valavanisalex 9:6e8964c19459 11 int run_all_tests()
valavanisalex 9:6e8964c19459 12 {
valavanisalex 9:6e8964c19459 13 int n_tests_failed = 0;
valavanisalex 9:6e8964c19459 14
valavanisalex 9:6e8964c19459 15 // Run the Ball_check_movement test
valavanisalex 9:6e8964c19459 16 printf("Testing Ball_check_movement...\n");
valavanisalex 9:6e8964c19459 17 bool this_test_passed = Ball_test_movement();
valavanisalex 9:6e8964c19459 18
valavanisalex 9:6e8964c19459 19 if (this_test_passed) {
valavanisalex 9:6e8964c19459 20 printf("...Passed!\n");
valavanisalex 9:6e8964c19459 21 }
valavanisalex 9:6e8964c19459 22 else {
valavanisalex 9:6e8964c19459 23 printf("...FAILED!\n");
valavanisalex 9:6e8964c19459 24 ++n_tests_failed; // Increment number of failures
valavanisalex 9:6e8964c19459 25 }
valavanisalex 9:6e8964c19459 26
valavanisalex 9:6e8964c19459 27
valavanisalex 9:6e8964c19459 28 // Repeat the above for each testing function...
valavanisalex 9:6e8964c19459 29
valavanisalex 9:6e8964c19459 30 if (n_tests_failed > 0) {
valavanisalex 9:6e8964c19459 31 printf("%d tests FAILED!\n", n_tests_failed);
valavanisalex 9:6e8964c19459 32 }
valavanisalex 9:6e8964c19459 33 else {
valavanisalex 9:6e8964c19459 34 printf("All tests passed!\n");
valavanisalex 9:6e8964c19459 35 }
valavanisalex 9:6e8964c19459 36
valavanisalex 9:6e8964c19459 37 return n_tests_failed;
valavanisalex 9:6e8964c19459 38 }
valavanisalex 9:6e8964c19459 39
valavanisalex 9:6e8964c19459 40 #endif