Reham Faqehi / Mbed 2 deprecated fy15raf

Dependencies:   mbed

Fork of fy15raf by ELEC2645 (2017/18)

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Spaceship-test.h Source File

Spaceship-test.h

00001 #ifndef SPACESHIP_TEST_H
00002 #define SPACESHIP_TEST_H
00003 
00004 /**
00005  * \brief Check that Spaceship object goes to correct position when it is updated
00006  * 
00007  * \returns true if all the tests passed
00008  */
00009 bool Spaceship_movement()
00010 {
00011   
00012     Spaceship S1;
00013     S1.init(); // x= 15  y=(HEIGHT/2)
00014 
00015     S1.update(N,2);//set Spaceship to move to the North with magnitude of 2 pixel -> y=(HEIGHT/2) will be changed to y=(HEIGHT/2)-speed and speed=meg*10
00016 
00017     Vector2D read_S1_pos = S1.get_pos();
00018     printf("Spaceship1 position x= %f, y= %f\n", read_S1_pos.x, read_S1_pos.y);  //print x and y pos.
00019 
00020     bool success_flag = true;
00021     
00022     // Fail the test if the position after updating is not equal to the expecting position
00023     if (read_S1_pos.x != 15 || read_S1_pos.y !=  (HEIGHT/2)-20) { // speed= (2)*10=20
00024         success_flag = false;
00025     }
00026 
00027 ///////////////another direction and meg to be tested ////////////////////////
00028 
00029     Spaceship S2;
00030     S2.init(); //// x= 15  y=(HEIGHT/2)
00031 
00032     S2.update(E,1); //set Spaceship to move toward East with magnitude of 1 pixel -> x=15 will be changed to x=15+speed and speed=meg*10
00033 
00034     Vector2D read_S2_pos = S2.get_pos();
00035     printf("Spaceship2 position x= %f, y= %f\n", read_S2_pos.x, read_S2_pos.y);  //print x and y pos.
00036 
00037     
00038     // Fail the test if the position after updating updating is not equal to the expecting position
00039     if (read_S2_pos.x != 15 +10 || read_S2_pos.y !=  (HEIGHT/2)) {// speed= (1)*10=10
00040         success_flag = false;
00041     }
00042 
00043     return success_flag;
00044 }
00045 #endif