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.
Ball/ball_test.h@39:dfc489594f11, 2019-05-09 (annotated)
- Committer:
- JamesCummins
- Date:
- Thu May 09 01:58:36 2019 +0000
- Revision:
- 39:dfc489594f11
- Child:
- 40:a1cdb6ab08af
Added test benches and included in main. Think I'm now all finished. Will check everything and produce final commit tomorrow morning
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JamesCummins | 39:dfc489594f11 | 1 | #ifndef BALL_TEST_H |
JamesCummins | 39:dfc489594f11 | 2 | #define BALL_TEST_H |
JamesCummins | 39:dfc489594f11 | 3 | |
JamesCummins | 39:dfc489594f11 | 4 | /** Ball Test |
JamesCummins | 39:dfc489594f11 | 5 | @brief Check that the ball moves as it should without seeding by the accelerometer |
JamesCummins | 39:dfc489594f11 | 6 | @returns true if moves correctly, false if moves incorrectly |
JamesCummins | 39:dfc489594f11 | 7 | */ |
JamesCummins | 39:dfc489594f11 | 8 | |
JamesCummins | 39:dfc489594f11 | 9 | bool ball_test(){ |
JamesCummins | 39:dfc489594f11 | 10 | Ball ball; //create ball object |
JamesCummins | 39:dfc489594f11 | 11 | ball.init(3) //set radius to 3 |
JamesCummins | 39:dfc489594f11 | 12 | Vector2D ball_pos = {10, 20}; //give ball initial position of (10,20) |
JamesCummins | 39:dfc489594f11 | 13 | ball.set_position(ball_pos); |
JamesCummins | 39:dfc489594f11 | 14 | Vector2D ball_vel = {3, -5}; //give ball initial velocity of (3, -5) |
JamesCummins | 39:dfc489594f11 | 15 | ball.set_velocity(ball_vel); |
JamesCummins | 39:dfc489594f11 | 16 | ball.update(); //update ball position |
JamesCummins | 39:dfc489594f11 | 17 | ball_pos = ball.get_position(); |
JamesCummins | 39:dfc489594f11 | 18 | |
JamesCummins | 39:dfc489594f11 | 19 | bool passed = true; |
JamesCummins | 39:dfc489594f11 | 20 | if(ball_pos.x != 13){ passed = false; } //check whether ball in correct position |
JamesCummins | 39:dfc489594f11 | 21 | else if(ball_pos.y != 15){ passed = false; } //return false if not |
JamesCummins | 39:dfc489594f11 | 22 | else { passed = true; } |
JamesCummins | 39:dfc489594f11 | 23 | return passed; |
JamesCummins | 39:dfc489594f11 | 24 | } |
JamesCummins | 39:dfc489594f11 | 25 | |
JamesCummins | 39:dfc489594f11 | 26 | #endif |