ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Committer:
el18jgb
Date:
Sat May 23 13:59:51 2020 +0000
Revision:
21:a0f3651f56c4
Parent:
13:cfdfe60a2327
Child:
22:7406068f6c59
polishing;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18jgb 13:cfdfe60a2327 1 #ifndef SPIKES_TEST_H
el18jgb 13:cfdfe60a2327 2 #define SPIKES_TEST_H
el18jgb 13:cfdfe60a2327 3
el18jgb 13:cfdfe60a2327 4 /** ENG Test
el18jgb 13:cfdfe60a2327 5 * @brief Checks that the calulate_map_movement caluclates correct map_movement
el18jgb 13:cfdfe60a2327 6 * @author Jospeh Body, University of Leeds
el18jgb 13:cfdfe60a2327 7 * @date May 2020
el18jgb 13:cfdfe60a2327 8 * @return true if test are passed
el18jgb 13:cfdfe60a2327 9 */
el18jgb 13:cfdfe60a2327 10
el18jgb 21:a0f3651f56c4 11 bool Spikes_test_updatey()
el18jgb 13:cfdfe60a2327 12 {
el18jgb 13:cfdfe60a2327 13 // Initialise
el18jgb 13:cfdfe60a2327 14 Spikes spikes;
el18jgb 21:a0f3651f56c4 15 spikes.position(2);
el18jgb 21:a0f3651f56c4 16
el18jgb 13:cfdfe60a2327 17 // Read the position
el18jgb 21:a0f3651f56c4 18 Vector2D read_pos = spikes.get_pos();
el18jgb 21:a0f3651f56c4 19 printf("%f, %f\n", read_pos.x, read_pos.y);
el18jgb 13:cfdfe60a2327 20
el18jgb 13:cfdfe60a2327 21 // Now check that both the position is as expected
el18jgb 13:cfdfe60a2327 22 bool success_flag = true;
el18jgb 13:cfdfe60a2327 23
el18jgb 21:a0f3651f56c4 24 //update position
el18jgb 21:a0f3651f56c4 25 spikes.updatey();
el18jgb 21:a0f3651f56c4 26
el18jgb 21:a0f3651f56c4 27 // Read the position
el18jgb 21:a0f3651f56c4 28 Vector2D read_pos_1 = spikes.get_pos();
el18jgb 21:a0f3651f56c4 29 printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
el18jgb 21:a0f3651f56c4 30
el18jgb 13:cfdfe60a2327 31 // Fail the test if the initial position is wrong
el18jgb 21:a0f3651f56c4 32 if (read_pos_1.x != read_pos.x || read_pos_1.y != read_pos.y +3 ) {
el18jgb 13:cfdfe60a2327 33 success_flag = false;
el18jgb 13:cfdfe60a2327 34 }
el18jgb 13:cfdfe60a2327 35
el18jgb 13:cfdfe60a2327 36 return success_flag;
el18jgb 13:cfdfe60a2327 37 }
el18jgb 21:a0f3651f56c4 38
el18jgb 21:a0f3651f56c4 39 bool Spikes_test_updatex()
el18jgb 21:a0f3651f56c4 40 {
el18jgb 21:a0f3651f56c4 41 // Initialise
el18jgb 21:a0f3651f56c4 42 Spikes spikes;
el18jgb 21:a0f3651f56c4 43 spikes.position(3);
el18jgb 21:a0f3651f56c4 44
el18jgb 21:a0f3651f56c4 45 // Read the position
el18jgb 21:a0f3651f56c4 46 Vector2D read_pos = spikes.get_pos();
el18jgb 21:a0f3651f56c4 47 printf("%f, %f\n", read_pos.x, read_pos.y);
el18jgb 21:a0f3651f56c4 48
el18jgb 21:a0f3651f56c4 49 // Now check that both the position is as expected
el18jgb 21:a0f3651f56c4 50 bool success_flag = true;
el18jgb 21:a0f3651f56c4 51
el18jgb 21:a0f3651f56c4 52 //update position
el18jgb 21:a0f3651f56c4 53 spikes.updatey();
el18jgb 21:a0f3651f56c4 54
el18jgb 21:a0f3651f56c4 55 // Read the position
el18jgb 21:a0f3651f56c4 56 Vector2D read_pos_1 = spikes.get_pos();
el18jgb 21:a0f3651f56c4 57 printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
el18jgb 21:a0f3651f56c4 58
el18jgb 21:a0f3651f56c4 59 // Fail the test if the initial position is wrong
el18jgb 21:a0f3651f56c4 60 if (read_pos_1.x != read_pos.x + 3 || read_pos_1.y != read_pos.y ) {
el18jgb 21:a0f3651f56c4 61 success_flag = false;
el18jgb 21:a0f3651f56c4 62 }
el18jgb 21:a0f3651f56c4 63
el18jgb 21:a0f3651f56c4 64 return success_flag;
el18jgb 21:a0f3651f56c4 65 }
el18jgb 21:a0f3651f56c4 66
el18jgb 21:a0f3651f56c4 67 bool Spikes_test_updatexn()
el18jgb 21:a0f3651f56c4 68 {
el18jgb 21:a0f3651f56c4 69 // Initialise
el18jgb 21:a0f3651f56c4 70 Spikes spikes;
el18jgb 21:a0f3651f56c4 71 spikes.position(4);
el18jgb 21:a0f3651f56c4 72
el18jgb 21:a0f3651f56c4 73 // Read the position
el18jgb 21:a0f3651f56c4 74 Vector2D read_pos = spikes.get_pos();
el18jgb 21:a0f3651f56c4 75 printf("%f, %f\n", read_pos.x, read_pos.y);
el18jgb 21:a0f3651f56c4 76
el18jgb 21:a0f3651f56c4 77 // Now check that both the position is as expected
el18jgb 21:a0f3651f56c4 78 bool success_flag = true;
el18jgb 21:a0f3651f56c4 79
el18jgb 21:a0f3651f56c4 80 //update position
el18jgb 21:a0f3651f56c4 81 spikes.updatey();
el18jgb 21:a0f3651f56c4 82
el18jgb 21:a0f3651f56c4 83 // Read the position
el18jgb 21:a0f3651f56c4 84 Vector2D read_pos_1 = spikes.get_pos();
el18jgb 21:a0f3651f56c4 85 printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
el18jgb 21:a0f3651f56c4 86
el18jgb 21:a0f3651f56c4 87 // Fail the test if the initial position is wrong
el18jgb 21:a0f3651f56c4 88 if (read_pos_1.x != read_pos.x - 3 || read_pos_1.y != read_pos.y ) {
el18jgb 21:a0f3651f56c4 89 success_flag = false;
el18jgb 21:a0f3651f56c4 90 }
el18jgb 21:a0f3651f56c4 91
el18jgb 21:a0f3651f56c4 92 return success_flag;
el18jgb 21:a0f3651f56c4 93 }
el18jgb 13:cfdfe60a2327 94 #endif