comparison src/Tests/deco_volume_test.cpp @ 293:6d6b3689b20b

FIX tests to use plans copyed from actual OSTC3 1.82 computer.
author jDG
date Sat, 30 May 2015 22:43:53 +0200
parents b1e47ee1f0a1
children 7027d735ac62
comparison
equal deleted inserted replaced
292:ccb93f319e78 293:6d6b3689b20b
9 extern "C" { 9 extern "C" {
10 # include "p2_deco.c" 10 # include "p2_deco.c"
11 } 11 }
12 12
13 #include <gtest/gtest.h> 13 #include <gtest/gtest.h>
14 #include <iostream>
14 15
15 ////////////////////////////////////////////////////////////////////////////// 16 //////////////////////////////////////////////////////////////////////////////
16 /// \brief Defines a default OC gas list 17 /// \brief Defines a default OC gas list
17 static void setup_gas() 18 static void setup_gas()
18 { 19 {
19 char_I_first_gas = 1; 20 char_I_first_gas = 1;
20 char_I_const_ppO2 = 0; // Default to OC mode
21 21
22 #define DEFINE_GAS(gas, o2, he, depth, role) \ 22 #define DEFINE_GAS(gas, o2, he, depth, role) \
23 char_I_deco_N2_ratio [gas-1] = 100 - o2 - he; \ 23 char_I_deco_N2_ratio [gas-1] = 100 - o2 - he; \
24 char_I_deco_He_ratio [gas-1] = he; \ 24 char_I_deco_He_ratio [gas-1] = he; \
25 char_I_deco_gas_change[gas-1] = depth; 25 char_I_deco_gas_change[gas-1] = depth;
31 DEFINE_GAS(5, 21, 0, 0, 0); // Gas#2 : air @ 40m DISABLED 31 DEFINE_GAS(5, 21, 0, 0, 0); // Gas#2 : air @ 40m DISABLED
32 } 32 }
33 33
34 ////////////////////////////////////////////////////////////////////////////// 34 //////////////////////////////////////////////////////////////////////////////
35 /// \brief Define a default deco plan. 35 /// \brief Define a default deco plan.
36 static void setup_plan() 36 static void setup_plan(const char* stops,
37 { 37 const char* gas)
38 // 1 min at 12m 38 {
39 char_O_deco_time [0] = 1; 39 int depth = 3 * (stops ? strlen(stops) : 0);
40 char_O_deco_depth[0] =12; 40
41 char_O_deco_gas [0] = 1; // Gas#1 41 int s = 0;
42 // 1 min at 9m 42 while( depth > 0 && s < NUM_STOPS ) {
43 char_O_deco_time [1] = 1; 43 char_O_deco_time [s] = stops[s];
44 char_O_deco_depth[1] = 9; 44 char_O_deco_depth[s] = depth;
45 char_O_deco_gas [1] = 3; // Gas#3 45 char_O_deco_gas [s] = gas ? gas[s] : 1; // Gas#1 by default
46 // 3min at 6m 46 ++s;
47 char_O_deco_time [2] = 3; 47 depth -= 3;
48 char_O_deco_depth[2] = 6; 48 }
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 49 // Done
55 for(int s=4; s<NUM_STOPS; ++s) { 50 for(; s<NUM_STOPS; ++s) {
56 char_O_deco_time [s] = 0; 51 char_O_deco_time [s] = 0;
57 char_O_deco_depth[s] = 0; 52 char_O_deco_depth[s] = 0;
58 char_O_deco_gas [s] = 0; 53 char_O_deco_gas [s] = 0;
59 } 54 }
60 } 55 }
61 56
62 static void setup_dive(int bottom, int depth) 57 static void setup_dive(int bottom, int depth,
58 const char* stops = 0, const char* gas = 0)
63 { 59 {
64 setup_gas(); 60 setup_gas();
65 setup_plan(); 61 setup_plan(stops, gas);
66 62
67 char_I_bottom_depth = depth; 63 char_I_bottom_depth = depth;
68 char_I_bottom_time = bottom; 64 char_I_bottom_time = bottom;
69 } 65 }
70 66
94 EXPECT_EQ(0, ascent(20, 30, 30)); // 30m -> 30m : no time, no conso 90 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 91 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 92 EXPECT_EQ(20*4*(1+2), ascent(20, 0, 40)); // 0m -> 40m : 4min, avg 20m
97 } 93 }
98 94
99 ////////////////////////////////////////////////////////////////////////////// 95 static void check_volumes(float G1, const char* L1,
100 96 float G2, const char* L2,
101 TEST(gas_volume, OC_30min40m_no_stops) 97 float G3, const char* L3,
102 { 98 float G4, const char* L4,
103 setup_dive(30, 40); // 30' @ 40m 99 float G5, const char* L5)
104 for(int s=0; s<32; ++s) 100 {
105 char_O_deco_time[s] = 0; 101 std::cout << " " << std::setw(6) << G1 << " = " << L1 << std::endl;
106 102 std::cout << " " << std::setw(6) << G2 << " = " << L2 << std::endl;
107 ASSERT_NO_THROW( deco_gas_volumes() ); 103 std::cout << " " << std::setw(6) << G3 << " = " << L3 << std::endl;
108 EXPECT_EQ(fixed(20,30,40) + ascent(20,40,0), 104 std::cout << " " << std::setw(6) << G4 << " = " << L4 << std::endl;
109 int_O_gas_volumes[0]); 105 std::cout << " " << std::setw(6) << G5 << " = " << L5 << std::endl;
110 EXPECT_EQ(0, int_O_gas_volumes[1]); 106
111 EXPECT_EQ(0, int_O_gas_volumes[2]); 107 EXPECT_NEAR(G1, int_O_gas_volumes[0], 1) << L1;
112 EXPECT_EQ(0, int_O_gas_volumes[3]); 108 EXPECT_NEAR(G2, int_O_gas_volumes[1], 1) << L2;
113 EXPECT_EQ(0, int_O_gas_volumes[4]); 109 EXPECT_NEAR(G3, int_O_gas_volumes[2], 1) << L3;
114 } 110 EXPECT_NEAR(G4, int_O_gas_volumes[3], 1) << L4;
115 111 EXPECT_NEAR(G5, int_O_gas_volumes[4], 1) << L5;
116 ////////////////////////////////////////////////////////////////////////////// 112 }
117 113
118 TEST(gas_volume, OC_30min40m_1min_1min_3min_12min) 114 //////////////////////////////////////////////////////////////////////////////
119 { 115 // v1.82 ZH-L16+GF, OC, 30%/85%
120 setup_dive(30, 40); // 30' @ 40m 116 TEST(gas_volume, OC_13min30m)
121 117 {
122 ASSERT_NO_THROW( deco_gas_volumes() ); 118 char_I_const_ppO2 = 0; // OC
123 EXPECT_NEAR(fixed(20,30,40) + ascent(20,40,12) 119 setup_dive(13, 30); // 13' @ 30m --> no deco
124 + fixed(20, 1,12) + ascent(20,12,9), 120
125 int_O_gas_volumes[0], 1); 121 ASSERT_NO_THROW( deco_gas_volumes() );
126 EXPECT_EQ(0, int_O_gas_volumes[1]); 122 check_volumes(fixed(20,13,30) + ascent(20,30,0), "Gas1: 1190 L",
127 EXPECT_NEAR(fixed(20, 1,9) + ascent(20,9,6) 123 0, "",
128 + fixed(20, 3,6) + ascent(20,6,3) 124 0, "",
129 + fixed(20,12,3) + ascent(20,3,0), 125 0, "",
130 int_O_gas_volumes[2], 1); 126 0, "");
131 EXPECT_EQ(0, int_O_gas_volumes[3]); 127 }
132 EXPECT_EQ(0, int_O_gas_volumes[4]); 128
133 } 129 //////////////////////////////////////////////////////////////////////////////
134 130 // v1.82 ZH-L16+GF, OC, 30%/85%
135 ////////////////////////////////////////////////////////////////////////////// 131 TEST(gas_volume, OC_15min30m)
136 132 {
137 TEST(gas_volume, CCR_30min40m_1min_1min_3min_12min) 133 char_I_const_ppO2 = 0; // OC
138 { 134 char stops[] = {1, 0};
139 setup_dive(30, 40); // 30' @ 40m 135 char gas[] = {3, 0};
140 char_I_const_ppO2 = 140; 136 setup_dive(15, 30, stops, gas); // 15' @ 30m --> 1min at 3m
141 137
142 ASSERT_NO_THROW( deco_gas_volumes() ); 138 ASSERT_NO_THROW( deco_gas_volumes() );
143 139 check_volumes(fixed(20,15,30) + ascent(20,30,3), "Gas1: 1343 L",
144 // BAILOUT at 40m: no bottom conso 140 0, "",
145 EXPECT_NEAR(ascent(20,40,12) 141 fixed(20, 1, 3) + ascent(20, 3,0), "Gas3: 33",
146 + fixed(20, 1,12) + ascent(20,12,9), 142 0, "",
147 int_O_gas_volumes[0], 1); 143 0, "");
148 EXPECT_EQ(0, int_O_gas_volumes[1]); 144 }
149 EXPECT_NEAR(fixed(20, 1,9) + ascent(20,9,6) 145
150 + fixed(20, 3,6) + ascent(20,6,3) 146 //////////////////////////////////////////////////////////////////////////////
151 + fixed(20,12,3) + ascent(20,3,0), 147 // v1.82 ZH-L16+GF, OC, 30%/85%
152 int_O_gas_volumes[2], 1); 148 TEST(gas_volume, OC_29min30m)
153 EXPECT_EQ(0, int_O_gas_volumes[3]); 149 {
154 EXPECT_EQ(0, int_O_gas_volumes[4]); 150 char_I_const_ppO2 = 0; // OC
155 } 151 char stops[] = {1, 1, 2, 4, 0};
152 char gas[] = {1, 3, 3, 3, 0};
153 setup_dive(29, 30, stops, gas); // 29' @ 30m --> 1' 1' 2' 4'
154
155 ASSERT_NO_THROW( deco_gas_volumes() );
156 check_volumes(fixed(20,29,30) + ascent(20,30,12) +
157 fixed(20, 1,12) + ascent(20,12, 9), "Gas1: 2488 L",
158 0, "",
159 fixed(20, 1, 9) + ascent(20, 9, 6) +
160 fixed(20, 2, 6) + ascent(20, 6, 3) +
161 fixed(20, 4, 3) + ascent(20, 3, 0), "Gas3: 232 L",
162 0, "",
163 0, "");
164 }
165
166 //////////////////////////////////////////////////////////////////////////////
167 // v1.82 ZH-L16+GF, OC, 30%/85%
168 TEST(gas_volume, OC_15min60m)
169 {
170 char_I_const_ppO2 = 0; // OC
171 char stops[] = {2, 1, 2, 4, 3, 4, 9, 0};
172 char gas[] = {1, 1, 1, 1, 3, 3, 3, 0};
173 setup_dive(15, 60, stops, gas); // 15' @ 60m --> DTR 32'
174
175 ASSERT_NO_THROW( deco_gas_volumes() );
176 check_volumes(fixed(20,15,60) + ascent(20,60,21) +
177 fixed(20, 2,21) + ascent(20,21,18) +
178 fixed(20, 1,18) + ascent(20,18,15) +
179 fixed(20, 2,15) + ascent(20,15,12) +
180 fixed(20, 4,12) + ascent(20,12, 9), "Gas1: 3010 L",
181 0, "",
182 fixed(20, 3, 9) + ascent(20, 9, 6) +
183 fixed(20, 4, 6) + ascent(20, 6, 3) +
184 fixed(20, 9, 3) + ascent(20, 3, 0), "Gas3: 502 L",
185 0, "",
186 0, "");
187 }
188
189 //////////////////////////////////////////////////////////////////////////////
190 // v1.82 ZH-L16+GF, CCR, 30%/85%
191 TEST(gas_volume, CCR_13min30m)
192 {
193 char_I_const_ppO2 = 140;// SP 1.4 bar
194 setup_dive(13, 30); // 13' @ 30m --> no deco
195
196 ASSERT_NO_THROW( deco_gas_volumes() );
197 check_volumes(/*NO BTM CONSO*/ ascent(20,30,0), "Gas1: 1190 L",
198 0, "",
199 0, "",
200 0, "",
201 0, "");
202 }
203
204 //////////////////////////////////////////////////////////////////////////////
205 // v1.82 ZH-L16+GF, CCR, 30%/85%
206 TEST(gas_volume, CCR_15min30m)
207 {
208 char_I_const_ppO2 = 140; // SP 1.4 bar
209 char stops[] = {1, 0};
210 char gas[] = {3, 0};
211 setup_dive(15, 30, stops, gas); // 15' @ 30m --> 1min at 3m
212
213 ASSERT_NO_THROW( deco_gas_volumes() );
214 check_volumes(/*NO BTM CONSO*/ ascent(20,30,3), "Gas1: 1343 L",
215 0, "",
216 fixed(20, 1, 3) + ascent(20, 3,0), "Gas3: 33",
217 0, "",
218 0, "");
219 }
220
221 //////////////////////////////////////////////////////////////////////////////
222 // v1.82 ZH-L16+GF, CCR, 30%/85%
223 TEST(gas_volume, CCR_29min30m)
224 {
225 char_I_const_ppO2 = 140; // SP 1.4 bar
226 char stops[] = {1, 1, 2, 4, 0};
227 char gas[] = {1, 3, 3, 3, 0};
228 setup_dive(29, 30, stops, gas); // 29' @ 30m --> 1' 1' 2' 4'
229
230 ASSERT_NO_THROW( deco_gas_volumes() );
231 check_volumes(/*NO BTM CONSO*/ ascent(20,30,12) +
232 fixed(20, 1,12) + ascent(20,12, 9), "Gas1: 2488 L",
233 0, "",
234 fixed(20, 1, 9) + ascent(20, 9, 6) +
235 fixed(20, 2, 6) + ascent(20, 6, 3) +
236 fixed(20, 4, 3) + ascent(20, 3, 0), "Gas3: 232 L",
237 0, "",
238 0, "");
239 }
240
241 //////////////////////////////////////////////////////////////////////////////
242 // v1.82 ZH-L16+GF, CCR, 30%/85%
243 TEST(gas_volume, CCR_15min60m)
244 {
245 char_I_const_ppO2 = 140; // SP 1.4 bar
246 char stops[] = {2, 1, 2, 4, 3, 4, 9, 0};
247 char gas[] = {1, 1, 1, 1, 3, 3, 3, 0};
248 setup_dive(15, 60, stops, gas); // 15' @ 60m --> DTR 32'
249
250 ASSERT_NO_THROW( deco_gas_volumes() );
251 check_volumes(/*NO BTM CONSO*/ ascent(20,60,21) +
252 fixed(20, 2,21) + ascent(20,21,18) +
253 fixed(20, 1,18) + ascent(20,18,15) +
254 fixed(20, 2,15) + ascent(20,15,12) +
255 fixed(20, 4,12) + ascent(20,12, 9), "Gas1: 3010 L",
256 0, "",
257 fixed(20, 3, 9) + ascent(20, 9, 6) +
258 fixed(20, 4, 6) + ascent(20, 6, 3) +
259 fixed(20, 9, 3) + ascent(20, 3, 0), "Gas3: 502 L",
260 0, "",
261 0, "");
262 }