Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | #include "pch.h" | |||
2 | #include "dynoview.h" | |||
3 | ||||
4 | struct DynoViewTestData { | |||
5 | const float time; | |||
6 | const int rpm; | |||
7 | const int tps; | |||
8 | const float torque; | |||
9 | const float hp; | |||
10 | }; | |||
11 | ||||
12 | // time, rpm, tps, torque, hp (got from real car) | |||
13 | std::vector<DynoViewTestData> testData = { | |||
14 | // run 1 | |||
15 | {1199.91, 2237, 98, 0, 0}, | |||
16 | {1200.33, 2358, 98, 132.507, 43.8788}, | |||
17 | {1200.71, 2468, 98, 132.507, 43.8788}, | |||
18 | {1201.06, 2575, 98, 101.319, 34.0879}, | |||
19 | {1201.42, 2677, 98, 101.319, 34.0879}, | |||
20 | {1201.77, 2803, 98, 91.7098, 31.4668}, | |||
21 | {1202.06, 2900, 98, 91.7098, 31.4668}, | |||
22 | {1202.39, 3019, 98, 89.463, 31.3981}, | |||
23 | {1202.66, 3133, 98, 89.463, 31.3981}, | |||
24 | {1202.92, 3237, 98, 91.1714, 32.8149}, | |||
25 | {1203.18, 3349, 98, 91.1714, 32.8149}, | |||
26 | {1203.42, 3468, 98, 101.615, 38.0108}, | |||
27 | {1203.7, 3586, 98, 113.536, 43.9937}, | |||
28 | {1203.89, 3689, 98, 133.16, 54.975}, | |||
29 | {1204.12, 3784, 98, 154.744, 66.1321}, | |||
30 | {1204.34, 3872, 98, 176.571, 77.7658}, | |||
31 | {1204.55, 4004, 98, 199.558, 90.4851}, | |||
32 | {1204.79, 4107, 98, 215.496, 100.216}, | |||
33 | {1204.99, 4194, 98, 229.02, 109.666}, | |||
34 | {1205.21, 4317, 98, 235.284, 115.874}, | |||
35 | {1205.41, 4414, 98, 231.857, 118.075}, | |||
36 | {1205.62, 4527, 98, 233.976, 122.622}, | |||
37 | {1205.83, 4637, 98, 235.271, 126.771}, | |||
38 | {1206.03, 4753, 98, 235.78, 130.722}, | |||
39 | {1206.23, 4858, 98, 242.037, 137.697}, | |||
40 | {1206.4, 4963, 98, 249.119, 145.879}, | |||
41 | {1206.6, 5064, 98, 252.107, 151.227}, | |||
42 | {1206.78, 5150, 98, 255.635, 157.219}, | |||
43 | {1206.97, 5265, 98, 259.892, 163.614}, | |||
44 | {1207.17, 5395, 98, 262.793, 169.127}, | |||
45 | {1207.35, 5479, 98, 267.64, 176.252}, | |||
46 | {1207.54, 5593, 98, 269.124, 181.115}, | |||
47 | {1207.75, 5702, 98, 261.354, 179.872}, | |||
48 | {1207.96, 5839, 98, 260.866, 183.25}, | |||
49 | {1208.16, 5945, 98, 259.311, 186.145}, | |||
50 | {1208.36, 6039, 98, 258.369, 189.427}, | |||
51 | {1208.56, 6145, 98, 258.941, 193.729}, | |||
52 | {1208.75, 6243, 98, 258.176, 197.368}, | |||
53 | {1208.96, 6357, 98, 256.443, 199.949}, | |||
54 | {1209.15, 6451, 98, 260, 206.637}, | |||
55 | {1209.35, 6582, 98, 262.935, 212.898}, | |||
56 | {1209.53, 6681, 98, 267.457, 220.788}, | |||
57 | ||||
58 | // not tun | |||
59 | {1209.48, 6624, 29, 0, 0}, | |||
60 | {1209.68, 5624, 10, 0, 0}, | |||
61 | {1209.88, 4624, 18, 0, 0}, | |||
62 | ||||
63 | // run 2 | |||
64 | {1222.98, 2807, 98, 0, 0}, | |||
65 | {1223.4, 2927, 98, 132.644, 54.5234}, | |||
66 | {1223.76, 3014, 98, 132.644, 54.5234}, | |||
67 | {1224.11, 3140, 98, 100.35, 41.7268}, | |||
68 | {1224.41, 3241, 98, 100.35, 41.7268}, | |||
69 | {1224.7, 3363, 98, 96.5131, 40.8638}, | |||
70 | {1224.95, 3477, 98, 96.5131, 40.8638}, | |||
71 | {1225.19, 3574, 98, 99.2021, 42.8801}, | |||
72 | {1225.42, 3685, 98, 99.2021, 42.8801}, | |||
73 | {1225.64, 3789, 98, 102.104, 45.0223}, | |||
74 | {1225.86, 3894, 98, 102.104, 45.0223}, | |||
75 | {1226.07, 3984, 98, 114.109, 51.8489}, | |||
76 | {1226.28, 4077, 98, 131.139, 61.396}, | |||
77 | {1226.48, 4217, 98, 148.014, 72.3723}, | |||
78 | {1226.71, 4289, 98, 168.489, 84.4988}, | |||
79 | {1226.93, 4399, 98, 187.246, 96.2993}, | |||
80 | {1227.17, 4535, 98, 201.557, 106.14}, | |||
81 | {1227.36, 4630, 98, 222.198, 119.975}, | |||
82 | {1227.56, 4721, 98, 231.989, 128.398}, | |||
83 | {1227.76, 4844, 98, 234.202, 133.203}, | |||
84 | {1227.98, 4974, 98, 231.457, 135.188}, | |||
85 | {1228.17, 5085, 98, 239.914, 143.776}, | |||
86 | {1228.36, 5162, 98, 246.712, 151.547}, | |||
87 | {1228.54, 5294, 98, 257.228, 161.743}, | |||
88 | {1228.75, 5354, 98, 254.613, 163.828}, | |||
89 | {1229.01, 5531, 98, 249.888, 164.202}, | |||
90 | {1229.18, 5605, 98, 256.615, 172.838}, | |||
91 | {1229.35, 5678, 98, 264.986, 182.496}, | |||
92 | {1229.53, 5790, 98, 266.519, 187.736}, | |||
93 | {1229.74, 5893, 98, 262.636, 188.805}, | |||
94 | {1229.96, 5996, 98, 254.576, 186.738}, | |||
95 | {1230.18, 6112, 98, 252.638, 188.773}, | |||
96 | {1230.37, 6219, 98, 261.059, 198.656}, | |||
97 | {1230.56, 6304, 98, 255.356, 198.295}, | |||
98 | {1230.75, 6424, 98, 252.785, 200.4}, | |||
99 | {1230.97, 6507, 98, 252.785, 200.4}, | |||
100 | {1231.19, 6636, 98, 244.623, 197.995}, | |||
101 | {1231.4, 6737, 98, 245.47, 202.721}, | |||
102 | {1231.64, 6828, 98, 244.215, 205.326}, | |||
103 | {1231.88, 7011, 98, 244.972, 209.81}, | |||
104 | {1232.12, 7252, 98, 243.574, 213.126}, | |||
105 | }; | |||
106 | ||||
107 | 4 | TEST(DynoView, Base) { | ||
108 | ||||
109 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
110 | ||||
111 | 1 | DynoView dut; | ||
112 | ||||
113 | 1 | config->dynoRpmStep = 100; | ||
114 | ||||
115 | 1 | config->dynoSaeTemperatureC = 20; | ||
116 | 1 | config->dynoSaeBaro = STD_ATMOSPHERE; | ||
117 | 1 | config->dynoSaeRelativeHumidity = 80; | ||
118 | ||||
119 | 1 | config->dynoCarWheelDiaInch = 18; | ||
120 | 1 | config->dynoCarWheelTireWidthMm = 235; | ||
121 | 1 | config->dynoCarWheelAspectRatio = 40; | ||
122 | ||||
123 | 1 | config->dynoCarGearPrimaryReduction = 1; | ||
124 | 1 | config->dynoCarGearRatio = 1.160; | ||
125 | 1 | config->dynoCarGearFinalDrive = 5.358; | ||
126 | ||||
127 | 1 | config->dynoCarCarMassKg = 1413; | ||
128 | 1 | config->dynoCarCargoMassKg = 180; | ||
129 | 1 | config->dynoCarCoeffOfDrag = 0.29; | ||
130 | 1 | config->dynoCarFrontalAreaM2 = 1.8580608; | ||
131 | ||||
132 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::Tps1, 0); | |
133 |
1/1✓ Branch 1 taken 1 time.
|
1 | dut.update(); | |
134 | ||||
135 | 1 | auto lastTime = testData[0].time - 0.01; | ||
136 |
2/2✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1 time.
|
2/2✓ Decision 'true' taken 86 times.
✓ Decision 'false' taken 1 time.
|
87 | for (size_t i = 0; i < testData.size(); ++i) { |
137 | 86 | auto point = testData[i]; | ||
138 | ||||
139 | 86 | auto timeDiff = int((point.time - lastTime) * 1000); | ||
140 | 86 | lastTime = point.time; | ||
141 | ||||
142 |
1/1✓ Branch 1 taken 86 times.
|
86 | eth.moveTimeForwardMs(timeDiff); | |
143 |
1/1✓ Branch 1 taken 86 times.
|
86 | Sensor::setMockValue(SensorType::Rpm, point.rpm); | |
144 |
1/1✓ Branch 1 taken 86 times.
|
86 | Sensor::setMockValue(SensorType::Tps1, point.tps); | |
145 |
1/1✓ Branch 1 taken 86 times.
|
86 | dut.update(); | |
146 | ||||
147 | //std::cerr << "time:" << point.time << ", rpm: " << point.rpm << ", hp: " << dut.currentHP << ", Torque: " << dut.currentTorque << std::endl; | |||
148 | //std::cerr << "{" << point.time << ", " << point.rpm << ", " << point.tps << ", " << dut.currentTorque << ", " << dut.currentHP << "}," << std::endl; | |||
149 | ||||
150 |
3/8✓ Branch 2 taken 86 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 86 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 24 taken 86 times.
✗ Branch 25 not taken.
|
86 | ASSERT_NEAR(point.hp, dut.currentHP, 10); | |
151 |
3/8✓ Branch 2 taken 86 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 86 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 24 taken 86 times.
✗ Branch 25 not taken.
|
86 | ASSERT_NEAR(point.torque, dut.currentTorque, 10); | |
152 | } | |||
153 | 1 | } | ||
154 | ||||
155 | 4 | TEST(DynoView, SlowCallback) { | ||
156 | ||||
157 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
158 | ||||
159 | 1 | config->dynoRpmStep = 100; | ||
160 | ||||
161 | 1 | config->dynoSaeTemperatureC = 20; | ||
162 | 1 | config->dynoSaeBaro = STD_ATMOSPHERE; | ||
163 | 1 | config->dynoSaeRelativeHumidity = 80; | ||
164 | ||||
165 | 1 | config->dynoCarWheelDiaInch = 18; | ||
166 | 1 | config->dynoCarWheelTireWidthMm = 235; | ||
167 | 1 | config->dynoCarWheelAspectRatio = 40; | ||
168 | ||||
169 | 1 | config->dynoCarGearPrimaryReduction = 1; | ||
170 | 1 | config->dynoCarGearRatio = 1.160; | ||
171 | 1 | config->dynoCarGearFinalDrive = 5.358; | ||
172 | ||||
173 | 1 | config->dynoCarCarMassKg = 1413; | ||
174 | 1 | config->dynoCarCargoMassKg = 180; | ||
175 | 1 | config->dynoCarCoeffOfDrag = 0.29; | ||
176 | 1 | config->dynoCarFrontalAreaM2 = 1.8580608; | ||
177 | ||||
178 |
1/1✓ Branch 1 taken 1 time.
|
1 | Sensor::setMockValue(SensorType::Tps1, 0); | |
179 |
1/1✓ Branch 1 taken 1 time.
|
1 | engine->periodicSlowCallback(); | |
180 | ||||
181 | 1 | auto lastTime = testData[0].time - 0.01; | ||
182 |
2/2✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1 time.
|
2/2✓ Decision 'true' taken 86 times.
✓ Decision 'false' taken 1 time.
|
87 | for (size_t i = 0; i < testData.size(); ++i) { |
183 | 86 | auto point = testData[i]; | ||
184 | ||||
185 | 86 | auto timeDiff = int((point.time - lastTime) * 1000); | ||
186 | 86 | lastTime = point.time; | ||
187 | ||||
188 |
1/1✓ Branch 1 taken 86 times.
|
86 | eth.moveTimeForwardMs(timeDiff); | |
189 |
1/1✓ Branch 1 taken 86 times.
|
86 | Sensor::setMockValue(SensorType::Rpm, point.rpm); | |
190 |
1/1✓ Branch 1 taken 86 times.
|
86 | Sensor::setMockValue(SensorType::Tps1, point.tps); | |
191 | ||||
192 |
1/1✓ Branch 1 taken 86 times.
|
86 | engine->periodicSlowCallback(); | |
193 | ||||
194 |
1/1✓ Branch 1 taken 86 times.
|
86 | auto currentHP = getDynoviewHP(); | |
195 |
1/1✓ Branch 1 taken 86 times.
|
86 | auto currentTorque = getDynoviewTorque(); | |
196 | // std::cerr << "rpm: " << point.rpm << ", hp: " << currentHP << ", Torque: " << currentTorque << std::endl; | |||
197 | ||||
198 |
3/8✓ Branch 2 taken 86 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 86 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 24 taken 86 times.
✗ Branch 25 not taken.
|
86 | ASSERT_NEAR(point.hp, currentHP, 10); | |
199 |
3/8✓ Branch 2 taken 86 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 86 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 24 taken 86 times.
✗ Branch 25 not taken.
|
86 | ASSERT_NEAR(point.torque, currentTorque, 10); | |
200 | } | |||
201 | 1 | } | ||
202 | ||||
203 | ||||
204 |