Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Spaceship/Spaceship_test.h
- Revision:
- 11:ab578a151f67
- Child:
- 12:1c0b6796aaca
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Spaceship/Spaceship_test.h Thu Apr 23 18:17:28 2020 +0000 @@ -0,0 +1,59 @@ +#ifndef SPACESHIP_TEST_H +#define SPACESHIP_TEST_H + + + +/** Spaceship Test +@brief Checks Spcaceship goes to the correct postion when moved +@author Benjamin Evans, University of Leeds +@date April 2020 +@return true if test are passed +*/ + +bool spaceship_movement_test(){ + Gamepad pad; + N5110 lcd; + Spaceship spaceship; + Serial usb(USBTX, USBRX); + + // Initialise spaceship in start postion of 36, 22 and draw + + pad.init(); + lcd.init(); + spaceship.init(); + spaceship.draw(lcd); + + // Checks start spaceship postion + int start_x_postion = spaceship.get_position_x_spaceship(); + int start_y_postion = spaceship.get_position_y_spaceship(); + usb.printf("start postion x = %d, start postion y = %d\n",start_x_postion, start_y_postion ); + + // Moves spaceship: Joystick in NE postion so should move x++, y-- + usb.printf("Move joystick to NE position\n"); + wait(3); // give me time to move joystick + spaceship.movement(pad); + + // Redraws spaceship + spaceship.draw(lcd); + + // Checks end spaceship postion + int end_x_postion = spaceship.get_position_x_spaceship(); + int end_y_postion = spaceship.get_position_y_spaceship(); + usb.printf("end postion x = %d, end postion y = %d\n",end_x_postion, end_y_postion ); + + // Check if finish x,y postions are correct + bool pass_flag = true; + + // Fail test if start postision is incorrect + if (start_x_postion != 36 || start_y_postion != 22) { + pass_flag = false; + } + + // Fail test if end postision is incorrect + if (end_x_postion != 37 || end_y_postion != 21) { + pass_flag = false; + } + + return pass_flag; +} +#endif \ No newline at end of file