swift
Loading...
Searching...
No Matches
testphysicalquantities.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
7
8#include <QString>
9#include <QTest>
10#include <QtGlobal>
11
12#include "test.h"
13
14#include "misc/math/mathutils.h"
16#include "misc/pq/angle.h"
17#include "misc/pq/constants.h"
18#include "misc/pq/frequency.h"
19#include "misc/pq/length.h"
20#include "misc/pq/literals.h"
21#include "misc/pq/mass.h"
24#include "misc/pq/pqstring.h"
25#include "misc/pq/pressure.h"
26#include "misc/pq/speed.h"
27#include "misc/pq/temperature.h"
28#include "misc/pq/time.h"
29#include "misc/pq/units.h"
30#include "misc/variant.h"
31
32using namespace swift::misc::physical_quantities;
33using namespace swift::misc::math;
34
35namespace MiscTest
36{
39 {
41
42 private slots:
44 void unitsBasics();
45
47 void lengthBasics();
48
50 void speedBasics();
51
53 void frequencyTests();
54
56 void angleTests();
57
59 void massTests();
60
62 void pressureTests();
63
65 void temperatureTests();
66
68 void timeTests();
69
71 void accelerationTests();
72
74 void memoryTests();
75
77 void parserTests();
78
80 void basicArithmetic();
81
83 void literalsTest();
84 };
85
86 void CTestPhysicalQuantities::unitsBasics()
87 {
88 // some tests on units
89 CLengthUnit du1 = CLengthUnit::m(); // Copy
90 CLengthUnit du2 = CLengthUnit::m(); // Copy
91 QVERIFY2(du1 == du2, "Compare by value 1");
92 du1 = CLengthUnit::m(); // Copy
93 du2 = CLengthUnit::m(); // Copy
94 QVERIFY2(du1 == du2, "Compare by value 2");
95 QVERIFY2(CLengthUnit::m() == CLengthUnit::m(), "Compare by value");
96
98 QVERIFY2(fu1 != du1, "Hz must not be meter");
99
100 // Unary expressions
102 QVERIFY2(-temp1 == CTemperature(-5, CTemperatureUnit::C()), "Temperatures must be the same");
103 CTemperature temp2(-8.7, CTemperatureUnit::K());
104 QVERIFY2(-temp2 == CTemperature(8.7, CTemperatureUnit::K()), "Temperatures must be the same");
105
106 // null comparisons
107 const CLength null(CLength::null());
108 const CLength nonNull(1, CLengthUnit::m());
109 QVERIFY2(null == CLength::null(), "null is equal to null");
110 QVERIFY2(!(null < CLength::null()), "null is equivalent to null");
111 QVERIFY2(null != nonNull, "null is not equal to non-null");
112 QVERIFY2((null < nonNull) != (null > nonNull), "null is ordered wrt non-null");
113 }
114
115 void CTestPhysicalQuantities::lengthBasics()
116 {
117 CLength d1(1, CLengthUnit::m()); // 1m
118 CLength d2(100, CLengthUnit::cm());
119 CLength d3(1.852 * 1000, CLengthUnit::m()); // 1852m
120 CLength d4(1, CLengthUnit::NM());
121 QVERIFY2(d1 == d2, "1meter shall be 100cm");
122 QVERIFY2(d3 == d4, "1852meters shall be 1NM");
123 QVERIFY2(d1 * 2 == 2 * d1, "Commutative multiplication");
124
125 d3 *= 2; // SI value
126 d4 *= 2.0; // SI value !
127 QVERIFY2(d3 == d4, "2*1852meters shall be 2NM");
128
129 // less / greater
130 QVERIFY2(!(d1 < d2), "Nothing shall be less / greater");
131 QVERIFY2(!(d1 > d2), "Nothing shall be less / greater");
132
133 // epsilon tests
134 d1 = d2; // both in same unit
135 d1.addValueSameUnit(d1.getUnit().getEpsilon() / 2.0); // this should be still the same
136 QVERIFY2(d1 == d2, "Epsilon: 100cm + epsilon shall be 100cm");
137 QVERIFY2(!(d1 != d2), "Epsilon: 100cm + epsilon shall be still 100cm");
138 QVERIFY2(!(d1 > d2), "d1 shall not be greater");
139
140 d1.addValueSameUnit(d1.getUnit().getEpsilon()); // now over epsilon threshold
141 QVERIFY2(d1 != d2, "Epsilon exceeded: 100 cm + 2 epsilon shall not be 100cm");
142 QVERIFY2(d1 > d2, "d1 shall be greater");
143 }
144
145 void CTestPhysicalQuantities::speedBasics()
146 {
147 CSpeed s1(100, CSpeedUnit::km_h());
148 CSpeed s2(1000, CSpeedUnit::ft_min());
149 QVERIFY2(CMathUtils::epsilonEqual(s1.valueRounded(CSpeedUnit::NM_h(), 0), 54),
150 qPrintable(QStringLiteral("100km/h is not %1 NM/h").arg(s1.valueRounded(CSpeedUnit::NM_h(), 0))));
151 QVERIFY2(CMathUtils::epsilonEqual(s2.valueRounded(CSpeedUnit::m_s(), 1), 5.1),
152 qPrintable(QStringLiteral("1000ft/min is not %1 m/s").arg(s2.valueRounded(CSpeedUnit::m_s(), 1))));
153 }
154
155 void CTestPhysicalQuantities::frequencyTests()
156 {
157 CFrequency f1(1, CFrequencyUnit::MHz());
158 QCOMPARE(f1.valueRounded(CFrequencyUnit::kHz(), 2), 1000.0); // "Mega is 1000kHz
159 QCOMPARE(f1.value(), 1.0); // 1MHz
160 QCOMPARE(f1.value(CFrequencyUnit::defaultUnit()), 1000000.0); // 1E6 Hz
161 CFrequency f2(1e+6, CFrequencyUnit::Hz()); // 1 Megahertz
162 QVERIFY2(f1 == f2, "MHz is 1E6 Hz");
163 }
164
165 void CTestPhysicalQuantities::angleTests()
166 {
167 CAngle a1(180, CAngleUnit::deg());
168 CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad());
169 CAngle a3(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666
170 CAngle a4(35.436, CAngleUnit::sexagesimalDegMin()); // 35.72666
171 CAngle a5(-60.3015, CAngleUnit::sexagesimalDeg()); // negative angles = west longitude or south latitude
172 a2.switchUnit(CAngleUnit::deg());
173 QVERIFY2(CMathUtils::epsilonEqual(a1.piFactor(), 1.00),
174 qPrintable(QStringLiteral("Pi should be 1PI, not %1").arg(a1.piFactor())));
175 QVERIFY2(CMathUtils::epsilonEqual(a3.valueRounded(CAngleUnit::deg()), 35.73), "Expecting 35.73");
176 QVERIFY2(CMathUtils::epsilonEqual(a4.valueRounded(CAngleUnit::deg()), 35.73), "Expecting 35.73");
177 QVERIFY2(CMathUtils::epsilonEqual(a5.valueRounded(CAngleUnit::deg(), 4), -60.5042), "Expecting -60.5042");
178
179 // issue #552
180 CAngle a6(48.07063588, CAngleUnit::sexagesimalDeg());
181 CAngle a7(a6);
182 a7.switchUnit(CAngleUnit::rad());
183 QVERIFY2(
185 "Conversion via radians yields same answer");
186 CAngle a8(48.07063588, CAngleUnit::sexagesimalDegMin());
187 CAngle a9(a8);
188 a9.switchUnit(CAngleUnit::rad());
191 "Conversion via radians yields same answer");
192 }
193
194 void CTestPhysicalQuantities::massTests()
195 {
196 CMass w1(1000, CMassUnit::kg());
197 CMass w2(w1.value(), CMassUnit::kg());
198 w2.switchUnit(CMassUnit::tonne());
199 QCOMPARE(w2.value(), 1.0); // 1tonne shall be 1000kg
200 w2.switchUnit(CMassUnit::lb());
201 QVERIFY2(CMathUtils::epsilonEqual(w2.valueRounded(2), 2204.62), "1tonne shall be 2204pounds");
202 QVERIFY2(w1 == w2, "Masses shall be equal");
203 }
204
205 void CTestPhysicalQuantities::pressureTests()
206 {
208 const CPressure p2(29.92, CPressureUnit::inHg());
209 CPressure p4(p1);
210 p4.switchUnit(CPressureUnit::mbar());
211
212 // does not match exactly
213 QVERIFY2(p1 != p2, "Standard pressure test little difference");
214 QCOMPARE(p1.value(), p4.value()); // mbar/hPa test
215
216 // Unit substract test
217 const CPressure seaLevelPressure(918.0, CPressureUnit::mbar());
218 const CPressure standardPressure(1013.2, CPressureUnit::mbar());
219 const CPressure delta = (standardPressure - seaLevelPressure);
220 const double expected = 95.2;
221 const double deltaV = delta.value(CPressureUnit::mbar());
222 QCOMPARE(deltaV, expected);
223 }
224
225 void CTestPhysicalQuantities::temperatureTests()
226 {
227 CTemperature t1(0, CTemperatureUnit::C()); // 0C
228 CTemperature t2(1, CTemperatureUnit::F()); // 1F
229 CTemperature t3(220.15, CTemperatureUnit::F());
230 CTemperature t4(10, CTemperatureUnit::F());
231 QVERIFY2(
232 CMathUtils::epsilonEqual(t1.valueRounded(CTemperatureUnit::K()), 273.15),
233 qPrintable(QStringLiteral("0C shall be 273.15K, not %1 K").arg(t1.valueRounded(CTemperatureUnit::K()))));
234 QVERIFY2(
235 CMathUtils::epsilonEqual(t2.valueRounded(CTemperatureUnit::C()), -17.22),
236 qPrintable(QStringLiteral("1F shall be -17.22C, not %1 C").arg(t2.valueRounded(CTemperatureUnit::C()))));
237 QVERIFY2(CMathUtils::epsilonEqual(t3.valueRounded(CTemperatureUnit::C()), 104.53),
238 qPrintable(
239 QStringLiteral("220.15F shall be 104.53C, not %1 C").arg(t3.valueRounded(CTemperatureUnit::C()))));
240 QVERIFY2(
241 CMathUtils::epsilonEqual(t4.valueRounded(CTemperatureUnit::K()), 260.93),
242 qPrintable(QStringLiteral("10F shall be 260.93K, not %1 K").arg(t4.valueRounded(CTemperatureUnit::K()))));
243 }
244
245 void CTestPhysicalQuantities::timeTests()
246 {
247 CTime t1(1, CTimeUnit::h());
248 CTime t2(1.5, CTimeUnit::h());
249 CTime t3(1.25, CTimeUnit::min());
250 CTime t4(1.0101, CTimeUnit::hms());
251 CTime t5(26, 35, 40);
252 CTime t6(3661, CTimeUnit::s());
253 CTime t7;
254 QVERIFY2(CMathUtils::epsilonEqual(t1.value(CTimeUnit::defaultUnit()), 3600), "1hour shall be 3600s");
255 QVERIFY2(CMathUtils::epsilonEqual(t2.value(CTimeUnit::hrmin()), 1.3), "1.5hour shall be 1h30m");
256 QVERIFY2(CMathUtils::epsilonEqual(t3.value(CTimeUnit::minsec()), 1.15), "1.25min shall be 1m15s");
257 QVERIFY2(CMathUtils::epsilonEqual(t4.value(CTimeUnit::s()), 3661), "1h01m01s shall be 3661s");
258 QVERIFY2(CMathUtils::epsilonEqual(t5.value(CTimeUnit::s()), 95740), "Time greater than 24h failed");
259 QVERIFY2(t6.formattedHrsMinSec() == "01:01:01", "Formatted output hh:mm:ss failed");
260 QVERIFY2(t6.formattedHrsMin() == "01:01", "Formatted output hh:mm failed");
261 t6.switchUnit(CTimeUnit::hms());
262 QVERIFY2(CMathUtils::epsilonEqual(t6.value(), 1.0101), "Switching the unit produced a wrong a value");
263 t7.parseFromString("27:30:55");
264 QVERIFY2(t7.formattedHrsMinSec() == "27:30:55", "Parsed time greater than 24h failed");
265
266 CTime t8(7680, CTimeUnit::s());
267 t8.switchUnit(CTimeUnit::hrmin());
268 qDebug() << t8.valueRoundedWithUnit();
269 QVERIFY2(t8.valueRoundedWithUnit() == "02h08.0m", "valueRoundedWithUnit in hrmin correctly formatted");
270 }
271
272 void CTestPhysicalQuantities::accelerationTests()
273 {
274 CLength oneMeter(1, CLengthUnit::m());
275 double ftFactor = oneMeter.switchUnit(CLengthUnit::ft()).value();
276
277 CAcceleration a1(10.0, CAccelerationUnit::m_s2());
278 CAcceleration a2(a1);
279 a1.switchUnit(CAccelerationUnit::ft_s2());
280 QVERIFY2(a1 == a2, "Accelerations should be similar");
282 a1.valueRounded(6)),
283 "Numerical values should be equal");
284 }
285
286 void CTestPhysicalQuantities::memoryTests()
287 {
288 auto c = new CLength(100, CLengthUnit::m());
289 c->switchUnit(CLengthUnit::NM());
291 "Testing distance units failed");
292 delete c;
293
294 auto a = new CAngle(100, CAngleUnit::rad());
295 a->switchUnit(CAngleUnit::deg());
297 "Testing angle units failed");
298 delete a;
299 }
300
301 void CTestPhysicalQuantities::parserTests()
302 {
303 QVERIFY2(CLength(33.0, CLengthUnit::ft()) == CLength("33.0 ft"), "Length");
304 QVERIFY2(CLength(33.0, CLengthUnit::ft()) != CLength("33.1 ft"), "Length !=");
305 QVERIFY2(CLength(-22.8, CLengthUnit::ft()) != CLength("-22.8 cm"), "Length !=");
306 QVERIFY2(CSpeed(123.45, CSpeedUnit::km_h()) == CSpeed("123.45km/h"), "Speed");
307 QVERIFY2(CMass(33.45, CMassUnit::kg()) == CMass("33.45000 kg"), "CMass");
308
309 // parsing via variant
310 auto parsedPq1 = CPqString::parseToVariant("100.123 km/h").value<CSpeed>();
311 QVERIFY2(CSpeed(100.123, CSpeedUnit::km_h()) == parsedPq1, "Parsed speed via variant");
312
313 auto parsedPq2 = CPqString::parseToVariant("-33.123ft").value<CLength>();
314 QVERIFY2(CLength(-33.123, CLengthUnit::ft()) == parsedPq2, "Parsed length via variant");
315
316 auto parsedPq3 = CPqString::parse<CFrequency>("122.8MHz");
317 QVERIFY2(CFrequency(122.8, CFrequencyUnit::MHz()) == parsedPq3, "Parsed frequency via variant");
318 }
319
320 void CTestPhysicalQuantities::basicArithmetic()
321 {
322 // pressure
324 CPressure p2(p1);
325 p2 *= 2.0;
326 CPressure p3 = p1 + p1;
327 QVERIFY2(p3 == p2, "Pressure needs to be the same (2times)");
328 p3 /= 2.0;
329 QVERIFY2(p3 == p1, "Pressure needs to be the same (1time)");
330 p3 = p3 - p3;
331 QCOMPARE(p3.value() + 1, 1.0); // Value needs to be zero
332 p3 = CPressure(1013, CPressureUnit::hPa());
333 QVERIFY2(p3 * 1.5 == 1.5 * p3, "Basic commutative test on PQ failed");
334
335 // the time clasas
336 CTime time1;
337 time1.parseFromString("11:30"); // hhmm
338
339 CTime time2;
340 time2.parseFromString("-11:30"); // hhmm
341
342 CTime time3 = time1 + time2;
343 QVERIFY2(time3.isZeroEpsilonConsidered(), "Time must be 0");
344
345 // angle
346 CAngle a1(180, CAngleUnit::deg());
347 CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad());
348 a1 += a2;
349 QVERIFY2(a1.valueInteger(CAngleUnit::deg()) == 450, "Expect 450 degrees");
350 }
351
352 void CTestPhysicalQuantities::literalsTest()
353 {
354 using namespace swift::misc::physical_quantities::Literals;
355
356 // Acceleration
357 QVERIFY2(12.5_ft_s2 == CAcceleration(12.5, CAccelerationUnit::ft_s2()), "Acceleration needs to be the same");
358 QVERIFY2(5.7_m_s2 == CAcceleration(5.7, CAccelerationUnit::m_s2()), "Acceleration needs to be the same");
359 QVERIFY2(48_ft_s2 == CAcceleration(48, CAccelerationUnit::ft_s2()), "Acceleration needs to be the same");
360 QVERIFY2(39_m_s2 == CAcceleration(39, CAccelerationUnit::m_s2()), "Acceleration needs to be the same");
361
362 // Angle
363 QVERIFY2(179.7_deg == CAngle(179.7, CAngleUnit::deg()), "Angle needs to be the same");
364 QVERIFY2(1.1_rad == CAngle(1.1, CAngleUnit::rad()), "Angle needs to be the same");
365 QVERIFY2(180_deg == CAngle(180, CAngleUnit::deg()), "Angle needs to be the same");
366 QVERIFY2(1_rad == CAngle(1, CAngleUnit::rad()), "Angle needs to be the same");
367
368 // Frequency
369 QVERIFY2(500.7_Hz == CFrequency(500.7, CFrequencyUnit::Hz()), "Frequency needs to be the same");
370 QVERIFY2(99.7_kHz == CFrequency(99.7, CFrequencyUnit::kHz()), "Frequency needs to be the same");
371 QVERIFY2(122.8_MHz == CFrequency(122.8, CFrequencyUnit::MHz()), "Frequency needs to be the same");
372 QVERIFY2(4.1_GHz == CFrequency(4.1, CFrequencyUnit::GHz()), "Frequency needs to be the same");
373 QVERIFY2(3000_Hz == CFrequency(3000, CFrequencyUnit::Hz()), "Frequency needs to be the same");
374 QVERIFY2(122_kHz == CFrequency(122, CFrequencyUnit::kHz()), "Frequency needs to be the same");
375 QVERIFY2(1333_MHz == CFrequency(1333, CFrequencyUnit::MHz()), "Frequency needs to be the same");
376 QVERIFY2(5_GHz == CFrequency(5, CFrequencyUnit::GHz()), "Frequency needs to be the same");
377
378 // Length
379 QVERIFY2(79.24_m == CLength(79.24, CLengthUnit::m()), "Length needs to be the same");
380 QVERIFY2(1024.2_NM == CLength(1024.2, CLengthUnit::NM()), "Length needs to be the same");
381 QVERIFY2(78.1_SM == CLength(78.1, CLengthUnit::SM()), "Length needs to be the same");
382 QVERIFY2(99.9_cm == CLength(99.9, CLengthUnit::cm()), "Length needs to be the same");
383 QVERIFY2(147.2_ft == CLength(147.2, CLengthUnit::ft()), "Length needs to be the same");
384 QVERIFY2(450.4_km == CLength(450.4, CLengthUnit::km()), "Length needs to be the same");
385 QVERIFY2(136.2_mi == CLength(136.2, CLengthUnit::mi()), "Length needs to be the same");
386 QVERIFY2(100_m == CLength(100, CLengthUnit::m()), "Length needs to be the same");
387 QVERIFY2(320_NM == CLength(320, CLengthUnit::NM()), "Length needs to be the same");
388 QVERIFY2(145_SM == CLength(145, CLengthUnit::SM()), "Length needs to be the same");
389 QVERIFY2(200_cm == CLength(200, CLengthUnit::cm()), "Length needs to be the same");
390 QVERIFY2(38000_ft == CLength(38000, CLengthUnit::ft()), "Length needs to be the same");
391 QVERIFY2(100_km == CLength(100, CLengthUnit::km()), "Length needs to be the same");
392 QVERIFY2(78_mi == CLength(78, CLengthUnit::mi()), "Length needs to be the same");
393
394 // Mass
395 QVERIFY2(142.1_g == CMass(142.1, CMassUnit::g()), "Mass needs to be the same");
396 QVERIFY2(2048.123_kg == CMass(2048.123, CMassUnit::kg()), "Mass needs to be the same");
397 QVERIFY2(8.2_lb == CMass(8.2, CMassUnit::lb()), "Mass needs to be the same");
398 QVERIFY2(60.5_tonne == CMass(60.5, CMassUnit::tonne()), "Mass needs to be the same");
399 QVERIFY2(45.3_shortTon == CMass(45.3, CMassUnit::shortTon()), "Mass needs to be the same");
400 QVERIFY2(100_g == CMass(100, CMassUnit::g()), "Mass needs to be the same");
401 QVERIFY2(2048_kg == CMass(2048, CMassUnit::kg()), "Mass needs to be the same");
402 QVERIFY2(100_lb == CMass(100, CMassUnit::lb()), "Mass needs to be the same");
403 QVERIFY2(30_tonne == CMass(30, CMassUnit::tonne()), "Mass needs to be the same");
404 QVERIFY2(10_shortTon == CMass(10, CMassUnit::shortTon()), "Mass needs to be the same");
405
406 // Pressure
407 QVERIFY2(36.111_Pa == CPressure(36.111, CPressureUnit::Pa()), "Pressure needs to be the same");
408 QVERIFY2(45.4_bar == CPressure(45.4, CPressureUnit::bar()), "Pressure needs to be the same");
409 QVERIFY2(67.8_hPa == CPressure(67.8, CPressureUnit::hPa()), "Pressure needs to be the same");
410 QVERIFY2(129.2_psi == CPressure(129.2, CPressureUnit::psi()), "Pressure needs to be the same");
411 QVERIFY2(20.2_inHg == CPressure(20.2, CPressureUnit::inHg()), "Pressure needs to be the same");
412 QVERIFY2(1013.13_mbar == CPressure(1013.13, CPressureUnit::mbar()), "Pressure needs to be the same");
413 QVERIFY2(22.92_mmHg == CPressure(22.92, CPressureUnit::mmHg()), "Pressure needs to be the same");
414 QVERIFY2(40_Pa == CPressure(40, CPressureUnit::Pa()), "Pressure needs to be the same");
415 QVERIFY2(16_bar == CPressure(16, CPressureUnit::bar()), "Pressure needs to be the same");
416 QVERIFY2(67_hPa == CPressure(67, CPressureUnit::hPa()), "Pressure needs to be the same");
417 QVERIFY2(129_psi == CPressure(129, CPressureUnit::psi()), "Pressure needs to be the same");
418 QVERIFY2(20_inHg == CPressure(20, CPressureUnit::inHg()), "Pressure needs to be the same");
419 QVERIFY2(1013_mbar == CPressure(1013, CPressureUnit::mbar()), "Pressure needs to be the same");
420 QVERIFY2(22_mmHg == CPressure(22, CPressureUnit::mmHg()), "Pressure needs to be the same");
421
422 // Speed
423 QVERIFY2(450.2_kts == CSpeed(450.2, CSpeedUnit::kts()), "Speed needs to be the same");
424 QVERIFY2(5.7_m_s == CSpeed(5.7, CSpeedUnit::m_s()), "Speed needs to be the same");
425 QVERIFY2(470.1_NM_h == CSpeed(470.1, CSpeedUnit::NM_h()), "Speed needs to be the same");
426 QVERIFY2(20.45_ft_s == CSpeed(20.45, CSpeedUnit::ft_s()), "Speed needs to be the same");
427 QVERIFY2(115.16_km_h == CSpeed(115.16, CSpeedUnit::km_h()), "Speed needs to be the same");
428 QVERIFY2(160.5_ft_min == CSpeed(160.5, CSpeedUnit::ft_min()), "Speed needs to be the same");
429 QVERIFY2(1020_kts == CSpeed(1020, CSpeedUnit::kts()), "Speed needs to be the same");
430 QVERIFY2(20_m_s == CSpeed(20, CSpeedUnit::m_s()), "Speed needs to be the same");
431 QVERIFY2(500_NM_h == CSpeed(500, CSpeedUnit::NM_h()), "Speed needs to be the same");
432 QVERIFY2(400_ft_s == CSpeed(400, CSpeedUnit::ft_s()), "Speed needs to be the same");
433 QVERIFY2(161_km_h == CSpeed(161, CSpeedUnit::km_h()), "Speed needs to be the same");
434 QVERIFY2(4000_ft_min == CSpeed(4000, CSpeedUnit::ft_min()), "Speed needs to be the same");
435
436 // Temperature
437 QVERIFY2(-15.2_degC == CTemperature(-15.2, CTemperatureUnit::C()), "Temperature needs to be the same");
438 QVERIFY2(68.1_degF == CTemperature(68.1, CTemperatureUnit::F()), "Temperature needs to be the same");
439 QVERIFY2(232.2_degK == CTemperature(232.2, CTemperatureUnit::K()), "Temperature needs to be the same");
440 QVERIFY2(35_degC == CTemperature(35, CTemperatureUnit::C()), "Temperature needs to be the same");
441 QVERIFY2(-20_degF == CTemperature(-20, CTemperatureUnit::F()), "Temperature needs to be the same");
442 QVERIFY2(140_degK == CTemperature(140, CTemperatureUnit::K()), "Temperature needs to be the same");
443 }
444} // namespace MiscTest
445
448
449#include "testphysicalquantities.moc"
450
static const double & PI()
PI as convenience method.
Definition angle.cpp:74
static CAngleUnit sexagesimalDegMin()
Sexagesimal degree (degrees, minutes, decimal minutes).
Definition units.h:294
static CAngleUnit rad()
Radians.
Definition units.h:268
static CAngleUnit deg()
Degrees.
Definition units.h:276
static CAngleUnit sexagesimalDeg()
Sexagesimal degree (degrees, minutes, seconds, decimal seconds).
Definition units.h:285
static CAngleUnit defaultUnit()
Default unit.
Definition units.h:254
static CFrequencyUnit Hz()
Hertz.
Definition units.h:363
static CFrequencyUnit MHz()
Megahertz.
Definition units.h:380
static CFrequencyUnit defaultUnit()
Default unit.
Definition units.h:353
static CFrequencyUnit kHz()
Kilohertz.
Definition units.h:371
static CFrequencyUnit GHz()
Gigahertz.
Definition units.h:389
Physical quantities, basic tests.
T value() const
Return the value converted to the type T.
Definition variant.h:154
static bool epsilonEqual(float v1, float v2, float epsilon=1E-06f)
Epsilon safe equal.
Definition mathutils.cpp:51
static double round(double value, int digits)
Utility round method.
Definition mathutils.cpp:18
static CAccelerationUnit ft_s2()
Feet/second^2.
Definition units.h:1080
static CAccelerationUnit m_s2()
Meter/second^2 (m/s^2).
Definition units.h:1071
Specialized class for frequency (hertz, mega hertz, kilo hertz).
Definition units.h:334
Physical unit length (length).
Definition length.h:18
Specialized class for distance units (meter, foot, nautical miles).
Definition units.h:95
static CLengthUnit km()
Kilometer km.
Definition units.h:165
static CLengthUnit m()
Meter m.
Definition units.h:140
static CLengthUnit SM()
Statute mile.
Definition units.h:190
static CLengthUnit NM()
Nautical miles NM.
Definition units.h:148
static CLengthUnit ft()
Foot ft.
Definition units.h:157
static CLengthUnit mi()
International mile.
Definition units.h:182
static CLengthUnit defaultUnit()
Default unit.
Definition units.h:130
static CLengthUnit cm()
Centimeter cm.
Definition units.h:173
static CMassUnit tonne()
Tonne, aka metric ton (1000kg).
Definition units.h:478
static CMassUnit shortTon()
Short ton (2000lb) used in the United States.
Definition units.h:486
static CMassUnit g()
Gram, SI unit.
Definition units.h:470
static CMassUnit lb()
Pound, aka mass pound.
Definition units.h:495
static CMassUnit kg()
Kilogram, SI base unit.
Definition units.h:462
static const CPressure & ISASeaLevelPressure()
International Standard Atmosphere pressure at mean sea level, 1013.25hPa.
Definition constants.h:22
double value(MU unit) const
Value in given unit.
bool isZeroEpsilonConsidered() const
Quantity value <= epsilon.
static CVariant parseToVariant(const QString &value, SeparatorMode mode=SeparatorQtDefault)
Parse a string value like "100m", "10.3Mhz".
Definition pqstring.cpp:28
static PQ parse(const QString &value, SeparatorMode mode=SeparatorQtDefault)
Parse into concrete type.
Definition pqstring.h:58
static CPressureUnit mbar()
Millibar, actually the same as hPa.
Definition units.h:609
static CPressureUnit mmHg()
Millimeter of mercury.
Definition units.h:627
static CPressureUnit Pa()
Pascal.
Definition units.h:575
static CPressureUnit inHg()
Inch of mercury at 0°C.
Definition units.h:618
static CPressureUnit psi()
Pounds per square inch.
Definition units.h:592
static CPressureUnit hPa()
Hectopascal.
Definition units.h:583
static CSpeedUnit NM_h()
Nautical miles per hour NM/h (same as kts).
Definition units.h:825
static CSpeedUnit ft_s()
Feet/second ft/s.
Definition units.h:834
static CSpeedUnit ft_min()
Feet/min ft/min.
Definition units.h:843
static CSpeedUnit km_h()
Kilometer/hour km/h.
Definition units.h:852
static CSpeedUnit m_s()
Meter/second m/s.
Definition units.h:808
static CSpeedUnit kts()
Knots.
Definition units.h:817
static CTemperatureUnit C()
Centigrade C.
Definition units.h:715
static CTemperatureUnit K()
Kelvin.
Definition units.h:707
static CTemperatureUnit F()
Fahrenheit F.
Definition units.h:724
void parseFromString(const QString &time)
From string hh:mm, or hh:mm:ss, or time units such as s, min.
Definition time.cpp:48
QString formattedHrsMinSec() const
Formatted as hh:mm:ss.
Definition time.cpp:132
static CTimeUnit min()
Minute.
Definition units.h:963
static CTimeUnit defaultUnit()
Default unit.
Definition units.h:924
static CTimeUnit hrmin()
Hours, minutes.
Definition units.h:989
static CTimeUnit hms()
Hours, minutes, seconds.
Definition units.h:980
static CTimeUnit s()
Second s.
Definition units.h:938
static CTimeUnit minsec()
Minutes, seconds.
Definition units.h:998
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QCOMPARE(actual, expected)
QVERIFY2(condition, message)
#define SWIFTTEST_APPLESS_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject without instantiating a QApplicati...
Definition test.h:39