Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

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

Ball-test.h

00001 #ifndef BALL_TEST_H
00002 #define BALL_TEST_H
00003 
00004 /**
00005  * @brief Check that Ball object goes to correct position when moved
00006  * 
00007  * @return true if all the tests passed
00008  */
00009 bool Ball_test_movement()
00010 {
00011     // Initialise Ball object with the reset function
00012     Ball ball;
00013     ball.reset();
00014     
00015     // Read the position
00016     Vector2D read_pos_1 = ball.getPos();
00017     printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
00018 
00019 
00020     // Move the ball (Update the position)
00021     ball.move();
00022 
00023     // Read the position
00024     Vector2D read_pos_2 = ball.getPos();
00025     printf("%f, %f\n", read_pos_2.x, read_pos_2.y);
00026     
00027     // Now check that both the positions are as expected
00028     bool success_flag = true;
00029     
00030     // Fail the test if the initial position is wrong
00031     if (read_pos_1.x != 42 || read_pos_1.y != 42) {
00032         success_flag = false;
00033     }
00034     
00035     // Fail the test if the final position is wrong
00036     if ((read_pos_2.x == 43) || (read_pos_2.y == 41) || (read_pos_2.x == 41)) {
00037         success_flag = true;
00038     }
00039     else {
00040         success_flag = false;
00041     }
00042 
00043     return success_flag;
00044 }
00045 #endif