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_test.h
00001 #ifndef SPACESHIP_TEST_H 00002 #define SPACESHIP_TEST_H 00003 00004 /** Spaceship Test 00005 * @brief Checks Spaceship move to the correct position when moved and doesn’t go 00006 * of map when being drawn 00007 * @author Benjamin Evans, University of Leeds 00008 * @date April 2020 00009 * @return true if test are passed 00010 */ 00011 bool spaceship_movement_test(Direction d_, int expected_x,int expected_y) { 00012 // Objects required for test 00013 FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL); 00014 Gamepad pad; 00015 Spaceship spaceship; 00016 00017 // Initialise spaceship in start position of 36, 22 00018 pad.init(); 00019 spaceship.init(); 00020 00021 printf("spaceship_movement = %d,%d : ", expected_x, expected_y ); 00022 00023 // Moves spaceship 00024 spaceship.movement(d_); 00025 00026 // Reads finish spaceship position 00027 Vector2D finish_postion = spaceship.get_pos(); 00028 00029 // Checks final position with expected 00030 if (finish_postion.x == expected_x && finish_postion.y == expected_y) { 00031 printf ( "Passed!\n"); 00032 return true; 00033 } else { 00034 int finish_x_postion = finish_postion.x; 00035 int finish_y_postion = finish_postion.y; 00036 printf ( "Failed! value = %d,%d (expecting %d,%d)\n", finish_x_postion, 00037 finish_y_postion, expected_x, expected_y); 00038 return false; 00039 } 00040 } 00041 00042 bool spaceship_draw_test(Direction d_, int expected_pixel_status, 00043 int expected_postion_x, int expected_postion_y) { 00044 // Objects required for test 00045 Gamepad pad; 00046 Spaceship spaceship; 00047 N5110 lcd; 00048 00049 // Initialise spaceship in start position of 36, 22 00050 pad.init(); 00051 lcd.init(); 00052 spaceship.init(); 00053 00054 // Reads start spaceship position 00055 printf("spaceship_draw x,y= %d,%d : ",expected_postion_x, 00056 expected_postion_y ); 00057 00058 // Moves spaceship to max/min x and y positions to test 00059 // off_screen_x_y_checker 00060 for (int i = 0; i < 30; i++) { 00061 spaceship.movement(d_); 00062 } 00063 00064 // Draws spaceship 00065 spaceship.draw(lcd); 00066 00067 // Reads pixel where spaceship is expected to be drawn 00068 int actual_pixel_status = lcd.getPixel(expected_postion_x, 00069 expected_postion_y); 00070 00071 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00072 if (actual_pixel_status) { 00073 printf ( "Passed!\n"); 00074 return true; 00075 } else { 00076 printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status, 00077 expected_pixel_status); 00078 return false; 00079 } 00080 } 00081 #endif
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2