
Final Commit
Dependencies: mbed
Food/Food-test.h@27:bd0f69a75d8b, 2018-05-08 (annotated)
- Committer:
- JRM1986
- Date:
- Tue May 08 12:32:46 2018 +0000
- Revision:
- 27:bd0f69a75d8b
- Parent:
- 25:f03439ee32c6
Final Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JRM1986 | 25:f03439ee32c6 | 1 | #ifndef FOOD_TEST_H |
JRM1986 | 25:f03439ee32c6 | 2 | #define FOOD_TEST_H |
JRM1986 | 25:f03439ee32c6 | 3 | |
JRM1986 | 25:f03439ee32c6 | 4 | /** |
JRM1986 | 25:f03439ee32c6 | 5 | * \brief Check that food changes position within game area |
JRM1986 | 25:f03439ee32c6 | 6 | * |
JRM1986 | 25:f03439ee32c6 | 7 | * \returns true if all the tests passed |
JRM1986 | 25:f03439ee32c6 | 8 | */ |
JRM1986 | 25:f03439ee32c6 | 9 | |
JRM1986 | 25:f03439ee32c6 | 10 | bool food_test_position() |
JRM1986 | 25:f03439ee32c6 | 11 | { |
JRM1986 | 25:f03439ee32c6 | 12 | |
JRM1986 | 25:f03439ee32c6 | 13 | Food food; |
JRM1986 | 25:f03439ee32c6 | 14 | int i; |
JRM1986 | 25:f03439ee32c6 | 15 | int frame_count = g_fc; |
JRM1986 | 25:f03439ee32c6 | 16 | |
JRM1986 | 25:f03439ee32c6 | 17 | // initialise food with a collision |
JRM1986 | 25:f03439ee32c6 | 18 | food.set_food_position(1,1,true); |
JRM1986 | 25:f03439ee32c6 | 19 | |
JRM1986 | 25:f03439ee32c6 | 20 | // get a random position |
JRM1986 | 25:f03439ee32c6 | 21 | |
JRM1986 | 25:f03439ee32c6 | 22 | Vector2D rand_pos = food.get_rand_pos(); |
JRM1986 | 25:f03439ee32c6 | 23 | printf("%f, %f \n", rand_pos.x, rand_pos.y); |
JRM1986 | 25:f03439ee32c6 | 24 | |
JRM1986 | 25:f03439ee32c6 | 25 | bool success_flag = true; |
JRM1986 | 25:f03439ee32c6 | 26 | |
JRM1986 | 25:f03439ee32c6 | 27 | // if the random position is within the screen boundaries return true |
JRM1986 | 25:f03439ee32c6 | 28 | |
JRM1986 | 25:f03439ee32c6 | 29 | if((0 >= rand_pos.x >= 83) && (0 >= rand_pos.y >= 47)) { |
JRM1986 | 25:f03439ee32c6 | 30 | |
JRM1986 | 25:f03439ee32c6 | 31 | success_flag = false; |
JRM1986 | 25:f03439ee32c6 | 32 | |
JRM1986 | 25:f03439ee32c6 | 33 | } |
JRM1986 | 25:f03439ee32c6 | 34 | |
JRM1986 | 25:f03439ee32c6 | 35 | for(i = 0; i <=1; i++) { |
JRM1986 | 25:f03439ee32c6 | 36 | |
JRM1986 | 25:f03439ee32c6 | 37 | // check update method |
JRM1986 | 25:f03439ee32c6 | 38 | |
JRM1986 | 25:f03439ee32c6 | 39 | food.update(true, 0); |
JRM1986 | 25:f03439ee32c6 | 40 | |
JRM1986 | 25:f03439ee32c6 | 41 | // get new positions |
JRM1986 | 25:f03439ee32c6 | 42 | wait(1.0); |
JRM1986 | 25:f03439ee32c6 | 43 | Vector2D rand_pos_1 = food.get_rand_pos(); |
JRM1986 | 25:f03439ee32c6 | 44 | printf("%f, %f \n", rand_pos_1.x, rand_pos_1.y); |
JRM1986 | 25:f03439ee32c6 | 45 | |
JRM1986 | 25:f03439ee32c6 | 46 | if((rand_pos.x == rand_pos_1.x) && (rand_pos.y == rand_pos_1.y)) { |
JRM1986 | 25:f03439ee32c6 | 47 | |
JRM1986 | 25:f03439ee32c6 | 48 | success_flag = false; |
JRM1986 | 25:f03439ee32c6 | 49 | |
JRM1986 | 25:f03439ee32c6 | 50 | } |
JRM1986 | 25:f03439ee32c6 | 51 | |
JRM1986 | 25:f03439ee32c6 | 52 | |
JRM1986 | 25:f03439ee32c6 | 53 | printf("%i\n", frame_count); |
JRM1986 | 25:f03439ee32c6 | 54 | |
JRM1986 | 25:f03439ee32c6 | 55 | } |
JRM1986 | 25:f03439ee32c6 | 56 | |
JRM1986 | 25:f03439ee32c6 | 57 | // check counter increments in update |
JRM1986 | 25:f03439ee32c6 | 58 | |
JRM1986 | 25:f03439ee32c6 | 59 | if(frame_count != 0) { |
JRM1986 | 25:f03439ee32c6 | 60 | |
JRM1986 | 25:f03439ee32c6 | 61 | success_flag = false; |
JRM1986 | 25:f03439ee32c6 | 62 | |
JRM1986 | 25:f03439ee32c6 | 63 | } |
JRM1986 | 25:f03439ee32c6 | 64 | |
JRM1986 | 25:f03439ee32c6 | 65 | |
JRM1986 | 25:f03439ee32c6 | 66 | return success_flag; |
JRM1986 | 25:f03439ee32c6 | 67 | |
JRM1986 | 25:f03439ee32c6 | 68 | } |
JRM1986 | 25:f03439ee32c6 | 69 | |
JRM1986 | 25:f03439ee32c6 | 70 | #endif |