Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Sat May 16 16:16:43 2020 +0000
Revision:
37:a05eac7fcb4c
Parent:
33:7fedd8029473
Child:
38:75bd968daa31
Added unit test for people wich it passed!! Also changed alien unit test as added more code to the alien class.;

Who changed what in which revision?

UserRevisionLine numberNew 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 37:a05eac7fcb4c 11 // Objects reqired 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 37:a05eac7fcb4c 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 37:a05eac7fcb4c 35 // Checks if pixel is drawn and therefor testing it hasnt 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 37:a05eac7fcb4c 45 #endif