changeset 286:729b01914098

NEW test w/o stops and with stops
author jdg@air
date Fri, 29 May 2015 02:07:28 +0200
parents cd2320cd6f9a
children f342853afcd9
files src/Tests/deco_volume_test.cpp
diffstat 1 files changed, 61 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/Tests/deco_volume_test.cpp	Fri May 29 01:25:45 2015 +0200
+++ b/src/Tests/deco_volume_test.cpp	Fri May 29 02:07:28 2015 +0200
@@ -27,8 +27,8 @@
     DEFINE_GAS(1, 21,  0, 0, 1);    // Gas#1 : Air       FIRST
     DEFINE_GAS(2, 18, 30, 0, 2);    // Gas#2 : Tx18/30   TRAVEL
     DEFINE_GAS(3, 80,  0, 9, 3);    // Gas#3 : Nx80 @ 9m DECO
-    DEFINE_GAS(4, 21, 0, 10, 0);    // Gas#2 : air @ 10m DISABLED
-    DEFINE_GAS(5, 21, 0, 40, 0);    // Gas#2 : air @ 40m DISABLED
+    DEFINE_GAS(4, 21, 0,  0, 0);    // Gas#2 : air @ 10m DISABLED
+    DEFINE_GAS(5, 21, 0,  0, 0);    // Gas#2 : air @ 40m DISABLED
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -64,15 +64,70 @@
     setup_gas();
     setup_plan();
 
-    char_I_bottom_depth = bottom;
-    char_I_bottom_time  = depth;
+    char_I_bottom_depth = depth;
+    char_I_bottom_time  = bottom;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+/// \brief Gas consumption at a fixed depth
+static float fixed(int rmv, int time, int depth) {
+    return rmv * time * (1 + 0.1f*depth);
+}
+
+TEST(gas_volume, fixed)
+{
+    EXPECT_EQ(20*30*1, fixed(20,30, 0));    // 30' @  0m
+    EXPECT_EQ(20*30*5, fixed(20,30,40));    // 30' @ 40m
+}
+
+//////////////////////////////////////////////////////////////////////////////
+/// \brief Gas consumption during an ascent at 10m/min.
+static float ascent(int rmv, int oldDepth, int newDepth)
+{
+    return rmv
+         * abs(oldDepth-newDepth)*0.1f          // Ascent time
+         * (1 + 0.05f*(oldDepth + newDepth));   // Avg pressure.
+}
+
+TEST(gas_volume, ascent)
+{
+    EXPECT_EQ(0,          ascent(20, 30, 30));  // 30m -> 30m : no time, no conso
+    EXPECT_EQ(20*4*(1+2), ascent(20, 40,  0));  // 40m ->  0m : 4min, avg 20m
+    EXPECT_EQ(20*4*(1+2), ascent(20,  0, 40));  // 0m  -> 40m : 4min, avg 20m
 }
 
 //////////////////////////////////////////////////////////////////////////////
 
-TEST(gas_volume, run)
+TEST(gas_volume, 30min40m_no_stops)
+{
+    setup_dive(30, 40);     // 30' @ 40m
+    for(int s=0; s<32; ++s)
+        char_O_deco_time[s] = 0;
+
+    ASSERT_NO_THROW( deco_gas_volumes() );
+    EXPECT_EQ(fixed(20,30,40) + ascent(20,40,0),
+              int_O_gas_volumes[0]);
+    EXPECT_EQ(0,  int_O_gas_volumes[1]);
+    EXPECT_EQ(0,  int_O_gas_volumes[2]);
+    EXPECT_EQ(0,  int_O_gas_volumes[3]);
+    EXPECT_EQ(0,  int_O_gas_volumes[4]);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+TEST(gas_volume, 30min40m_1min_1min_3min_12min)
 {
     setup_dive(30, 40);     // 30' @ 40m
 
-    EXPECT_NO_THROW( deco_gas_volumes() );
+    ASSERT_NO_THROW( deco_gas_volumes() );
+    EXPECT_NEAR(fixed(20,30,40) + ascent(20,40,12)
+              + fixed(20, 1,12) + ascent(20,12,9),
+              int_O_gas_volumes[0], 1);
+    EXPECT_EQ(0, int_O_gas_volumes[1]);
+    EXPECT_NEAR(fixed(20, 1,9) + ascent(20,9,6)
+              + fixed(20, 3,6) + ascent(20,6,3)
+              + fixed(20,12,3) + ascent(20,3,0),
+              int_O_gas_volumes[2], 1);
+    EXPECT_EQ(0, int_O_gas_volumes[3]);
+    EXPECT_EQ(0, int_O_gas_volumes[4]);
 }