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.
Spaceship/Spaceship_test.h@11:ab578a151f67, 2020-04-23 (annotated)
- Committer:
- evanso
- Date:
- Thu Apr 23 18:17:28 2020 +0000
- Revision:
- 11:ab578a151f67
- Child:
- 12:1c0b6796aaca
Added test files and ran a spaceship unit test, which it passed! Also cleaned up code and comments.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evanso | 11:ab578a151f67 | 1 | #ifndef SPACESHIP_TEST_H |
evanso | 11:ab578a151f67 | 2 | #define SPACESHIP_TEST_H |
evanso | 11:ab578a151f67 | 3 | |
evanso | 11:ab578a151f67 | 4 | |
evanso | 11:ab578a151f67 | 5 | |
evanso | 11:ab578a151f67 | 6 | /** Spaceship Test |
evanso | 11:ab578a151f67 | 7 | @brief Checks Spcaceship goes to the correct postion when moved |
evanso | 11:ab578a151f67 | 8 | @author Benjamin Evans, University of Leeds |
evanso | 11:ab578a151f67 | 9 | @date April 2020 |
evanso | 11:ab578a151f67 | 10 | @return true if test are passed |
evanso | 11:ab578a151f67 | 11 | */ |
evanso | 11:ab578a151f67 | 12 | |
evanso | 11:ab578a151f67 | 13 | bool spaceship_movement_test(){ |
evanso | 11:ab578a151f67 | 14 | Gamepad pad; |
evanso | 11:ab578a151f67 | 15 | N5110 lcd; |
evanso | 11:ab578a151f67 | 16 | Spaceship spaceship; |
evanso | 11:ab578a151f67 | 17 | Serial usb(USBTX, USBRX); |
evanso | 11:ab578a151f67 | 18 | |
evanso | 11:ab578a151f67 | 19 | // Initialise spaceship in start postion of 36, 22 and draw |
evanso | 11:ab578a151f67 | 20 | |
evanso | 11:ab578a151f67 | 21 | pad.init(); |
evanso | 11:ab578a151f67 | 22 | lcd.init(); |
evanso | 11:ab578a151f67 | 23 | spaceship.init(); |
evanso | 11:ab578a151f67 | 24 | spaceship.draw(lcd); |
evanso | 11:ab578a151f67 | 25 | |
evanso | 11:ab578a151f67 | 26 | // Checks start spaceship postion |
evanso | 11:ab578a151f67 | 27 | int start_x_postion = spaceship.get_position_x_spaceship(); |
evanso | 11:ab578a151f67 | 28 | int start_y_postion = spaceship.get_position_y_spaceship(); |
evanso | 11:ab578a151f67 | 29 | usb.printf("start postion x = %d, start postion y = %d\n",start_x_postion, start_y_postion ); |
evanso | 11:ab578a151f67 | 30 | |
evanso | 11:ab578a151f67 | 31 | // Moves spaceship: Joystick in NE postion so should move x++, y-- |
evanso | 11:ab578a151f67 | 32 | usb.printf("Move joystick to NE position\n"); |
evanso | 11:ab578a151f67 | 33 | wait(3); // give me time to move joystick |
evanso | 11:ab578a151f67 | 34 | spaceship.movement(pad); |
evanso | 11:ab578a151f67 | 35 | |
evanso | 11:ab578a151f67 | 36 | // Redraws spaceship |
evanso | 11:ab578a151f67 | 37 | spaceship.draw(lcd); |
evanso | 11:ab578a151f67 | 38 | |
evanso | 11:ab578a151f67 | 39 | // Checks end spaceship postion |
evanso | 11:ab578a151f67 | 40 | int end_x_postion = spaceship.get_position_x_spaceship(); |
evanso | 11:ab578a151f67 | 41 | int end_y_postion = spaceship.get_position_y_spaceship(); |
evanso | 11:ab578a151f67 | 42 | usb.printf("end postion x = %d, end postion y = %d\n",end_x_postion, end_y_postion ); |
evanso | 11:ab578a151f67 | 43 | |
evanso | 11:ab578a151f67 | 44 | // Check if finish x,y postions are correct |
evanso | 11:ab578a151f67 | 45 | bool pass_flag = true; |
evanso | 11:ab578a151f67 | 46 | |
evanso | 11:ab578a151f67 | 47 | // Fail test if start postision is incorrect |
evanso | 11:ab578a151f67 | 48 | if (start_x_postion != 36 || start_y_postion != 22) { |
evanso | 11:ab578a151f67 | 49 | pass_flag = false; |
evanso | 11:ab578a151f67 | 50 | } |
evanso | 11:ab578a151f67 | 51 | |
evanso | 11:ab578a151f67 | 52 | // Fail test if end postision is incorrect |
evanso | 11:ab578a151f67 | 53 | if (end_x_postion != 37 || end_y_postion != 21) { |
evanso | 11:ab578a151f67 | 54 | pass_flag = false; |
evanso | 11:ab578a151f67 | 55 | } |
evanso | 11:ab578a151f67 | 56 | |
evanso | 11:ab578a151f67 | 57 | return pass_flag; |
evanso | 11:ab578a151f67 | 58 | } |
evanso | 11:ab578a151f67 | 59 | #endif |