ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jgb

Dependencies:   mbed

Revision:
21:a0f3651f56c4
Parent:
13:cfdfe60a2327
Child:
22:7406068f6c59
--- a/Spikes/Spikes_test.h	Fri May 22 14:06:35 2020 +0000
+++ b/Spikes/Spikes_test.h	Sat May 23 13:59:51 2020 +0000
@@ -8,25 +8,87 @@
  * @return true if test are passed 
  */
  
-bool Spikes_test_initial()
+bool Spikes_test_updatey()
 {
     // Initialise
     Spikes spikes;
-    spikes.init(); //_x = 0 _y = 0
-
+    spikes.position(2); 
+    
     // Read the position
-    Vector2D read_pos_1 = spikes.get_pos();
-    printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
+    Vector2D read_pos = spikes.get_pos();
+    printf("%f, %f\n", read_pos.x, read_pos.y);
 
     // Now check that both the position is as expected
     bool success_flag = true;
     
+    //update position
+    spikes.updatey();
+    
+    // Read the position
+    Vector2D read_pos_1 = spikes.get_pos();
+    printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
+    
     // Fail the test if the initial position is wrong
-    if (read_pos_1.x != 0 || read_pos_1.y != 0) {
+    if (read_pos_1.x != read_pos.x || read_pos_1.y != read_pos.y +3 ) {
         success_flag = false;
     }
 
     return success_flag;
 }
- 
+
+bool Spikes_test_updatex()
+{
+    // Initialise
+    Spikes spikes;
+    spikes.position(3); 
+    
+    // Read the position
+    Vector2D read_pos = spikes.get_pos();
+    printf("%f, %f\n", read_pos.x, read_pos.y);
+
+    // Now check that both the position is as expected
+    bool success_flag = true;
+    
+    //update position
+    spikes.updatey();
+    
+    // Read the position
+    Vector2D read_pos_1 = spikes.get_pos();
+    printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
+    
+    // Fail the test if the initial position is wrong
+    if (read_pos_1.x != read_pos.x + 3 || read_pos_1.y != read_pos.y ) {
+        success_flag = false;
+    }
+
+    return success_flag;
+}
+
+bool Spikes_test_updatexn()
+{
+    // Initialise
+    Spikes spikes;
+    spikes.position(4); 
+    
+    // Read the position
+    Vector2D read_pos = spikes.get_pos();
+    printf("%f, %f\n", read_pos.x, read_pos.y);
+
+    // Now check that both the position is as expected
+    bool success_flag = true;
+    
+    //update position
+    spikes.updatey();
+    
+    // Read the position
+    Vector2D read_pos_1 = spikes.get_pos();
+    printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
+    
+    // Fail the test if the initial position is wrong
+    if (read_pos_1.x != read_pos.x - 3 || read_pos_1.y != read_pos.y ) {
+        success_flag = false;
+    }
+
+    return success_flag;
+}
 #endif
\ No newline at end of file