James Cummins / Mbed 2 deprecated el17jnc

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 /** Ball Test
00005 @brief Check that the ball moves as it should without seeding by the accelerometer
00006 @returns true if moves correctly, false if moves incorrectly
00007 */
00008 
00009 bool ball_test(){
00010     Ball ball;      //create ball object
00011     ball.init(3);    //set radius to 3
00012     Vector2D ball_pos = {10, 20};       //give ball initial position of (10,20)
00013     ball.set_position(ball_pos);
00014     Vector2D ball_vel = {3, -5};        //give ball initial velocity of (3, -5)
00015     ball.set_velocity(ball_vel);
00016     ball.update();                      //update ball position
00017     ball_pos = ball.get_position();     
00018     
00019     bool passed = true;
00020     if(ball_pos.x != 13){ passed = false; }         //check whether ball in correct position
00021     else if(ball_pos.y != 15){ passed = false; }    //return false if not
00022     else { passed = true; }
00023     return passed;
00024 }
00025 
00026 #endif