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@22:053c11a202e1, 2020-05-06 (annotated)
- Committer:
- evanso
- Date:
- Wed May 06 11:24:22 2020 +0000
- Revision:
- 22:053c11a202e1
- Parent:
- 21:f7d7834e3af1
- Child:
- 27:8bb2bd97c319
Now that the main code structure is finished for alien and weapons I can unit test those classes. Added a unit test for the alien class and 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 | 22:053c11a202e1 | 5 | @brief Checks Spcaceship move to the correct postion when moved and doesnt go of map when being drawn |
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 | 21:f7d7834e3af1 | 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 | 18:11068b98e261 | 26 | Vector2D finish_postion = spaceship.get_pos(); |
evanso | 13:12276eed13ac | 27 | |
evanso | 13:12276eed13ac | 28 | // Checks final position with espected |
evanso | 18:11068b98e261 | 29 | if (finish_postion.x == expected_x && finish_postion.y == expected_y) { |
evanso | 13:12276eed13ac | 30 | printf ( "Passed!\n"); |
evanso | 13:12276eed13ac | 31 | return true; |
evanso | 13:12276eed13ac | 32 | } else { |
evanso | 18:11068b98e261 | 33 | int finish_x_postion = finish_postion.x; |
evanso | 18:11068b98e261 | 34 | int finish_y_postion = finish_postion.y; |
evanso | 18:11068b98e261 | 35 | printf ( "Failed! value = %d,%d (expecting %d,%d)\n", finish_x_postion, finish_y_postion, expected_x, expected_y); |
evanso | 13:12276eed13ac | 36 | return false; |
evanso | 13:12276eed13ac | 37 | } |
evanso | 13:12276eed13ac | 38 | |
evanso | 13:12276eed13ac | 39 | } |
evanso | 13:12276eed13ac | 40 | |
evanso | 13:12276eed13ac | 41 | bool spaceship_draw_test(Direction d_, int expected_pixel_status, int expected_postion_x, int expected_postion_y){ |
evanso | 21:f7d7834e3af1 | 42 | // Objects reqired for test |
evanso | 14:7419c680656f | 43 | Gamepad pad; |
evanso | 14:7419c680656f | 44 | Spaceship spaceship; |
evanso | 14:7419c680656f | 45 | N5110 lcd; |
evanso | 14:7419c680656f | 46 | |
evanso | 13:12276eed13ac | 47 | // Initialise spaceship in start postion of 36, 22 |
evanso | 11:ab578a151f67 | 48 | pad.init(); |
evanso | 11:ab578a151f67 | 49 | lcd.init(); |
evanso | 11:ab578a151f67 | 50 | spaceship.init(); |
evanso | 11:ab578a151f67 | 51 | |
evanso | 12:1c0b6796aaca | 52 | // Reads start spaceship postion |
evanso | 13:12276eed13ac | 53 | printf("spaceship_draw x,y= %d,%d : ",expected_postion_x, expected_postion_y ); |
evanso | 11:ab578a151f67 | 54 | |
evanso | 13:12276eed13ac | 55 | // Moves spcaeship to max/min x and y postions to test off_screen_x_y_checker |
evanso | 13:12276eed13ac | 56 | for (int i = 0; i < 30; i++){ |
evanso | 13:12276eed13ac | 57 | spaceship.movement(d_); |
evanso | 12:1c0b6796aaca | 58 | } |
evanso | 12:1c0b6796aaca | 59 | |
evanso | 13:12276eed13ac | 60 | // Draws spaceship |
evanso | 12:1c0b6796aaca | 61 | spaceship.draw(lcd); |
evanso | 13:12276eed13ac | 62 | |
evanso | 13:12276eed13ac | 63 | // Reads pixel where spaceship is expected to be drawn |
evanso | 13:12276eed13ac | 64 | int actual_pixel_status = lcd.getPixel(expected_postion_x, expected_postion_y); |
evanso | 12:1c0b6796aaca | 65 | |
evanso | 13:12276eed13ac | 66 | // Checks if pixel is drawn and therefor testing it hasnt gone of screen |
evanso | 13:12276eed13ac | 67 | if (actual_pixel_status) { |
evanso | 13:12276eed13ac | 68 | printf ( "Passed!\n"); |
evanso | 13:12276eed13ac | 69 | return true; |
evanso | 13:12276eed13ac | 70 | } else { |
evanso | 13:12276eed13ac | 71 | printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status, expected_pixel_status); |
evanso | 13:12276eed13ac | 72 | return false; |
evanso | 12:1c0b6796aaca | 73 | } |
evanso | 11:ab578a151f67 | 74 | } |
evanso | 11:ab578a151f67 | 75 | #endif |