From 16f88948a840654eb0d131b9a7e29bbf882f13c2 Mon Sep 17 00:00:00 2001
From: Roque Porchetto <roque.porchetto@nexedi.com>
Date: Wed, 2 Aug 2023 13:41:31 +0000
Subject: [PATCH] erp5_officejs_drone: improve precision in script test -
 capture flag - drone simulator

---
 .../web_page_module/test_capture_drone_flight_js.js  | 12 +++++++-----
 .../web_page_module/test_capture_drone_flight_js.xml |  4 ++--
 .../test_drone_simulator_flight_js.js                |  8 +++++---
 .../test_drone_simulator_flight_js.xml               |  4 ++--
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.js b/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.js
index c554fcd181..bf2c00551b 100644
--- a/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.js
+++ b/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.js
@@ -55,7 +55,8 @@
       '  );\n' +
       '};\n' +
       'me.onUpdate = function (timestamp) {\n' +
-      'var realDistance = distance(\n' +
+      '  var current_position = me.getCurrentPosition(),\n' +
+      '  realDistance = distance(\n' +
       '  me.initialPosition.x,\n' +
       '  me.initialPosition.y,\n' +
       '  me.getCurrentPosition().x,\n' +
@@ -64,10 +65,11 @@
       '  expectedDistance = (me.getAirSpeed() * timestamp / 1000).toFixed(8);\n' +
       '  assert(timestamp, 1000 / 60, "Timestamp");\n' +
       '  assert(realDistance, expectedDistance, "Distance");\n' +
-      'compare(me.getCurrentPosition(), {\n' +
-      '  x: me.initialPosition.x + 2.3992831666911723e-06,\n' +
-      '  y: me.initialPosition.y,\n' +
-      '  z: me.initialPosition.z\n' +
+      '  current_position.x = current_position.x.toFixed(7);\n' +
+      '  compare(current_position, {\n' +
+      '    x: (me.initialPosition.x + 2.3992831666911723e-06).toFixed(7),\n' +
+      '    y: me.initialPosition.y,\n' +
+      '    z: me.initialPosition.z\n' +
       '});\n' +
       'me.exit(me.triggerParachute());\n' +
       '};',
diff --git a/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.xml b/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.xml
index 369bd80587..991721a211 100644
--- a/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.xml
+++ b/bt5/erp5_officejs_drone_capture_flag_test/PathTemplateItem/web_page_module/test_capture_drone_flight_js.xml
@@ -246,7 +246,7 @@
                   </item>
                   <item>
                       <key> <string>serial</string> </key>
-                      <value> <string>1009.56051.15404.48947</string> </value>
+                      <value> <string>1010.10600.362.51182</string> </value>
                   </item>
                   <item>
                       <key> <string>state</string> </key>
@@ -266,7 +266,7 @@
                           </tuple>
                           <state>
                             <tuple>
-                              <float>1690898400.26</float>
+                              <float>1690983490.56</float>
                               <string>UTC</string>
                             </tuple>
                           </state>
diff --git a/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.js b/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.js
index b6fe331517..91af85c627 100644
--- a/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.js
+++ b/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.js
@@ -68,7 +68,8 @@
       '};\n' +
       '\n' +
       'me.onUpdate = function (timestamp) {\n' +
-      '  var realDistance = distance(\n' +
+      '  var current_position = me.getCurrentPosition(),\n' +
+      '    realDistance = distance(\n' +
       '    me.initialPosition.x,\n' +
       '    me.initialPosition.y,\n' +
       '    me.getCurrentPosition().x,\n' +
@@ -77,8 +78,9 @@
       '    expectedDistance = (me.getAirSpeed() * timestamp / 1000).toFixed(8);\n' +
       '    assert(timestamp, 1000 / 60, "Timestamp");\n' +
       '    assert(realDistance, expectedDistance, "Distance");\n' +
-      '  compare(me.getCurrentPosition(), {\n' +
-      '    x: me.initialPosition.x + 2.3992831666911723e-06,\n' +
+      '  current_position.x = current_position.x.toFixed(7);\n' +
+      '  compare(current_position, {\n' +
+      '    x: (me.initialPosition.x + 2.3992831666911723e-06).toFixed(7),\n' +
       '    y: me.initialPosition.y,\n' +
       '    z: me.initialPosition.z\n' +
       '  });\n' +
diff --git a/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.xml b/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.xml
index 5ce05df7ec..00f43fb5cc 100644
--- a/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.xml
+++ b/bt5/erp5_officejs_drone_simulator_test/PathTemplateItem/web_page_module/test_drone_simulator_flight_js.xml
@@ -246,7 +246,7 @@
                   </item>
                   <item>
                       <key> <string>serial</string> </key>
-                      <value> <string>1010.3741.38295.37973</string> </value>
+                      <value> <string>1010.10621.5765.11161</string> </value>
                   </item>
                   <item>
                       <key> <string>state</string> </key>
@@ -266,7 +266,7 @@
                           </tuple>
                           <state>
                             <tuple>
-                              <float>1690898327.04</float>
+                              <float>1690900659.22</float>
                               <string>UTC</string>
                             </tuple>
                           </state>
-- 
2.30.9