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@12:1c0b6796aaca, 2020-04-24 (annotated)
- Committer:
- evanso
- Date:
- Fri Apr 24 19:09:22 2020 +0000
- Revision:
- 12:1c0b6796aaca
- Parent:
- 11:ab578a151f67
- Child:
- 13:12276eed13ac
Added unit test for map, which it passed.
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 | /** Spaceship Test |
evanso | 12:1c0b6796aaca | 5 | @brief Checks Spcaceship goes to the correct postion when moved and doesnt go of map |
evanso | 11:ab578a151f67 | 6 | @author Benjamin Evans, University of Leeds |
evanso | 11:ab578a151f67 | 7 | @date April 2020 |
evanso | 11:ab578a151f67 | 8 | @return true if test are passed |
evanso | 11:ab578a151f67 | 9 | */ |
evanso | 11:ab578a151f67 | 10 | |
evanso | 11:ab578a151f67 | 11 | bool spaceship_movement_test(){ |
evanso | 12:1c0b6796aaca | 12 | // Objects reqired for test |
evanso | 11:ab578a151f67 | 13 | Gamepad pad; |
evanso | 11:ab578a151f67 | 14 | N5110 lcd; |
evanso | 11:ab578a151f67 | 15 | Spaceship spaceship; |
evanso | 12:1c0b6796aaca | 16 | Serial usb(USBTX, USBRX); |
evanso | 12:1c0b6796aaca | 17 | |
evanso | 12:1c0b6796aaca | 18 | // Flag to return if test passed |
evanso | 12:1c0b6796aaca | 19 | bool pass_flag = true; |
evanso | 11:ab578a151f67 | 20 | |
evanso | 11:ab578a151f67 | 21 | // Initialise spaceship in start postion of 36, 22 and draw |
evanso | 11:ab578a151f67 | 22 | pad.init(); |
evanso | 11:ab578a151f67 | 23 | lcd.init(); |
evanso | 11:ab578a151f67 | 24 | spaceship.init(); |
evanso | 11:ab578a151f67 | 25 | spaceship.draw(lcd); |
evanso | 11:ab578a151f67 | 26 | |
evanso | 12:1c0b6796aaca | 27 | // Reads start spaceship postion |
evanso | 11:ab578a151f67 | 28 | int start_x_postion = spaceship.get_position_x_spaceship(); |
evanso | 11:ab578a151f67 | 29 | int start_y_postion = spaceship.get_position_y_spaceship(); |
evanso | 11:ab578a151f67 | 30 | usb.printf("start postion x = %d, start postion y = %d\n",start_x_postion, start_y_postion ); |
evanso | 11:ab578a151f67 | 31 | |
evanso | 12:1c0b6796aaca | 32 | // Test Moves spaceship: Joystick in NE postion so should move x++, y-- |
evanso | 11:ab578a151f67 | 33 | usb.printf("Move joystick to NE position\n"); |
evanso | 11:ab578a151f67 | 34 | wait(3); // give me time to move joystick |
evanso | 11:ab578a151f67 | 35 | spaceship.movement(pad); |
evanso | 11:ab578a151f67 | 36 | |
evanso | 12:1c0b6796aaca | 37 | // Reads end spaceship postion one |
evanso | 12:1c0b6796aaca | 38 | int end_x_postion_one = spaceship.get_position_x_spaceship(); |
evanso | 12:1c0b6796aaca | 39 | int end_y_postion_one = spaceship.get_position_y_spaceship(); |
evanso | 12:1c0b6796aaca | 40 | usb.printf("end postion one x = %d, end postion one y = %d\n",end_x_postion_one, end_y_postion_one); |
evanso | 11:ab578a151f67 | 41 | |
evanso | 11:ab578a151f67 | 42 | // Fail test if start postision is incorrect |
evanso | 11:ab578a151f67 | 43 | if (start_x_postion != 36 || start_y_postion != 22) { |
evanso | 11:ab578a151f67 | 44 | pass_flag = false; |
evanso | 11:ab578a151f67 | 45 | } |
evanso | 11:ab578a151f67 | 46 | |
evanso | 11:ab578a151f67 | 47 | // Fail test if end postision is incorrect |
evanso | 12:1c0b6796aaca | 48 | if (end_x_postion_one != 37 || end_y_postion_one != 21) { |
evanso | 12:1c0b6796aaca | 49 | pass_flag = false; |
evanso | 12:1c0b6796aaca | 50 | } |
evanso | 12:1c0b6796aaca | 51 | |
evanso | 12:1c0b6796aaca | 52 | // Test spaceship off screen checker and spaceship is drawn: Hold Joystick in NE postion so should move x++, y-- |
evanso | 12:1c0b6796aaca | 53 | usb.printf("Move joystick to NE position\n"); |
evanso | 12:1c0b6796aaca | 54 | wait(3); // give me time to move joystick |
evanso | 12:1c0b6796aaca | 55 | |
evanso | 12:1c0b6796aaca | 56 | // Move spaceship to max postions |
evanso | 12:1c0b6796aaca | 57 | for (int i = 0; i < 21;i++){ |
evanso | 12:1c0b6796aaca | 58 | spaceship.movement(pad); |
evanso | 12:1c0b6796aaca | 59 | } |
evanso | 12:1c0b6796aaca | 60 | |
evanso | 12:1c0b6796aaca | 61 | // Redraws spaceship, spaceship.draw calls off screen checker |
evanso | 12:1c0b6796aaca | 62 | spaceship.draw(lcd); |
evanso | 12:1c0b6796aaca | 63 | |
evanso | 12:1c0b6796aaca | 64 | // Reads end spaceship postion two |
evanso | 12:1c0b6796aaca | 65 | int end_x_postion_two = spaceship.get_position_x_spaceship(); |
evanso | 12:1c0b6796aaca | 66 | int end_y_postion_two = spaceship.get_position_y_spaceship(); |
evanso | 12:1c0b6796aaca | 67 | usb.printf("end postion two x = %d, end postion two y = %d\n",end_x_postion_two, end_y_postion_two); |
evanso | 12:1c0b6796aaca | 68 | |
evanso | 12:1c0b6796aaca | 69 | //Checks if spaceships draws |
evanso | 12:1c0b6796aaca | 70 | int did_spaceship_draw = lcd.getPixel(end_x_postion_two,end_y_postion_two); |
evanso | 12:1c0b6796aaca | 71 | |
evanso | 12:1c0b6796aaca | 72 | // Fail test if pixel isnt drawn |
evanso | 12:1c0b6796aaca | 73 | if (!did_spaceship_draw) { |
evanso | 12:1c0b6796aaca | 74 | pass_flag = false; |
evanso | 12:1c0b6796aaca | 75 | } |
evanso | 12:1c0b6796aaca | 76 | |
evanso | 12:1c0b6796aaca | 77 | // Fail test if end postision is incorrect |
evanso | 12:1c0b6796aaca | 78 | if (end_x_postion_two != 52 || end_y_postion_two != 1) { |
evanso | 11:ab578a151f67 | 79 | pass_flag = false; |
evanso | 11:ab578a151f67 | 80 | } |
evanso | 11:ab578a151f67 | 81 | |
evanso | 11:ab578a151f67 | 82 | return pass_flag; |
evanso | 11:ab578a151f67 | 83 | } |
evanso | 11:ab578a151f67 | 84 | #endif |