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@85:87bc28b151d8, 2020-05-26 (annotated)
- Committer:
- evanso
- Date:
- Tue May 26 19:38:48 2020 +0000
- Revision:
- 85:87bc28b151d8
- Parent:
- 82:3211b31e9421
Spell checked all of code and 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 | 85:87bc28b151d8 | 5 | * @brief Checks Spaceship move to the correct position when moved and doesn’t go |
evanso | 27:8bb2bd97c319 | 6 | * of map when being drawn |
evanso | 27:8bb2bd97c319 | 7 | * @author Benjamin Evans, University of Leeds |
evanso | 27:8bb2bd97c319 | 8 | * @date April 2020 |
evanso | 27:8bb2bd97c319 | 9 | * @return true if test are passed |
evanso | 27:8bb2bd97c319 | 10 | */ |
evanso | 82:3211b31e9421 | 11 | bool spaceship_movement_test(Direction d_, int expected_x,int expected_y) { |
evanso | 85:87bc28b151d8 | 12 | // Objects required for test |
evanso | 65:daa792a09e1f | 13 | FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL); |
evanso | 14:7419c680656f | 14 | Gamepad pad; |
evanso | 14:7419c680656f | 15 | Spaceship spaceship; |
evanso | 13:12276eed13ac | 16 | |
evanso | 85:87bc28b151d8 | 17 | // Initialise spaceship in start position of 36, 22 |
evanso | 13:12276eed13ac | 18 | pad.init(); |
evanso | 13:12276eed13ac | 19 | spaceship.init(); |
evanso | 13:12276eed13ac | 20 | |
evanso | 13:12276eed13ac | 21 | printf("spaceship_movement = %d,%d : ", expected_x, expected_y ); |
evanso | 13:12276eed13ac | 22 | |
evanso | 85:87bc28b151d8 | 23 | // Moves spaceship |
evanso | 13:12276eed13ac | 24 | spaceship.movement(d_); |
evanso | 11:ab578a151f67 | 25 | |
evanso | 85:87bc28b151d8 | 26 | // Reads finish spaceship position |
evanso | 18:11068b98e261 | 27 | Vector2D finish_postion = spaceship.get_pos(); |
evanso | 13:12276eed13ac | 28 | |
evanso | 85:87bc28b151d8 | 29 | // Checks final position with expected |
evanso | 18:11068b98e261 | 30 | if (finish_postion.x == expected_x && finish_postion.y == expected_y) { |
evanso | 13:12276eed13ac | 31 | printf ( "Passed!\n"); |
evanso | 13:12276eed13ac | 32 | return true; |
evanso | 13:12276eed13ac | 33 | } else { |
evanso | 18:11068b98e261 | 34 | int finish_x_postion = finish_postion.x; |
evanso | 18:11068b98e261 | 35 | int finish_y_postion = finish_postion.y; |
evanso | 27:8bb2bd97c319 | 36 | printf ( "Failed! value = %d,%d (expecting %d,%d)\n", finish_x_postion, |
evanso | 27:8bb2bd97c319 | 37 | finish_y_postion, expected_x, expected_y); |
evanso | 13:12276eed13ac | 38 | return false; |
evanso | 65:daa792a09e1f | 39 | } |
evanso | 13:12276eed13ac | 40 | } |
evanso | 13:12276eed13ac | 41 | |
evanso | 27:8bb2bd97c319 | 42 | bool spaceship_draw_test(Direction d_, int expected_pixel_status, |
evanso | 82:3211b31e9421 | 43 | int expected_postion_x, int expected_postion_y) { |
evanso | 85:87bc28b151d8 | 44 | // Objects required for test |
evanso | 14:7419c680656f | 45 | Gamepad pad; |
evanso | 14:7419c680656f | 46 | Spaceship spaceship; |
evanso | 14:7419c680656f | 47 | N5110 lcd; |
evanso | 14:7419c680656f | 48 | |
evanso | 85:87bc28b151d8 | 49 | // Initialise spaceship in start position of 36, 22 |
evanso | 11:ab578a151f67 | 50 | pad.init(); |
evanso | 11:ab578a151f67 | 51 | lcd.init(); |
evanso | 11:ab578a151f67 | 52 | spaceship.init(); |
evanso | 11:ab578a151f67 | 53 | |
evanso | 85:87bc28b151d8 | 54 | // Reads start spaceship position |
evanso | 27:8bb2bd97c319 | 55 | printf("spaceship_draw x,y= %d,%d : ",expected_postion_x, |
evanso | 27:8bb2bd97c319 | 56 | expected_postion_y ); |
evanso | 11:ab578a151f67 | 57 | |
evanso | 85:87bc28b151d8 | 58 | // Moves spaceship to max/min x and y positions to test |
evanso | 27:8bb2bd97c319 | 59 | // off_screen_x_y_checker |
evanso | 82:3211b31e9421 | 60 | for (int i = 0; i < 30; i++) { |
evanso | 13:12276eed13ac | 61 | spaceship.movement(d_); |
evanso | 12:1c0b6796aaca | 62 | } |
evanso | 12:1c0b6796aaca | 63 | |
evanso | 13:12276eed13ac | 64 | // Draws spaceship |
evanso | 12:1c0b6796aaca | 65 | spaceship.draw(lcd); |
evanso | 13:12276eed13ac | 66 | |
evanso | 13:12276eed13ac | 67 | // Reads pixel where spaceship is expected to be drawn |
evanso | 27:8bb2bd97c319 | 68 | int actual_pixel_status = lcd.getPixel(expected_postion_x, |
evanso | 27:8bb2bd97c319 | 69 | expected_postion_y); |
evanso | 12:1c0b6796aaca | 70 | |
evanso | 85:87bc28b151d8 | 71 | // Checks if pixel is drawn and therefor testing it hasn’t gone of screen |
evanso | 13:12276eed13ac | 72 | if (actual_pixel_status) { |
evanso | 13:12276eed13ac | 73 | printf ( "Passed!\n"); |
evanso | 13:12276eed13ac | 74 | return true; |
evanso | 13:12276eed13ac | 75 | } else { |
evanso | 27:8bb2bd97c319 | 76 | printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status, |
evanso | 27:8bb2bd97c319 | 77 | expected_pixel_status); |
evanso | 13:12276eed13ac | 78 | return false; |
evanso | 12:1c0b6796aaca | 79 | } |
evanso | 11:ab578a151f67 | 80 | } |
evanso | 85:87bc28b151d8 | 81 | #endif |