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@13:12276eed13ac, 2020-04-26 (annotated)
- Committer:
- evanso
- Date:
- Sun Apr 26 17:08:10 2020 +0000
- Revision:
- 13:12276eed13ac
- Parent:
- 12:1c0b6796aaca
- Child:
- 14:7419c680656f
Changed spaceship unit test code so it now done properly and doesn't require my input. Changed where objects are defined to reduce the number of arguments that need passing when a function is called. Edited gamepad code to properly add ADC pin.
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 | 13:12276eed13ac | 4 | // Objects reqired for test ---------------------------------------------------- |
evanso | 13:12276eed13ac | 5 | Gamepad pad; |
evanso | 13:12276eed13ac | 6 | N5110 lcd; |
evanso | 13:12276eed13ac | 7 | Spaceship spaceship; |
evanso | 13:12276eed13ac | 8 | Direction d_; |
evanso | 13:12276eed13ac | 9 | |
evanso | 11:ab578a151f67 | 10 | /** Spaceship Test |
evanso | 12:1c0b6796aaca | 11 | @brief Checks Spcaceship goes to the correct postion when moved and doesnt go of map |
evanso | 11:ab578a151f67 | 12 | @author Benjamin Evans, University of Leeds |
evanso | 11:ab578a151f67 | 13 | @date April 2020 |
evanso | 11:ab578a151f67 | 14 | @return true if test are passed |
evanso | 11:ab578a151f67 | 15 | */ |
evanso | 11:ab578a151f67 | 16 | |
evanso | 13:12276eed13ac | 17 | bool spaceship_movement_test(Direction d_, int expected_x,int expected_y){ |
evanso | 13:12276eed13ac | 18 | |
evanso | 13:12276eed13ac | 19 | // Initialise spaceship in start postion of 36, 22 |
evanso | 13:12276eed13ac | 20 | pad.init(); |
evanso | 13:12276eed13ac | 21 | lcd.init(); |
evanso | 13:12276eed13ac | 22 | spaceship.init(); |
evanso | 13:12276eed13ac | 23 | |
evanso | 13:12276eed13ac | 24 | printf("spaceship_movement = %d,%d : ", expected_x, expected_y ); |
evanso | 13:12276eed13ac | 25 | |
evanso | 13:12276eed13ac | 26 | // Moves spcaeship |
evanso | 13:12276eed13ac | 27 | spaceship.movement(d_); |
evanso | 11:ab578a151f67 | 28 | |
evanso | 13:12276eed13ac | 29 | //Reads finish spaceship positon |
evanso | 13:12276eed13ac | 30 | int finish_x_postion = spaceship.get_position_x_spaceship(); |
evanso | 13:12276eed13ac | 31 | int finish_y_postion = spaceship.get_position_y_spaceship(); |
evanso | 13:12276eed13ac | 32 | |
evanso | 13:12276eed13ac | 33 | // Checks final position with espected |
evanso | 13:12276eed13ac | 34 | if (finish_x_postion == expected_x && finish_y_postion == expected_y) { |
evanso | 13:12276eed13ac | 35 | printf ( "Passed!\n"); |
evanso | 13:12276eed13ac | 36 | return true; |
evanso | 13:12276eed13ac | 37 | } else { |
evanso | 13:12276eed13ac | 38 | printf ( "Failed! value = %d,%d (expecting %d,%d)\n", finish_x_postion, finish_y_postion, expected_x, expected_y); |
evanso | 13:12276eed13ac | 39 | return false; |
evanso | 13:12276eed13ac | 40 | } |
evanso | 13:12276eed13ac | 41 | |
evanso | 13:12276eed13ac | 42 | } |
evanso | 13:12276eed13ac | 43 | |
evanso | 13:12276eed13ac | 44 | bool spaceship_draw_test(Direction d_, int expected_pixel_status, int expected_postion_x, int expected_postion_y){ |
evanso | 13:12276eed13ac | 45 | // Initialise spaceship in start postion of 36, 22 |
evanso | 11:ab578a151f67 | 46 | pad.init(); |
evanso | 11:ab578a151f67 | 47 | lcd.init(); |
evanso | 11:ab578a151f67 | 48 | spaceship.init(); |
evanso | 11:ab578a151f67 | 49 | |
evanso | 12:1c0b6796aaca | 50 | // Reads start spaceship postion |
evanso | 13:12276eed13ac | 51 | printf("spaceship_draw x,y= %d,%d : ",expected_postion_x, expected_postion_y ); |
evanso | 11:ab578a151f67 | 52 | |
evanso | 13:12276eed13ac | 53 | // Moves spcaeship to max/min x and y postions to test off_screen_x_y_checker |
evanso | 13:12276eed13ac | 54 | for (int i = 0; i < 30; i++){ |
evanso | 13:12276eed13ac | 55 | spaceship.movement(d_); |
evanso | 12:1c0b6796aaca | 56 | } |
evanso | 12:1c0b6796aaca | 57 | |
evanso | 13:12276eed13ac | 58 | // Draws spaceship |
evanso | 12:1c0b6796aaca | 59 | spaceship.draw(lcd); |
evanso | 13:12276eed13ac | 60 | |
evanso | 13:12276eed13ac | 61 | // Reads pixel where spaceship is expected to be drawn |
evanso | 13:12276eed13ac | 62 | int actual_pixel_status = lcd.getPixel(expected_postion_x, expected_postion_y); |
evanso | 12:1c0b6796aaca | 63 | |
evanso | 13:12276eed13ac | 64 | //Reads finish spaceship positon |
evanso | 13:12276eed13ac | 65 | int finish_x_postion = spaceship.get_position_x_spaceship(); |
evanso | 13:12276eed13ac | 66 | int finish_y_postion = spaceship.get_position_y_spaceship(); |
evanso | 13:12276eed13ac | 67 | |
evanso | 12:1c0b6796aaca | 68 | |
evanso | 13:12276eed13ac | 69 | // Checks if pixel is drawn and therefor testing it hasnt gone of screen |
evanso | 13:12276eed13ac | 70 | if (actual_pixel_status) { |
evanso | 13:12276eed13ac | 71 | printf ( "Passed!\n"); |
evanso | 13:12276eed13ac | 72 | return true; |
evanso | 13:12276eed13ac | 73 | } else { |
evanso | 13:12276eed13ac | 74 | printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status, expected_pixel_status); |
evanso | 13:12276eed13ac | 75 | printf("\nactual psotion x,y= %d,%d : \n ",finish_x_postion, finish_y_postion ); |
evanso | 13:12276eed13ac | 76 | return false; |
evanso | 12:1c0b6796aaca | 77 | } |
evanso | 11:ab578a151f67 | 78 | } |
evanso | 11:ab578a151f67 | 79 | #endif |