333333333

Dependencies:   mbed

Committer:
Jenny121
Date:
Mon May 06 09:23:23 2019 +0000
Revision:
12:47a1d478493d
Parent:
10:167d0aa1c9b3
change the value of the code,

Who changed what in which revision?

UserRevisionLine numberNew contents of line
valavanisalex 10:167d0aa1c9b3 1 #ifndef BALL_TEST_H
valavanisalex 10:167d0aa1c9b3 2 #define BALL_TEST_H
valavanisalex 10:167d0aa1c9b3 3
valavanisalex 10:167d0aa1c9b3 4 /**
valavanisalex 10:167d0aa1c9b3 5 * \brief Check that Ball object goes to correct position when moved
valavanisalex 10:167d0aa1c9b3 6 *
valavanisalex 10:167d0aa1c9b3 7 * \returns true if all the tests passed
valavanisalex 10:167d0aa1c9b3 8 */
valavanisalex 10:167d0aa1c9b3 9 bool Ball_test_movement()
valavanisalex 10:167d0aa1c9b3 10 {
valavanisalex 10:167d0aa1c9b3 11 // Initialise Ball object with a size of 2, and speed of 1
valavanisalex 10:167d0aa1c9b3 12 Ball ball;
valavanisalex 10:167d0aa1c9b3 13 ball.init(2, 1);
valavanisalex 10:167d0aa1c9b3 14
valavanisalex 10:167d0aa1c9b3 15 // Set the position to 5, 5
valavanisalex 10:167d0aa1c9b3 16 Vector2D initial_pos = {5, 5};
valavanisalex 10:167d0aa1c9b3 17 ball.set_pos(initial_pos);
valavanisalex 10:167d0aa1c9b3 18
valavanisalex 10:167d0aa1c9b3 19 // Read the position
valavanisalex 10:167d0aa1c9b3 20 Vector2D read_pos_1 = ball.get_pos();
valavanisalex 10:167d0aa1c9b3 21 printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
valavanisalex 10:167d0aa1c9b3 22
valavanisalex 10:167d0aa1c9b3 23 // Set the velocity to -2, 3
valavanisalex 10:167d0aa1c9b3 24 Vector2D velocity = {-2, 3};
valavanisalex 10:167d0aa1c9b3 25 ball.set_velocity(velocity);
valavanisalex 10:167d0aa1c9b3 26
valavanisalex 10:167d0aa1c9b3 27 // Update the position
valavanisalex 10:167d0aa1c9b3 28 ball.update();
valavanisalex 10:167d0aa1c9b3 29
valavanisalex 10:167d0aa1c9b3 30 // Read the position
valavanisalex 10:167d0aa1c9b3 31 Vector2D read_pos_2 = ball.get_pos();
valavanisalex 10:167d0aa1c9b3 32 printf("%f, %f\n", read_pos_2.x, read_pos_2.y);
valavanisalex 10:167d0aa1c9b3 33
valavanisalex 10:167d0aa1c9b3 34 // Now check that both the positions are as expected
valavanisalex 10:167d0aa1c9b3 35 bool success_flag = true;
valavanisalex 10:167d0aa1c9b3 36
valavanisalex 10:167d0aa1c9b3 37 // Fail the test if the initial position is wrong
valavanisalex 10:167d0aa1c9b3 38 if (read_pos_1.x != 5 || read_pos_1.y != 5) {
valavanisalex 10:167d0aa1c9b3 39 success_flag = false;
valavanisalex 10:167d0aa1c9b3 40 }
valavanisalex 10:167d0aa1c9b3 41
valavanisalex 10:167d0aa1c9b3 42 // Fail the test if the final position is wrong
valavanisalex 10:167d0aa1c9b3 43 if (read_pos_2.x != 3 || read_pos_2.y != 8) {
valavanisalex 10:167d0aa1c9b3 44 success_flag = false;
valavanisalex 10:167d0aa1c9b3 45 }
valavanisalex 10:167d0aa1c9b3 46
valavanisalex 10:167d0aa1c9b3 47 return success_flag;
valavanisalex 10:167d0aa1c9b3 48 }
valavanisalex 10:167d0aa1c9b3 49 #endif