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.
People/People_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 | 37:a05eac7fcb4c | 1 | #ifndef PEOPLE_TEST_H |
| evanso | 37:a05eac7fcb4c | 2 | #define PEOPLE_TEST_H |
| evanso | 37:a05eac7fcb4c | 3 | |
| evanso | 37:a05eac7fcb4c | 4 | /** People Test |
| evanso | 37:a05eac7fcb4c | 5 | * @brief Checks People draw corectly and moves joystick direction |
| evanso | 37:a05eac7fcb4c | 6 | * @author Benjamin Evans, University of Leeds |
| evanso | 37:a05eac7fcb4c | 7 | * @date April 2020 |
| evanso | 37:a05eac7fcb4c | 8 | * @return true if test are passed |
| evanso | 37:a05eac7fcb4c | 9 | */ |
| evanso | 37:a05eac7fcb4c | 10 | bool people_draw_test(Direction d_, int expected_pixel_status, int expected_x){ |
| evanso | 85:87bc28b151d8 | 11 | // Objects required for test |
| evanso | 37:a05eac7fcb4c | 12 | Gamepad pad; |
| evanso | 37:a05eac7fcb4c | 13 | Map map; |
| evanso | 37:a05eac7fcb4c | 14 | People people; |
| evanso | 37:a05eac7fcb4c | 15 | N5110 lcd; |
| evanso | 37:a05eac7fcb4c | 16 | |
| evanso | 37:a05eac7fcb4c | 17 | // Initialises |
| evanso | 37:a05eac7fcb4c | 18 | pad.init(); |
| evanso | 37:a05eac7fcb4c | 19 | lcd.init(); |
| evanso | 37:a05eac7fcb4c | 20 | map.init(pad); |
| evanso | 37:a05eac7fcb4c | 21 | people.init(pad,expected_x), |
| evanso | 37:a05eac7fcb4c | 22 | |
| evanso | 37:a05eac7fcb4c | 23 | printf(" expected pixel status = %d ",expected_pixel_status); |
| evanso | 37:a05eac7fcb4c | 24 | |
| evanso | 37:a05eac7fcb4c | 25 | // Draws people |
| evanso | 37:a05eac7fcb4c | 26 | people.draw_people(lcd, d_, map.get_length_map(), map.get_position_x_map()); |
| evanso | 37:a05eac7fcb4c | 27 | |
| evanso | 82:3211b31e9421 | 28 | // Gets the position of person as it's random |
| evanso | 37:a05eac7fcb4c | 29 | Vector2D people_pos = people.get_pos(); |
| evanso | 37:a05eac7fcb4c | 30 | |
| evanso | 37:a05eac7fcb4c | 31 | // Reads pixel where person is expected to be drawn |
| evanso | 37:a05eac7fcb4c | 32 | int actual_pixel_status = lcd.getPixel(people_pos.x + 1, |
| evanso | 37:a05eac7fcb4c | 33 | people_pos.y + 1); |
| evanso | 37:a05eac7fcb4c | 34 | |
| evanso | 85:87bc28b151d8 | 35 | // Checks if pixel is drawn and therefor testing it hasn’t gone of screen |
| evanso | 37:a05eac7fcb4c | 36 | if (actual_pixel_status == expected_pixel_status) { |
| evanso | 37:a05eac7fcb4c | 37 | printf ( "Passed!\n"); |
| evanso | 37:a05eac7fcb4c | 38 | return true; |
| evanso | 37:a05eac7fcb4c | 39 | } else { |
| evanso | 37:a05eac7fcb4c | 40 | printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status, |
| evanso | 37:a05eac7fcb4c | 41 | expected_pixel_status); |
| evanso | 37:a05eac7fcb4c | 42 | return false; |
| evanso | 37:a05eac7fcb4c | 43 | } |
| evanso | 37:a05eac7fcb4c | 44 | } |
| evanso | 38:75bd968daa31 | 45 | |
| evanso | 38:75bd968daa31 | 46 | bool check_alien_collision_test(bool expected_collision, int expected_x){ |
| evanso | 38:75bd968daa31 | 47 | |
| evanso | 85:87bc28b151d8 | 48 | // Objects required for test |
| evanso | 38:75bd968daa31 | 49 | Alien alien; |
| evanso | 38:75bd968daa31 | 50 | People people; |
| evanso | 38:75bd968daa31 | 51 | Gamepad pad; |
| evanso | 38:75bd968daa31 | 52 | |
| evanso | 38:75bd968daa31 | 53 | // Initialise people x start position |
| evanso | 38:75bd968daa31 | 54 | people.init(pad,expected_x); |
| evanso | 38:75bd968daa31 | 55 | |
| evanso | 38:75bd968daa31 | 56 | printf("collision = %s : " ,expected_collision ? "true" : "false"); |
| evanso | 38:75bd968daa31 | 57 | |
| evanso | 85:87bc28b151d8 | 58 | // Initialise alien to people position |
| evanso | 38:75bd968daa31 | 59 | alien.init(pad,expected_x,43); |
| evanso | 38:75bd968daa31 | 60 | |
| evanso | 38:75bd968daa31 | 61 | // Checks collision function |
| evanso | 38:75bd968daa31 | 62 | bool actual_collision = people.check_alien_collision(alien); |
| evanso | 38:75bd968daa31 | 63 | |
| evanso | 85:87bc28b151d8 | 64 | // Checks if collision is expected |
| evanso | 38:75bd968daa31 | 65 | if (actual_collision == expected_collision) { |
| evanso | 38:75bd968daa31 | 66 | printf ( "Passed!\n"); |
| evanso | 38:75bd968daa31 | 67 | return true; |
| evanso | 38:75bd968daa31 | 68 | } else { |
| evanso | 38:75bd968daa31 | 69 | printf ("Failed! value = %s (expecting %d)\n", |
| evanso | 38:75bd968daa31 | 70 | actual_collision ? "true" : "false", |
| evanso | 38:75bd968daa31 | 71 | expected_collision ? "true" : "false"); |
| evanso | 38:75bd968daa31 | 72 | return false; |
| evanso | 38:75bd968daa31 | 73 | } |
| evanso | 38:75bd968daa31 | 74 | } |
| evanso | 85:87bc28b151d8 | 75 | #endif |