Mercurial > public > hwos_code
annotate src/Tests/deco_volume_test.cpp @ 290:b1e47ee1f0a1
NEW gas_volume unit test in CCR mode. Works too.
author | jdg@air |
---|---|
date | Fri, 29 May 2015 02:50:12 +0200 |
parents | 08986d479b94 |
children | 6d6b3689b20b |
rev | line source |
---|---|
285 | 1 ////////////////////////////////////////////////////////////////////////////// |
2 /// deco_volume_test.cpp | |
3 /// Unit test for gas consumption c code. | |
4 /// Copyright (c) 2015, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
5 ////////////////////////////////////////////////////////////////////////////// | |
6 // HISTORY | |
288
08986d479b94
FIX gas_volume shall read gas switches from char_O_deco_gas
jdg@air
parents:
286
diff
changeset
|
7 // 2015-05-27 jDG: Creation for gas volum re-introduction in hwOS 1.82 |
285 | 8 |
9 extern "C" { | |
10 # include "p2_deco.c" | |
11 } | |
12 | |
13 #include <gtest/gtest.h> | |
14 | |
15 ////////////////////////////////////////////////////////////////////////////// | |
16 /// \brief Defines a default OC gas list | |
17 static void setup_gas() | |
18 { | |
19 char_I_first_gas = 1; | |
20 char_I_const_ppO2 = 0; // Default to OC mode | |
21 | |
22 #define DEFINE_GAS(gas, o2, he, depth, role) \ | |
23 char_I_deco_N2_ratio [gas-1] = 100 - o2 - he; \ | |
24 char_I_deco_He_ratio [gas-1] = he; \ | |
25 char_I_deco_gas_change[gas-1] = depth; | |
26 | |
27 DEFINE_GAS(1, 21, 0, 0, 1); // Gas#1 : Air FIRST | |
28 DEFINE_GAS(2, 18, 30, 0, 2); // Gas#2 : Tx18/30 TRAVEL | |
29 DEFINE_GAS(3, 80, 0, 9, 3); // Gas#3 : Nx80 @ 9m DECO | |
286 | 30 DEFINE_GAS(4, 21, 0, 0, 0); // Gas#2 : air @ 10m DISABLED |
31 DEFINE_GAS(5, 21, 0, 0, 0); // Gas#2 : air @ 40m DISABLED | |
285 | 32 } |
33 | |
34 ////////////////////////////////////////////////////////////////////////////// | |
35 /// \brief Define a default deco plan. | |
36 static void setup_plan() | |
37 { | |
38 // 1 min at 12m | |
39 char_O_deco_time [0] = 1; | |
40 char_O_deco_depth[0] =12; | |
41 char_O_deco_gas [0] = 1; // Gas#1 | |
42 // 1 min at 9m | |
43 char_O_deco_time [1] = 1; | |
44 char_O_deco_depth[1] = 9; | |
45 char_O_deco_gas [1] = 3; // Gas#3 | |
46 // 3min at 6m | |
47 char_O_deco_time [2] = 3; | |
48 char_O_deco_depth[2] = 6; | |
49 char_O_deco_gas [2] = 3; // Gas#3 | |
50 // 12 min at 3m | |
51 char_O_deco_time [3] =12; | |
52 char_O_deco_depth[3] = 3; | |
53 char_O_deco_gas [3] = 3; // Gas#3 | |
54 // Done | |
55 for(int s=4; s<NUM_STOPS; ++s) { | |
56 char_O_deco_time [s] = 0; | |
57 char_O_deco_depth[s] = 0; | |
58 char_O_deco_gas [s] = 0; | |
59 } | |
60 } | |
61 | |
62 static void setup_dive(int bottom, int depth) | |
63 { | |
64 setup_gas(); | |
65 setup_plan(); | |
66 | |
286 | 67 char_I_bottom_depth = depth; |
68 char_I_bottom_time = bottom; | |
69 } | |
70 | |
71 ////////////////////////////////////////////////////////////////////////////// | |
72 /// \brief Gas consumption at a fixed depth | |
73 static float fixed(int rmv, int time, int depth) { | |
74 return rmv * time * (1 + 0.1f*depth); | |
75 } | |
76 | |
77 TEST(gas_volume, fixed) | |
78 { | |
79 EXPECT_EQ(20*30*1, fixed(20,30, 0)); // 30' @ 0m | |
80 EXPECT_EQ(20*30*5, fixed(20,30,40)); // 30' @ 40m | |
81 } | |
82 | |
83 ////////////////////////////////////////////////////////////////////////////// | |
84 /// \brief Gas consumption during an ascent at 10m/min. | |
85 static float ascent(int rmv, int oldDepth, int newDepth) | |
86 { | |
87 return rmv | |
88 * abs(oldDepth-newDepth)*0.1f // Ascent time | |
89 * (1 + 0.05f*(oldDepth + newDepth)); // Avg pressure. | |
90 } | |
91 | |
92 TEST(gas_volume, ascent) | |
93 { | |
94 EXPECT_EQ(0, ascent(20, 30, 30)); // 30m -> 30m : no time, no conso | |
95 EXPECT_EQ(20*4*(1+2), ascent(20, 40, 0)); // 40m -> 0m : 4min, avg 20m | |
96 EXPECT_EQ(20*4*(1+2), ascent(20, 0, 40)); // 0m -> 40m : 4min, avg 20m | |
285 | 97 } |
98 | |
99 ////////////////////////////////////////////////////////////////////////////// | |
100 | |
290 | 101 TEST(gas_volume, OC_30min40m_no_stops) |
286 | 102 { |
103 setup_dive(30, 40); // 30' @ 40m | |
104 for(int s=0; s<32; ++s) | |
105 char_O_deco_time[s] = 0; | |
106 | |
107 ASSERT_NO_THROW( deco_gas_volumes() ); | |
108 EXPECT_EQ(fixed(20,30,40) + ascent(20,40,0), | |
109 int_O_gas_volumes[0]); | |
110 EXPECT_EQ(0, int_O_gas_volumes[1]); | |
111 EXPECT_EQ(0, int_O_gas_volumes[2]); | |
112 EXPECT_EQ(0, int_O_gas_volumes[3]); | |
113 EXPECT_EQ(0, int_O_gas_volumes[4]); | |
114 } | |
115 | |
116 ////////////////////////////////////////////////////////////////////////////// | |
117 | |
290 | 118 TEST(gas_volume, OC_30min40m_1min_1min_3min_12min) |
285 | 119 { |
120 setup_dive(30, 40); // 30' @ 40m | |
121 | |
286 | 122 ASSERT_NO_THROW( deco_gas_volumes() ); |
123 EXPECT_NEAR(fixed(20,30,40) + ascent(20,40,12) | |
124 + fixed(20, 1,12) + ascent(20,12,9), | |
125 int_O_gas_volumes[0], 1); | |
126 EXPECT_EQ(0, int_O_gas_volumes[1]); | |
127 EXPECT_NEAR(fixed(20, 1,9) + ascent(20,9,6) | |
128 + fixed(20, 3,6) + ascent(20,6,3) | |
129 + fixed(20,12,3) + ascent(20,3,0), | |
130 int_O_gas_volumes[2], 1); | |
131 EXPECT_EQ(0, int_O_gas_volumes[3]); | |
132 EXPECT_EQ(0, int_O_gas_volumes[4]); | |
285 | 133 } |
290 | 134 |
135 ////////////////////////////////////////////////////////////////////////////// | |
136 | |
137 TEST(gas_volume, CCR_30min40m_1min_1min_3min_12min) | |
138 { | |
139 setup_dive(30, 40); // 30' @ 40m | |
140 char_I_const_ppO2 = 140; | |
141 | |
142 ASSERT_NO_THROW( deco_gas_volumes() ); | |
143 | |
144 // BAILOUT at 40m: no bottom conso | |
145 EXPECT_NEAR(ascent(20,40,12) | |
146 + fixed(20, 1,12) + ascent(20,12,9), | |
147 int_O_gas_volumes[0], 1); | |
148 EXPECT_EQ(0, int_O_gas_volumes[1]); | |
149 EXPECT_NEAR(fixed(20, 1,9) + ascent(20,9,6) | |
150 + fixed(20, 3,6) + ascent(20,6,3) | |
151 + fixed(20,12,3) + ascent(20,3,0), | |
152 int_O_gas_volumes[2], 1); | |
153 EXPECT_EQ(0, int_O_gas_volumes[3]); | |
154 EXPECT_EQ(0, int_O_gas_volumes[4]); | |
155 } |