Zikang Qian / Mbed 2 deprecated el17z2q

Dependencies:   mbed

Fork of el17z2q by ELEC2645 (2017/18)

Committer:
yzjdxl
Date:
Mon May 07 21:24:25 2018 +0000
Revision:
1:00a4ea97c4cd
Child:
2:6dc7bc55c1cb
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yzjdxl 1:00a4ea97c4cd 1 #ifndef COINWITHBAG_TEST_H
yzjdxl 1:00a4ea97c4cd 2 #define COINWITHBAG_TEST_H
yzjdxl 1:00a4ea97c4cd 3
yzjdxl 1:00a4ea97c4cd 4 /** CoinWithBag-test Class
yzjdxl 1:00a4ea97c4cd 5 * @brief Check that the coin object correctly collides with the bag
yzjdxl 1:00a4ea97c4cd 6 * @author Zikang Qian
yzjdxl 1:00a4ea97c4cd 7 * @date April, 2018
yzjdxl 1:00a4ea97c4cd 8 */
yzjdxl 1:00a4ea97c4cd 9
yzjdxl 1:00a4ea97c4cd 10 /** \returns true if all the tests passed
yzjdxl 1:00a4ea97c4cd 11 */
yzjdxl 1:00a4ea97c4cd 12 bool CoinWithBag_test_collide()
yzjdxl 1:00a4ea97c4cd 13 {
yzjdxl 1:00a4ea97c4cd 14 Coin coin;
yzjdxl 1:00a4ea97c4cd 15 Bag bag;
yzjdxl 1:00a4ea97c4cd 16 GameEngine game;
yzjdxl 1:00a4ea97c4cd 17
yzjdxl 1:00a4ea97c4cd 18 coin.init(2.5,1);
yzjdxl 1:00a4ea97c4cd 19 bag.init(17,2,1);
yzjdxl 1:00a4ea97c4cd 20 game.init(17,2,2.5,1);
yzjdxl 1:00a4ea97c4cd 21
yzjdxl 1:00a4ea97c4cd 22 Vector2D initial_coin_position = {5, 0};
yzjdxl 1:00a4ea97c4cd 23 coin.set_position(initial_coin_position);
yzjdxl 1:00a4ea97c4cd 24
yzjdxl 1:00a4ea97c4cd 25 Vector2D initial_bag_position = {3, 46};
yzjdxl 1:00a4ea97c4cd 26 bag.set_position(initial_bag_position);
yzjdxl 1:00a4ea97c4cd 27
yzjdxl 1:00a4ea97c4cd 28 // Read the position
yzjdxl 1:00a4ea97c4cd 29 Vector2D read_coin_position = coin.get_position();
yzjdxl 1:00a4ea97c4cd 30 printf("%f, %f\n", read_coin_position.x, read_coin_position.y);
yzjdxl 1:00a4ea97c4cd 31
yzjdxl 1:00a4ea97c4cd 32 Vector2D read_bag_position = bag.get_position();
yzjdxl 1:00a4ea97c4cd 33 printf("%f, %f\n", read_bag_position.x, read_bag_position.y);
yzjdxl 1:00a4ea97c4cd 34
yzjdxl 1:00a4ea97c4cd 35 // Set the velocity to -2, 3
yzjdxl 1:00a4ea97c4cd 36 Vector2D velocity = {0, 46};
yzjdxl 1:00a4ea97c4cd 37 coin.set_velocity(velocity);
yzjdxl 1:00a4ea97c4cd 38
yzjdxl 1:00a4ea97c4cd 39 // Update the position
yzjdxl 1:00a4ea97c4cd 40 coin.update();
yzjdxl 1:00a4ea97c4cd 41 bag.update();
yzjdxl 1:00a4ea97c4cd 42
yzjdxl 1:00a4ea97c4cd 43 int nodead = game.update(pad);
yzjdxl 1:00a4ea97c4cd 44
yzjdxl 1:00a4ea97c4cd 45 // Now check that both the positions are as expected
yzjdxl 1:00a4ea97c4cd 46 bool success = true;
yzjdxl 1:00a4ea97c4cd 47
yzjdxl 1:00a4ea97c4cd 48 // Fail the test if the initial position is wrong
yzjdxl 1:00a4ea97c4cd 49 if (nodead != 1) {
yzjdxl 1:00a4ea97c4cd 50 success = false;
yzjdxl 1:00a4ea97c4cd 51 }
yzjdxl 1:00a4ea97c4cd 52
yzjdxl 1:00a4ea97c4cd 53 return success;
yzjdxl 1:00a4ea97c4cd 54 }
yzjdxl 1:00a4ea97c4cd 55
yzjdxl 1:00a4ea97c4cd 56 #endif