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.
Diff: Spaceship/Spaceship_test.h
- Revision:
- 13:12276eed13ac
- Parent:
- 12:1c0b6796aaca
- Child:
- 14:7419c680656f
diff -r 1c0b6796aaca -r 12276eed13ac Spaceship/Spaceship_test.h
--- a/Spaceship/Spaceship_test.h Fri Apr 24 19:09:22 2020 +0000
+++ b/Spaceship/Spaceship_test.h Sun Apr 26 17:08:10 2020 +0000
@@ -1,6 +1,12 @@
#ifndef SPACESHIP_TEST_H
#define SPACESHIP_TEST_H
+// Objects reqired for test ----------------------------------------------------
+Gamepad pad;
+N5110 lcd;
+Spaceship spaceship;
+Direction d_;
+
/** Spaceship Test
@brief Checks Spcaceship goes to the correct postion when moved and doesnt go of map
@author Benjamin Evans, University of Leeds
@@ -8,77 +14,66 @@
@return true if test are passed
*/
-bool spaceship_movement_test(){
- // Objects reqired for test
- Gamepad pad;
- N5110 lcd;
- Spaceship spaceship;
- Serial usb(USBTX, USBRX);
-
- // Flag to return if test passed
- bool pass_flag = true;
+bool spaceship_movement_test(Direction d_, int expected_x,int expected_y){
+
+ // Initialise spaceship in start postion of 36, 22
+ pad.init();
+ lcd.init();
+ spaceship.init();
+
+ printf("spaceship_movement = %d,%d : ", expected_x, expected_y );
+
+ // Moves spcaeship
+ spaceship.movement(d_);
- // Initialise spaceship in start postion of 36, 22 and draw
+ //Reads finish spaceship positon
+ int finish_x_postion = spaceship.get_position_x_spaceship();
+ int finish_y_postion = spaceship.get_position_y_spaceship();
+
+ // Checks final position with espected
+ if (finish_x_postion == expected_x && finish_y_postion == expected_y) {
+ printf ( "Passed!\n");
+ return true;
+ } else {
+ printf ( "Failed! value = %d,%d (expecting %d,%d)\n", finish_x_postion, finish_y_postion, expected_x, expected_y);
+ return false;
+ }
+
+}
+
+bool spaceship_draw_test(Direction d_, int expected_pixel_status, int expected_postion_x, int expected_postion_y){
+ // Initialise spaceship in start postion of 36, 22
pad.init();
lcd.init();
spaceship.init();
- spaceship.draw(lcd);
// Reads start spaceship postion
- int start_x_postion = spaceship.get_position_x_spaceship();
- int start_y_postion = spaceship.get_position_y_spaceship();
- usb.printf("start postion x = %d, start postion y = %d\n",start_x_postion, start_y_postion );
-
-// Test Moves spaceship: Joystick in NE postion so should move x++, y--
- usb.printf("Move joystick to NE position\n");
- wait(3); // give me time to move joystick
- spaceship.movement(pad);
+ printf("spaceship_draw x,y= %d,%d : ",expected_postion_x, expected_postion_y );
- // Reads end spaceship postion one
- int end_x_postion_one = spaceship.get_position_x_spaceship();
- int end_y_postion_one = spaceship.get_position_y_spaceship();
- usb.printf("end postion one x = %d, end postion one y = %d\n",end_x_postion_one, end_y_postion_one);
-
- // Fail test if start postision is incorrect
- if (start_x_postion != 36 || start_y_postion != 22) {
- pass_flag = false;
- }
-
- // Fail test if end postision is incorrect
- if (end_x_postion_one != 37 || end_y_postion_one != 21) {
- pass_flag = false;
+ // Moves spcaeship to max/min x and y postions to test off_screen_x_y_checker
+ for (int i = 0; i < 30; i++){
+ spaceship.movement(d_);
}
-// Test spaceship off screen checker and spaceship is drawn: Hold Joystick in NE postion so should move x++, y--
- usb.printf("Move joystick to NE position\n");
- wait(3); // give me time to move joystick
-
- // Move spaceship to max postions
- for (int i = 0; i < 21;i++){
- spaceship.movement(pad);
- }
-
- // Redraws spaceship, spaceship.draw calls off screen checker
+ // Draws spaceship
spaceship.draw(lcd);
-
- // Reads end spaceship postion two
- int end_x_postion_two = spaceship.get_position_x_spaceship();
- int end_y_postion_two = spaceship.get_position_y_spaceship();
- usb.printf("end postion two x = %d, end postion two y = %d\n",end_x_postion_two, end_y_postion_two);
+
+ // Reads pixel where spaceship is expected to be drawn
+ int actual_pixel_status = lcd.getPixel(expected_postion_x, expected_postion_y);
- //Checks if spaceships draws
- int did_spaceship_draw = lcd.getPixel(end_x_postion_two,end_y_postion_two);
+ //Reads finish spaceship positon
+ int finish_x_postion = spaceship.get_position_x_spaceship();
+ int finish_y_postion = spaceship.get_position_y_spaceship();
+
- // Fail test if pixel isnt drawn
- if (!did_spaceship_draw) {
- pass_flag = false;
+ // Checks if pixel is drawn and therefor testing it hasnt gone of screen
+ if (actual_pixel_status) {
+ printf ( "Passed!\n");
+ return true;
+ } else {
+ printf ( "Failed! value = %d (expecting %d)\n", actual_pixel_status, expected_pixel_status);
+ printf("\nactual psotion x,y= %d,%d : \n ",finish_x_postion, finish_y_postion );
+ return false;
}
-
- // Fail test if end postision is incorrect
- if (end_x_postion_two != 52 || end_y_postion_two != 1) {
- pass_flag = false;
- }
-
- return pass_flag;
}
#endif
\ No newline at end of file