mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-11 12:15:36 +08:00
Changed PQ to template, removed unit default values, checked unit tests
This commit is contained in:
@@ -37,9 +37,9 @@ void TestPhysicalQuantitiesBase::unitsBasics()
|
||||
*/
|
||||
void TestPhysicalQuantitiesBase::distanceBasics()
|
||||
{
|
||||
CDistance d1(1); // 1m
|
||||
CDistance d1(1,CDistanceUnit::m()); // 1m
|
||||
CDistance d2(100, CDistanceUnit::cm());
|
||||
CDistance d3(1.852 * 1000); // 1852m
|
||||
CDistance d3(1.852 * 1000,CDistanceUnit::m()); // 1852m
|
||||
CDistance d4(1,CDistanceUnit::NM());
|
||||
|
||||
QVERIFY2(d1 == d2, "1meter shall be 100cm");
|
||||
@@ -54,11 +54,11 @@ void TestPhysicalQuantitiesBase::distanceBasics()
|
||||
QVERIFY2(!(d1 > d2), "Nothing shall be less / greater");
|
||||
|
||||
// epsilon tests
|
||||
d1 += d1.getUnit().getEpsilon(); // this should be still the same
|
||||
d1.addUnitValue(d1.getUnit().getEpsilon()); // this should be still the same
|
||||
QVERIFY2(d1 == d2, "Epsilon: 1meter+epsilon shall be 100cm");
|
||||
QVERIFY2(!(d1 != d2), "Epsilon: 1meter+epsilon shall be 100cm");
|
||||
|
||||
d1 += d1.getUnit().getEpsilon(); // now over epsilon threshold
|
||||
d1.addUnitValue(d1.getUnit().getEpsilon()); // now over epsilon threshold
|
||||
QVERIFY2(d1 != d2, "Epsilon exceeded: 1meter+2epsilon shall not be 100cm");
|
||||
QVERIFY2(d1 > d2, "d1 shall be greater");
|
||||
}
|
||||
@@ -82,7 +82,7 @@ void TestPhysicalQuantitiesBase::frequencyTests()
|
||||
CFrequency f1(1, CFrequencyUnit::MHz());
|
||||
QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(),2) == 1000, "Mega is 1000kHz");
|
||||
QVERIFY2(f1 == 1000000 , "MHz is 1E6 Hz");
|
||||
CFrequency f2 = CMeasurementPrefix::M(); // 1 Megahertz
|
||||
CFrequency f2(CMeasurementPrefix::M(),CFrequencyUnit::Hz()) ; // 1 Megahertz
|
||||
QVERIFY2(f1 == f2 , "MHz is 1E6 Hz");
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ void TestPhysicalQuantitiesBase::frequencyTests()
|
||||
void TestPhysicalQuantitiesBase::angleTests()
|
||||
{
|
||||
CAngle a1(180, CAngleUnit::deg());
|
||||
CAngle a2(1.5 * CAngle::pi());
|
||||
CAngle a2(1.5 * CAngle::pi(), CAngleUnit::rad());
|
||||
a2.switchUnit(CAngleUnit::deg());
|
||||
QVERIFY2(a2.unitValueToInteger() == 270, qPrintable(QString("1.5Pi should be 270deg, not %1 deg").arg(a2.unitValueToInteger())));
|
||||
QVERIFY2(a1.piFactor() == 1, qPrintable(QString("Pi should be 1PI,not %1").arg(a1.piFactor())));
|
||||
@@ -103,8 +103,8 @@ void TestPhysicalQuantitiesBase::angleTests()
|
||||
*/
|
||||
void TestPhysicalQuantitiesBase::massTests()
|
||||
{
|
||||
CMass w1(1000);
|
||||
CMass w2(w1);
|
||||
CMass w1(1000, CMassUnit::kg());
|
||||
CMass w2(w1, CMassUnit::kg());
|
||||
w2.switchUnit(CMassUnit::t());
|
||||
QVERIFY2(w2.unitValueToInteger() == 1, "1tonne shall be 1000kg");
|
||||
w2.switchUnit(CMassUnit::lb());
|
||||
@@ -140,25 +140,41 @@ void TestPhysicalQuantitiesBase::temperatureTests()
|
||||
QVERIFY2(t1.convertedSiValueToDoubleRounded() == 273.15, qPrintable(QString("0C shall be 273.15K, not %1 K").arg(t1.convertedSiValueToDoubleRounded())));
|
||||
QVERIFY2(t2.valueRounded(CTemperatureUnit::C()) == -17.22, qPrintable(QString("1F shall be -17.22C, not %1 C").arg(t2.valueRounded(CTemperatureUnit::C()))));
|
||||
QVERIFY2(t3.valueRounded(CTemperatureUnit::C()) == 104.53, qPrintable(QString("220.15F shall be 104.53C, not %1 C").arg(t3.valueRounded(CTemperatureUnit::C()))));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Just tesing obvious memory create / destruct flaws
|
||||
* @brief Just testing obvious memory create / destruct flaws
|
||||
*/
|
||||
void TestPhysicalQuantitiesBase::memoryTests()
|
||||
{
|
||||
CDistance* c = new CDistance(100);
|
||||
CDistance* c = new CDistance(100, CDistanceUnit::m());
|
||||
c->switchUnit(CDistanceUnit::NM());
|
||||
QVERIFY2(c->getUnit() == CDistanceUnit::NM() && c->getConversionSiUnit() == CDistanceUnit::m(),
|
||||
"Testing distance units failed");
|
||||
delete c;
|
||||
|
||||
CAngle* a = new CAngle(100);
|
||||
CAngle* a = new CAngle(100, CAngleUnit::rad());
|
||||
a->switchUnit(CAngleUnit::deg());
|
||||
QVERIFY2(a->getUnit() == CAngleUnit::deg() && c->getConversionSiUnit() == CAngleUnit::rad(),
|
||||
"Testing angle units failed");
|
||||
delete a;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Just testing obvious memory create / destruct flaws
|
||||
*/
|
||||
void TestPhysicalQuantitiesBase::basicArithmetic()
|
||||
{
|
||||
CPressure p1 = CPhysicalQuantitiesConstants::InternationalStandardSeaLevelPressure();
|
||||
CPressure p2(p1);
|
||||
p2 *= 2.0;
|
||||
CPressure p3 = p1 + p1;
|
||||
QVERIFY2(p3 == p2, "Pressure needs to be the same (2times)");
|
||||
p3 /= 2.0;
|
||||
QVERIFY2(p3 == p1, "Pressure needs to be the same (1time)");
|
||||
p3 = p3 - p3;
|
||||
QVERIFY2(p3.unitValueToDouble() == 0, "Value needs to be zero");
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -53,9 +53,14 @@ private slots:
|
||||
*/
|
||||
void temperatureTests();
|
||||
/*!
|
||||
* \brief testing construction / destruction in memory
|
||||
* \brief Testing construction / destruction in memory
|
||||
*/
|
||||
void memoryTests();
|
||||
/*!
|
||||
* \brief Basic arithmetic such as +/-
|
||||
*/
|
||||
void basicArithmetic();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user