yumaowei 201377547

Dependencies:   mbed ELEC2645_Project_el17my

Revision:
2:5e54476c518f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/prey/Prey-test.h	Tue May 26 07:24:21 2020 +0000
@@ -0,0 +1,49 @@
+#ifndef PREY_TEST_H
+#define PREY_TEST_H
+
+/**
+ * \brief Check that PREY object goes to correct position when moved
+ * 
+ * \returns true if all the tests passed
+ */
+bool prey_test_movement()
+{
+    // Initialise prey object with a size of 2, and speed of 1
+    Prey prey;
+    prey.init(2, 1);
+
+    // Set the position to 5, 5
+    POS2D initial_pos = {5, 5};
+    prey.set_pos(initial_pos);
+
+    // Read the position
+    POS2D read_pos_1 = prey.get_pos();
+    printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
+
+    // Set the velocity to -2, 3
+    POS2D velocity = {-2, 3};
+    prey.set_velocity(velocity);
+
+    // Update the position
+    prey.update();
+
+    // Read the position
+    POS2D read_pos_2 = prey.get_pos();
+    printf("%f, %f\n", read_pos_2.x, read_pos_2.y);
+    
+    // Now check that both the positions are as expected
+    bool success_flag = true;
+    
+    // Fail the test if the initial position is wrong
+    if (read_pos_1.x != 5 || read_pos_1.y != 5) {
+        success_flag = false;
+    }
+    
+    // Fail the test if the final position is wrong
+    if (read_pos_2.x != 3 || read_pos_2.y != 8) {
+        success_flag = false;
+    }
+
+    return success_flag;
+}
+#endif
\ No newline at end of file