ELEC2645 (2017/18) / Mbed 2 deprecated el17yw

Dependencies:   mbed

Committer:
RickYu
Date:
Mon Apr 30 20:53:08 2018 +0000
Revision:
29:f3e24ccc401d
Child:
31:e39a1ab1f12d
written a test for boom move ,to check whether its x and y moves all the time

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RickYu 29:f3e24ccc401d 1 #ifndef BOOM_TEST_H
RickYu 29:f3e24ccc401d 2 #define BOOM_TEST_H
RickYu 29:f3e24ccc401d 3
RickYu 29:f3e24ccc401d 4 /**
RickYu 29:f3e24ccc401d 5 check whether the boom will move as x+1,y+1
RickYu 29:f3e24ccc401d 6 */
RickYu 29:f3e24ccc401d 7 bool boom_test_movement()
RickYu 29:f3e24ccc401d 8 {
RickYu 29:f3e24ccc401d 9 //set the position of boom at(5,8)
RickYu 29:f3e24ccc401d 10 boom boom;
RickYu 29:f3e24ccc401d 11 boom.init(5, 8);
RickYu 29:f3e24ccc401d 12
RickYu 29:f3e24ccc401d 13 // get the position
RickYu 29:f3e24ccc401d 14 Vector2D get_pos_1 = boom.get_pos();
RickYu 29:f3e24ccc401d 15 printf("%f, %f\n", get_pos_1.x, get_pos_1.y);
RickYu 29:f3e24ccc401d 16
RickYu 29:f3e24ccc401d 17
RickYu 29:f3e24ccc401d 18 // Update the position
RickYu 29:f3e24ccc401d 19 boom.update();
RickYu 29:f3e24ccc401d 20
RickYu 29:f3e24ccc401d 21 // get the position
RickYu 29:f3e24ccc401d 22 Vector2D get_pos_2 = boom.get_pos();
RickYu 29:f3e24ccc401d 23 printf("%f, %f\n", get_pos_2.x, get_pos_2.y);
RickYu 29:f3e24ccc401d 24
RickYu 29:f3e24ccc401d 25 bool success_flag = true;
RickYu 29:f3e24ccc401d 26
RickYu 29:f3e24ccc401d 27 // if the initial position is wrong ,the test failed
RickYu 29:f3e24ccc401d 28 if (get_pos_1.x != 5 || get_pos_1.y != 8) {
RickYu 29:f3e24ccc401d 29 success_flag = false;
RickYu 29:f3e24ccc401d 30 }
RickYu 29:f3e24ccc401d 31
RickYu 29:f3e24ccc401d 32 // the test is failed if the boom not go as excepted
RickYu 29:f3e24ccc401d 33 if (get_pos_2.x != 9 || get_pos_2.y != 12) {
RickYu 29:f3e24ccc401d 34 success_flag = false;
RickYu 29:f3e24ccc401d 35 }
RickYu 29:f3e24ccc401d 36
RickYu 29:f3e24ccc401d 37 return success_flag;
RickYu 29:f3e24ccc401d 38 }
RickYu 29:f3e24ccc401d 39 #endif