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
- Committer:
- evanso
- Date:
- 2020-05-26
- Revision:
- 85:87bc28b151d8
- Parent:
- 82:3211b31e9421
File content as of revision 85:87bc28b151d8:
#ifndef PEOPLE_TEST_H
#define PEOPLE_TEST_H
/** People Test
* @brief Checks People draw corectly and moves joystick direction
* @author Benjamin Evans, University of Leeds
* @date April 2020
* @return true if test are passed
*/
bool people_draw_test(Direction d_, int expected_pixel_status, int expected_x){
// Objects required for test
Gamepad pad;
Map map;
People people;
N5110 lcd;
// Initialises
pad.init();
lcd.init();
map.init(pad);
people.init(pad,expected_x),
printf(" expected pixel status = %d ",expected_pixel_status);
// Draws people
people.draw_people(lcd, d_, map.get_length_map(), map.get_position_x_map());
// Gets the position of person as it's random
Vector2D people_pos = people.get_pos();
// Reads pixel where person is expected to be drawn
int actual_pixel_status = lcd.getPixel(people_pos.x + 1,
people_pos.y + 1);
// Checks if pixel is drawn and therefor testing it hasn’t gone of screen
if (actual_pixel_status == expected_pixel_status) {
printf ( "Passed!\n");
return true;
} else {
printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status,
expected_pixel_status);
return false;
}
}
bool check_alien_collision_test(bool expected_collision, int expected_x){
// Objects required for test
Alien alien;
People people;
Gamepad pad;
// Initialise people x start position
people.init(pad,expected_x);
printf("collision = %s : " ,expected_collision ? "true" : "false");
// Initialise alien to people position
alien.init(pad,expected_x,43);
// Checks collision function
bool actual_collision = people.check_alien_collision(alien);
// Checks if collision is expected
if (actual_collision == expected_collision) {
printf ( "Passed!\n");
return true;
} else {
printf ("Failed! value = %s (expecting %d)\n",
actual_collision ? "true" : "false",
expected_collision ? "true" : "false");
return false;
}
}
#endif