ELEC2645 (2017/18) / Mbed 2 deprecated el17yw

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
RickYu
Date:
Mon Apr 30 20:53:08 2018 +0000
Parent:
28:85ddd500a116
Child:
30:057301068dac
Commit message:
written a test for boom move ,to check whether its x and y moves all the time

Changed in this revision

boom/boom-test.h Show annotated file Show diff for this revision Revisions of this file
boom/boom.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/boom/boom-test.h	Mon Apr 30 20:53:08 2018 +0000
@@ -0,0 +1,39 @@
+#ifndef BOOM_TEST_H
+#define BOOM_TEST_H
+
+/**
+check whether the boom will move as x+1,y+1
+ */
+bool boom_test_movement()
+{
+    //set the position of boom at(5,8)
+    boom boom;
+    boom.init(5, 8);
+
+    // get the position
+    Vector2D get_pos_1 = boom.get_pos();
+    printf("%f, %f\n", get_pos_1.x, get_pos_1.y);
+
+
+    // Update the position
+    boom.update();
+
+    // get the position
+    Vector2D get_pos_2 = boom.get_pos();
+    printf("%f, %f\n", get_pos_2.x, get_pos_2.y);
+    
+    bool success_flag = true;
+    
+    // if the initial position is wrong ,the  test failed
+    if (get_pos_1.x != 5 || get_pos_1.y != 8) {
+        success_flag = false;
+    }
+    
+    // the test is failed if the boom not go as excepted
+    if (get_pos_2.x != 9 || get_pos_2.y != 12) {
+        success_flag = false;
+    }
+
+    return success_flag;
+}
+#endif
\ No newline at end of file
--- a/boom/boom.cpp	Mon Apr 30 20:47:51 2018 +0000
+++ b/boom/boom.cpp	Mon Apr 30 20:53:08 2018 +0000
@@ -23,7 +23,8 @@
     //set the falling speed of boom
     //let the boom move with set speed
     boom_speed = 4;
-    boom_y+= boom_speed;  
+    boom_y+= boom_speed; 
+    boom_X+= boom_speed; 
 }
 
 Vector2D boom::get_pos()