Unit tests for acceleration and more for vector

This commit is contained in:
Klaus Basan
2013-04-25 20:21:04 +02:00
parent 2d8720c6ae
commit 5eac9be7d5
16 changed files with 88 additions and 59 deletions

View File

@@ -8,18 +8,9 @@ CONFIG -= app_bundle
DEPENDPATH += . ../../src/blackmisc
INCLUDEPATH += . ../../src
SOURCES += main.cpp testmain.cpp \
testphysicalquantities.cpp \
testvectormatrix.cpp \
testaviation.cpp \
testgeo.cpp
HEADERS += testmain.h \
blackmisctest.h \
testphysicalquantities.h \
testvectormatrix.h \
testaviation.h \
testgeo.h
HEADERS += *.h
SOURCES += *.cpp
win32-msvc* {
PRE_TARGETDEPS += ../../lib/blackmisc.lib

View File

@@ -10,14 +10,6 @@ using namespace BlackMisc::PhysicalQuantities;
namespace BlackMiscTest
{
/*
* Constructor
*/
CTestPhysicalQuantities::CTestPhysicalQuantities(QObject *parent) : QObject(parent)
{
// void
}
/*
* Basic unit tests for physical units
*/
@@ -163,6 +155,22 @@ void CTestPhysicalQuantities::timeTests()
QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s");
}
/*
* Test acceleration
*/
void CTestPhysicalQuantities::accelerationTests()
{
CLength oneMeter(1, CLengthUnit::m());
double ftFactor = oneMeter.switchUnit(CLengthUnit::ft()).unitValueToDouble();
CAcceleration a1(10.0, CAccelerationUnit::m_s2());
CAcceleration a2(a1);
a1.switchUnit(CAccelerationUnit::ft_s2());
QVERIFY2(a1 == a2, "Accelerations should be similar");
QVERIFY2(BlackMisc::Math::CMath::round(a1.unitValueToDouble() * ftFactor, 6) == a2.unitValueToDoubleRounded(6),
"Numerical values should be equal");
}
/*
* Just testing obvious memory create / destruct flaws
*/
@@ -182,7 +190,7 @@ void CTestPhysicalQuantities::memoryTests()
}
/*
* @brief Just testing obvious memory create / destruct flaws
* Some very basic arithmetic tests on the PQs
*/
void CTestPhysicalQuantities::basicArithmetic()
{
@@ -195,5 +203,7 @@ void CTestPhysicalQuantities::basicArithmetic()
QVERIFY2(p3 == p1, "Pressure needs to be the same (1time)");
p3 = p3 - p3;
QVERIFY2(p3.unitValueToDouble() == 0, "Value needs to be zero");
p3 = CPressure(1013, CPressureUnit::hPa());
QVERIFY2(p3 * 1.5 == 1.5 * p3, "Basic commutative test on PQ failed");
}
} // namespace

View File

@@ -24,49 +24,64 @@ public:
* \brief Standard test case constructor
* \param parent
*/
explicit CTestPhysicalQuantities(QObject *parent = 0);
explicit CTestPhysicalQuantities(QObject *parent = 0) : QObject(parent) {}
private slots:
/*!
* \brief Basic unit tests for physical units
*/
void unitsBasics();
/*!
* \brief Basic tests around length
*/
void lengthBasics();
/*!
* \brief Basic tests about speed
*/
void speedBasics();
/*!
* \brief Frequency tests
*/
void frequencyTests();
/*!
* \brief Testing angles (degrees / radians)
*/
void angleTests();
/*!
* \brief Testing angles
*/
void massTests();
/*!
* \brief Testing pressure
*/
void pressureTests();
/*!
* \brief Testing temperature
*/
void temperatureTests();
/*!
* \brief Testing time
*/
void timeTests();
/*!
* \brief Testing acceleration
*/
void accelerationTests();
/*!
* \brief Testing construction / destruction in memory
*/
void memoryTests();
/*!
* \brief Basic arithmetic such as +/-
*/

View File

@@ -28,6 +28,9 @@ void CTestVectorMatrix::vectorBasics()
CVector3D v7(3, 4, 5);
QVERIFY2(v6.crossProduct(v7) == CVector3D(-2, 4, -2), "Cross product is wrong");
QVERIFY2(v6.dotProduct(v7) == 26, "Dot product is wrong, 26 expected");
QVERIFY2(v6.length() == (1 + 2 + 3), "Wrong vector length");
QVERIFY2(v6.lengthSquared() == (1 + 4 + 9), "Wrong squared vector length");
QVERIFY2(v6.magnitude() == sqrt(1.0 + 4.0 + 9.0), "Wrong vector magnitude");
}
/*
@@ -68,8 +71,13 @@ void CTestVectorMatrix::matrixBasics()
QVERIFY2(m1(0, 0) == 1 && m1(1, 0) == 2 && m1(0, 2) == 3, "Index error");
CMatrix3x3 mi = m1.inverse(invertible);
CMatrix3x3 mid = m1 * mi;
mid.round();
QVERIFY2(mid.isIdentity(), qPrintable(QString("Multiply with inverse should be identity: %1").arg(mid.toQString())));
QVERIFY2(mid.isIdentityEpsilon(), qPrintable(QString("Multiply with inverse should be identity: %1").arg(mid.toQString())));
m1.setToIdentity();
CMatrix3x1 mc1 = m1.getColumn(0);
CMatrix1x3 mr2 = m1.getRow(1);
QVERIFY2(mc1 == CMatrix3x1(1, 0, 0), "Wrong column 0");
QVERIFY2(mr2 == CMatrix1x3(0, 1, 0), "Wrong row 1");
}
} // namespace