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.
Weapons/Weapons_test.h@23:cc44e26c08fa, 2020-05-06 (annotated)
- Committer:
- evanso
- Date:
- Wed May 06 12:15:16 2020 +0000
- Revision:
- 23:cc44e26c08fa
- Child:
- 27:8bb2bd97c319
Added unit test for weapons class which it passed!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evanso | 23:cc44e26c08fa | 1 | #ifndef WEAPONS_TEST_H |
evanso | 23:cc44e26c08fa | 2 | #define WEAPONS_TEST_H |
evanso | 23:cc44e26c08fa | 3 | |
evanso | 23:cc44e26c08fa | 4 | /** Weapons Test |
evanso | 23:cc44e26c08fa | 5 | @brief Checks that the weapons draws |
evanso | 23:cc44e26c08fa | 6 | @author Benjamin Evans, University of Leeds |
evanso | 23:cc44e26c08fa | 7 | @date May 2020 |
evanso | 23:cc44e26c08fa | 8 | @return true if test are passed |
evanso | 23:cc44e26c08fa | 9 | */ |
evanso | 23:cc44e26c08fa | 10 | |
evanso | 23:cc44e26c08fa | 11 | bool weapons_draw_test(int expected_pixel_status,bool direction, int bullet_movement, int expected_postion_x, int expected_postion_y){ |
evanso | 23:cc44e26c08fa | 12 | // Objects reqired for test |
evanso | 23:cc44e26c08fa | 13 | Weapons bullet; |
evanso | 23:cc44e26c08fa | 14 | Spaceship spaceship; |
evanso | 23:cc44e26c08fa | 15 | N5110 lcd; |
evanso | 23:cc44e26c08fa | 16 | |
evanso | 23:cc44e26c08fa | 17 | // Initialise objects for tets |
evanso | 23:cc44e26c08fa | 18 | spaceship.init(); |
evanso | 23:cc44e26c08fa | 19 | lcd.init(); |
evanso | 23:cc44e26c08fa | 20 | bullet.init(spaceship.get_pos(), direction); |
evanso | 23:cc44e26c08fa | 21 | |
evanso | 23:cc44e26c08fa | 22 | printf("draw_bullet = %d,%d : ", expected_postion_x, expected_postion_y); |
evanso | 23:cc44e26c08fa | 23 | |
evanso | 23:cc44e26c08fa | 24 | //Draws bullet in different posisions |
evanso | 23:cc44e26c08fa | 25 | for(int i = 0;i <= bullet_movement; i++){ |
evanso | 23:cc44e26c08fa | 26 | bullet.draw_bullet(lcd); |
evanso | 23:cc44e26c08fa | 27 | } |
evanso | 23:cc44e26c08fa | 28 | |
evanso | 23:cc44e26c08fa | 29 | // Reads pixel where bullet is expected to be drawn |
evanso | 23:cc44e26c08fa | 30 | int actual_pixel_status = lcd.getPixel(expected_postion_x, expected_postion_y); |
evanso | 23:cc44e26c08fa | 31 | |
evanso | 23:cc44e26c08fa | 32 | // Checks if pixel is drawn and therefor testing it hasnt gone of screen |
evanso | 23:cc44e26c08fa | 33 | if (actual_pixel_status) { |
evanso | 23:cc44e26c08fa | 34 | printf ( "Passed!\n"); |
evanso | 23:cc44e26c08fa | 35 | return true; |
evanso | 23:cc44e26c08fa | 36 | } else { |
evanso | 23:cc44e26c08fa | 37 | printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status, expected_pixel_status); |
evanso | 23:cc44e26c08fa | 38 | return false; |
evanso | 23:cc44e26c08fa | 39 | } |
evanso | 23:cc44e26c08fa | 40 | } |
evanso | 23:cc44e26c08fa | 41 | |
evanso | 23:cc44e26c08fa | 42 | #endif |