James Heavey / Mbed 2 deprecated 2665-Breakout-Game

Dependencies:   mbed

Committer:
jamesheavey
Date:
Tue Jan 05 01:14:11 2021 +0000
Revision:
0:92b180c8d407
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamesheavey 0:92b180c8d407 1 #ifndef LASER_TEST_H
jamesheavey 0:92b180c8d407 2 #define LASER_TEST_H
jamesheavey 0:92b180c8d407 3
jamesheavey 0:92b180c8d407 4 /**
jamesheavey 0:92b180c8d407 5 * \brief Check that Laser object goes to correct position when moved
jamesheavey 0:92b180c8d407 6 *
jamesheavey 0:92b180c8d407 7 * \returns true if all the tests passed
jamesheavey 0:92b180c8d407 8 */
jamesheavey 0:92b180c8d407 9 bool Laser_test_movement()
jamesheavey 0:92b180c8d407 10 {
jamesheavey 0:92b180c8d407 11 // Initialise Laser object at -10,0 with velocity of y as -2
jamesheavey 0:92b180c8d407 12 Laser _laser;
jamesheavey 0:92b180c8d407 13 _laser.init();
jamesheavey 0:92b180c8d407 14
jamesheavey 0:92b180c8d407 15 int read_pos1x = _laser.get_x();
jamesheavey 0:92b180c8d407 16 int read_pos1y = _laser.get_y();
jamesheavey 0:92b180c8d407 17
jamesheavey 0:92b180c8d407 18 // Read the position
jamesheavey 0:92b180c8d407 19 printf("%f, %f\n", read_pos1x, read_pos1y);
jamesheavey 0:92b180c8d407 20
jamesheavey 0:92b180c8d407 21 // Set the x position to 10, 0
jamesheavey 0:92b180c8d407 22 _laser.set_posx(10);
jamesheavey 0:92b180c8d407 23
jamesheavey 0:92b180c8d407 24 // Update the position
jamesheavey 0:92b180c8d407 25 _laser.update();
jamesheavey 0:92b180c8d407 26
jamesheavey 0:92b180c8d407 27 int read_pos2x = _laser.get_x();
jamesheavey 0:92b180c8d407 28 int read_pos2y = _laser.get_y();
jamesheavey 0:92b180c8d407 29
jamesheavey 0:92b180c8d407 30 // Read the position
jamesheavey 0:92b180c8d407 31 printf("%f, %f\n", read_pos2x, read_pos2y);
jamesheavey 0:92b180c8d407 32
jamesheavey 0:92b180c8d407 33 // Now check that both the positions are as expected
jamesheavey 0:92b180c8d407 34 bool success_flag = true;
jamesheavey 0:92b180c8d407 35
jamesheavey 0:92b180c8d407 36 // Fail the test if the initial position is wrong
jamesheavey 0:92b180c8d407 37 if (read_pos1x != 0 || read_pos1y != 0) {
jamesheavey 0:92b180c8d407 38 success_flag = false;
jamesheavey 0:92b180c8d407 39 }
jamesheavey 0:92b180c8d407 40 if (read_pos2x != 10 || read_pos2y != 0) {
jamesheavey 0:92b180c8d407 41 success_flag = false;
jamesheavey 0:92b180c8d407 42 }
jamesheavey 0:92b180c8d407 43
jamesheavey 0:92b180c8d407 44
jamesheavey 0:92b180c8d407 45
jamesheavey 0:92b180c8d407 46 return success_flag;
jamesheavey 0:92b180c8d407 47 }
jamesheavey 0:92b180c8d407 48 #endif