annotate src/Tests/deco_volume_test.cpp @ 289:30edd177016a

[mq]: 2015-05-29_02-40-44_r288+.diff
author jdg@air
date Fri, 29 May 2015 02:46:44 +0200
parents 08986d479b94
children b1e47ee1f0a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
285
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
1 //////////////////////////////////////////////////////////////////////////////
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
2 /// deco_volume_test.cpp
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
3 /// Unit test for gas consumption c code.
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
4 /// Copyright (c) 2015, JD Gascuel, HeinrichsWeikamp, all right reserved.
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
5 //////////////////////////////////////////////////////////////////////////////
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
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
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
8
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
9 extern "C" {
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
10 # include "p2_deco.c"
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
11 }
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
12
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
13 #include <gtest/gtest.h>
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
14
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
15 //////////////////////////////////////////////////////////////////////////////
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
16 /// \brief Defines a default OC gas list
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
17 static void setup_gas()
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
18 {
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
19 char_I_first_gas = 1;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
20 char_I_const_ppO2 = 0; // Default to OC mode
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
21
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
22 #define DEFINE_GAS(gas, o2, he, depth, role) \
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
23 char_I_deco_N2_ratio [gas-1] = 100 - o2 - he; \
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
24 char_I_deco_He_ratio [gas-1] = he; \
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
25 char_I_deco_gas_change[gas-1] = depth;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
26
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
27 DEFINE_GAS(1, 21, 0, 0, 1); // Gas#1 : Air FIRST
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
28 DEFINE_GAS(2, 18, 30, 0, 2); // Gas#2 : Tx18/30 TRAVEL
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
29 DEFINE_GAS(3, 80, 0, 9, 3); // Gas#3 : Nx80 @ 9m DECO
286
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
30 DEFINE_GAS(4, 21, 0, 0, 0); // Gas#2 : air @ 10m DISABLED
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
31 DEFINE_GAS(5, 21, 0, 0, 0); // Gas#2 : air @ 40m DISABLED
285
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
32 }
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
33
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
34 //////////////////////////////////////////////////////////////////////////////
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
35 /// \brief Define a default deco plan.
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
36 static void setup_plan()
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
37 {
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
38 // 1 min at 12m
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
39 char_O_deco_time [0] = 1;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
40 char_O_deco_depth[0] =12;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
41 char_O_deco_gas [0] = 1; // Gas#1
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
42 // 1 min at 9m
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
43 char_O_deco_time [1] = 1;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
44 char_O_deco_depth[1] = 9;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
45 char_O_deco_gas [1] = 3; // Gas#3
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
46 // 3min at 6m
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
47 char_O_deco_time [2] = 3;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
48 char_O_deco_depth[2] = 6;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
49 char_O_deco_gas [2] = 3; // Gas#3
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
50 // 12 min at 3m
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
51 char_O_deco_time [3] =12;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
52 char_O_deco_depth[3] = 3;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
53 char_O_deco_gas [3] = 3; // Gas#3
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
54 // Done
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
55 for(int s=4; s<NUM_STOPS; ++s) {
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
56 char_O_deco_time [s] = 0;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
57 char_O_deco_depth[s] = 0;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
58 char_O_deco_gas [s] = 0;
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
59 }
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
60 }
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
61
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
62 static void setup_dive(int bottom, int depth)
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
63 {
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
64 setup_gas();
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
65 setup_plan();
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
66
286
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
67 char_I_bottom_depth = depth;
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
68 char_I_bottom_time = bottom;
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
69 }
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
70
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
71 //////////////////////////////////////////////////////////////////////////////
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
72 /// \brief Gas consumption at a fixed depth
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
73 static float fixed(int rmv, int time, int depth) {
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
74 return rmv * time * (1 + 0.1f*depth);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
75 }
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
76
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
77 TEST(gas_volume, fixed)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
78 {
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
79 EXPECT_EQ(20*30*1, fixed(20,30, 0)); // 30' @ 0m
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
80 EXPECT_EQ(20*30*5, fixed(20,30,40)); // 30' @ 40m
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
81 }
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
82
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
83 //////////////////////////////////////////////////////////////////////////////
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
84 /// \brief Gas consumption during an ascent at 10m/min.
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
85 static float ascent(int rmv, int oldDepth, int newDepth)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
86 {
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
87 return rmv
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
88 * abs(oldDepth-newDepth)*0.1f // Ascent time
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
89 * (1 + 0.05f*(oldDepth + newDepth)); // Avg pressure.
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
90 }
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
91
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
92 TEST(gas_volume, ascent)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
93 {
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
94 EXPECT_EQ(0, ascent(20, 30, 30)); // 30m -> 30m : no time, no conso
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
95 EXPECT_EQ(20*4*(1+2), ascent(20, 40, 0)); // 40m -> 0m : 4min, avg 20m
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
96 EXPECT_EQ(20*4*(1+2), ascent(20, 0, 40)); // 0m -> 40m : 4min, avg 20m
285
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
97 }
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
98
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
99 //////////////////////////////////////////////////////////////////////////////
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
100
286
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
101 TEST(gas_volume, 30min40m_no_stops)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
102 {
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
103 setup_dive(30, 40); // 30' @ 40m
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
104 for(int s=0; s<32; ++s)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
105 char_O_deco_time[s] = 0;
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
106
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
107 ASSERT_NO_THROW( deco_gas_volumes() );
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
108 EXPECT_EQ(fixed(20,30,40) + ascent(20,40,0),
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
109 int_O_gas_volumes[0]);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
110 EXPECT_EQ(0, int_O_gas_volumes[1]);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
111 EXPECT_EQ(0, int_O_gas_volumes[2]);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
112 EXPECT_EQ(0, int_O_gas_volumes[3]);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
113 EXPECT_EQ(0, int_O_gas_volumes[4]);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
114 }
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
115
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
116 //////////////////////////////////////////////////////////////////////////////
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
117
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
118 TEST(gas_volume, 30min40m_1min_1min_3min_12min)
285
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
119 {
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
120 setup_dive(30, 40); // 30' @ 40m
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
121
286
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
122 ASSERT_NO_THROW( deco_gas_volumes() );
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
123 EXPECT_NEAR(fixed(20,30,40) + ascent(20,40,12)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
124 + fixed(20, 1,12) + ascent(20,12,9),
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
125 int_O_gas_volumes[0], 1);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
126 EXPECT_EQ(0, int_O_gas_volumes[1]);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
127 EXPECT_NEAR(fixed(20, 1,9) + ascent(20,9,6)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
128 + fixed(20, 3,6) + ascent(20,6,3)
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
129 + fixed(20,12,3) + ascent(20,3,0),
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
130 int_O_gas_volumes[2], 1);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
131 EXPECT_EQ(0, int_O_gas_volumes[3]);
729b01914098 NEW test w/o stops and with stops
jdg@air
parents: 285
diff changeset
132 EXPECT_EQ(0, int_O_gas_volumes[4]);
285
cd2320cd6f9a NEW unit tests for gas volumes...
jdg@air
parents:
diff changeset
133 }