not final

Dependencies:   mbed

Committer:
ChenZirui
Date:
Fri May 29 04:25:22 2020 +0000
Revision:
14:3b4370d5b2c0
Parent:
5:7207c9b70108
not final

Who changed what in which revision?

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