Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Paddle-Test.h Source File

Paddle-Test.h

00001 #ifndef PADDLE_TEST_H
00002 #define PADDLE_TEST_H
00003 
00004 /**
00005  * @brief Check that Paddle object goes to correct position when moved
00006  * 
00007  * @return true if all the tests passed
00008  */
00009 bool Paddle_test_movement()
00010 {
00011     // Initialise Ball object with the reset function
00012     Paddle paddle;
00013     paddle.reset();
00014     
00015 
00016     // Read the position
00017     Vector2D read_pos_1 = paddle.getPos();
00018     printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
00019 
00020 
00021     // Move the paddle (It won't move so the position should be the same,
00022     // as joystick is not touched)
00023     paddle.move();
00024 
00025     // Read the position
00026     Vector2D read_pos_2 = paddle.getPos();
00027     printf("%f, %f\n", read_pos_2.x, read_pos_2.y);
00028     
00029     // Now check that both the positions are as expected
00030     bool success_flag = true;
00031     
00032     // Fail the test if the initial position is wrong
00033     if (read_pos_1.x != WIDTH/2 || read_pos_1.y != HEIGHT - GAP) {
00034         success_flag = false;
00035     }
00036     
00037     // Fail the test if the final position is wrong
00038     if (read_pos_2.x != WIDTH/2 || read_pos_2.y != HEIGHT - GAP) {
00039         success_flag = false;
00040     }
00041 
00042     return success_flag;
00043 }
00044 #endif