Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Sat May 04 16:56:04 2019 +0000
Revision:
68:b9cfd27987ac
Child:
69:55e309da7efd
Added test headers and functions that makes sure that my snake moves and updates as expected.

Who changed what in which revision?

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