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@14:7419c680656f, 2020-04-26 (annotated)
- Committer:
- evanso
- Date:
- Sun Apr 26 20:31:53 2020 +0000
- Revision:
- 14:7419c680656f
- Parent:
- 13:12276eed13ac
- Child:
- 16:1ee3d3804557
Added map movement test unit and doxygen details to 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 | /** 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 | 13:12276eed13ac | 11 | bool spaceship_movement_test(Direction d_, int expected_x,int expected_y){ |
evanso | 14:7419c680656f | 12 | // Objects reqired for test ------------------------------------------------ |
evanso | 14:7419c680656f | 13 | Gamepad pad; |
evanso | 14:7419c680656f | 14 | Spaceship spaceship; |
evanso | 13:12276eed13ac | 15 | |
evanso | 13:12276eed13ac | 16 | // Initialise spaceship in start postion of 36, 22 |
evanso | 13:12276eed13ac | 17 | pad.init(); |
evanso | 13:12276eed13ac | 18 | spaceship.init(); |
evanso | 13:12276eed13ac | 19 | |
evanso | 13:12276eed13ac | 20 | printf("spaceship_movement = %d,%d : ", expected_x, expected_y ); |
evanso | 13:12276eed13ac | 21 | |
evanso | 13:12276eed13ac | 22 | // Moves spcaeship |
evanso | 13:12276eed13ac | 23 | spaceship.movement(d_); |
evanso | 11:ab578a151f67 | 24 | |
evanso | 13:12276eed13ac | 25 | //Reads finish spaceship positon |
evanso | 13:12276eed13ac | 26 | int finish_x_postion = spaceship.get_position_x_spaceship(); |
evanso | 13:12276eed13ac | 27 | int finish_y_postion = spaceship.get_position_y_spaceship(); |
evanso | 13:12276eed13ac | 28 | |
evanso | 13:12276eed13ac | 29 | // Checks final position with espected |
evanso | 13:12276eed13ac | 30 | if (finish_x_postion == expected_x && finish_y_postion == expected_y) { |
evanso | 13:12276eed13ac | 31 | printf ( "Passed!\n"); |
evanso | 13:12276eed13ac | 32 | return true; |
evanso | 13:12276eed13ac | 33 | } else { |
evanso | 13:12276eed13ac | 34 | printf ( "Failed! value = %d,%d (expecting %d,%d)\n", finish_x_postion, finish_y_postion, expected_x, expected_y); |
evanso | 13:12276eed13ac | 35 | return false; |
evanso | 13:12276eed13ac | 36 | } |
evanso | 13:12276eed13ac | 37 | |
evanso | 13:12276eed13ac | 38 | } |
evanso | 13:12276eed13ac | 39 | |
evanso | 13:12276eed13ac | 40 | bool spaceship_draw_test(Direction d_, int expected_pixel_status, int expected_postion_x, int expected_postion_y){ |
evanso | 14:7419c680656f | 41 | // Objects reqired for test ------------------------------------------------ |
evanso | 14:7419c680656f | 42 | Gamepad pad; |
evanso | 14:7419c680656f | 43 | Spaceship spaceship; |
evanso | 14:7419c680656f | 44 | N5110 lcd; |
evanso | 14:7419c680656f | 45 | |
evanso | 13:12276eed13ac | 46 | // Initialise spaceship in start postion of 36, 22 |
evanso | 11:ab578a151f67 | 47 | pad.init(); |
evanso | 11:ab578a151f67 | 48 | lcd.init(); |
evanso | 11:ab578a151f67 | 49 | spaceship.init(); |
evanso | 11:ab578a151f67 | 50 | |
evanso | 12:1c0b6796aaca | 51 | // Reads start spaceship postion |
evanso | 13:12276eed13ac | 52 | printf("spaceship_draw x,y= %d,%d : ",expected_postion_x, expected_postion_y ); |
evanso | 11:ab578a151f67 | 53 | |
evanso | 13:12276eed13ac | 54 | // Moves spcaeship to max/min x and y postions to test off_screen_x_y_checker |
evanso | 13:12276eed13ac | 55 | for (int i = 0; i < 30; i++){ |
evanso | 13:12276eed13ac | 56 | spaceship.movement(d_); |
evanso | 12:1c0b6796aaca | 57 | } |
evanso | 12:1c0b6796aaca | 58 | |
evanso | 13:12276eed13ac | 59 | // Draws spaceship |
evanso | 12:1c0b6796aaca | 60 | spaceship.draw(lcd); |
evanso | 13:12276eed13ac | 61 | |
evanso | 13:12276eed13ac | 62 | // Reads pixel where spaceship is expected to be drawn |
evanso | 13:12276eed13ac | 63 | int actual_pixel_status = lcd.getPixel(expected_postion_x, expected_postion_y); |
evanso | 12:1c0b6796aaca | 64 | |
evanso | 13:12276eed13ac | 65 | //Reads finish spaceship positon |
evanso | 13:12276eed13ac | 66 | int finish_x_postion = spaceship.get_position_x_spaceship(); |
evanso | 13:12276eed13ac | 67 | int finish_y_postion = spaceship.get_position_y_spaceship(); |
evanso | 13:12276eed13ac | 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 |