mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Unit tests for acceleration and more for vector
This commit is contained in:
@@ -10,10 +10,6 @@ CONFIG -= app_bundle
|
||||
DEPENDPATH += . ../../src/blackmisc
|
||||
INCLUDEPATH += . ../../src
|
||||
|
||||
SOURCES += main.cpp \
|
||||
samplesphysicalquantities.cpp \
|
||||
samplesaviation.cpp
|
||||
|
||||
win32-msvc* {
|
||||
PRE_TARGETDEPS += ../../lib/blackmisc.lib
|
||||
LIBS += ../../lib/blackmisc.lib
|
||||
@@ -26,6 +22,5 @@ win32-msvc* {
|
||||
|
||||
DESTDIR = ../../bin
|
||||
|
||||
HEADERS += \
|
||||
samplesphysicalquantities.h \
|
||||
samplesaviation.h
|
||||
HEADERS += *.h
|
||||
SOURCES += *.cpp
|
||||
|
||||
@@ -110,6 +110,9 @@ int CSamplesPhysicalQuantities::samples()
|
||||
ti2.switchUnit(CTimeUnit::ms());
|
||||
qDebug() << ti1 << ti2;
|
||||
|
||||
CAcceleration ac1(10, CAccelerationUnit::m_s2());
|
||||
qDebug() << ac1;
|
||||
|
||||
// bye
|
||||
qDebug() << "-----------------------------------------------";
|
||||
return 0;
|
||||
|
||||
@@ -26,4 +26,4 @@ private:
|
||||
};
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
#endif // guard
|
||||
|
||||
@@ -5,19 +5,16 @@ TEMPLATE = lib
|
||||
CONFIG += staticlib
|
||||
|
||||
INCLUDEPATH += ..
|
||||
|
||||
# DEPENDPATH += . .. // BlackMisc should be independent
|
||||
# PRECOMPILED_HEADER = stdpch.h
|
||||
|
||||
# PRECOMPILED_HEADER = stdpch.h
|
||||
precompile_header:!isEmpty(PRECOMPILED_HEADER) {
|
||||
DEFINES += USING_PCH
|
||||
}
|
||||
|
||||
DEFINES += LOG_IN_FILE
|
||||
|
||||
HEADERS += *.h \
|
||||
pqacceleration.h
|
||||
|
||||
HEADERS += *.h
|
||||
SOURCES += *.cpp
|
||||
|
||||
DESTDIR = ../../lib
|
||||
|
||||
@@ -166,10 +166,10 @@ public:
|
||||
|
||||
/*!
|
||||
* \brief Get row
|
||||
* \param column
|
||||
* \param row
|
||||
* \return
|
||||
*/
|
||||
CMatrix1x3 getRow(int column) const;
|
||||
CMatrix1x3 getRow(int row) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -375,7 +375,7 @@ public:
|
||||
*/
|
||||
double length()const
|
||||
{
|
||||
return this->m_i * this->m_j + this->m_k;
|
||||
return this->m_i + this->m_j + this->m_k;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#ifndef PQUNITSALL_H
|
||||
#define PQUNITSALL_H
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef BLACKMISC_PQUNITSALL_H
|
||||
#define BLACKMISC_PQUNITSALL_H
|
||||
|
||||
// All units / quantities, required for the instantiations of the template
|
||||
// especially as CRTP is used.
|
||||
@@ -14,5 +19,6 @@
|
||||
#include "blackmisc/pqtemperature.h"
|
||||
#include "blackmisc/pqangle.h"
|
||||
#include "blackmisc/pqtime.h"
|
||||
#include "blackmisc/pqacceleration.h"
|
||||
|
||||
#endif // PQUNITSALL_H
|
||||
#endif // guard
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
@@ -276,13 +276,15 @@ template <class MU, class PQ> bool CPhysicalQuantity<MU, PQ>::operator <=(const
|
||||
/*
|
||||
* Switch to another unit
|
||||
*/
|
||||
template <class MU, class PQ> CPhysicalQuantity<MU, PQ> &CPhysicalQuantity<MU, PQ>::switchUnit(const MU &newUnit)
|
||||
template <class MU, class PQ> PQ &CPhysicalQuantity<MU, PQ>::switchUnit(const MU &newUnit)
|
||||
{
|
||||
if (this->m_unit == newUnit) return *this;
|
||||
double cf = this->m_unit.conversionToUnit(this->m_unitValueD, newUnit);
|
||||
this->m_unit = newUnit;
|
||||
this->setUnitValue(cf);
|
||||
return *this;
|
||||
if (this->m_unit != newUnit)
|
||||
{
|
||||
double cf = this->m_unit.conversionToUnit(this->m_unitValueD, newUnit);
|
||||
this->m_unit = newUnit;
|
||||
this->setUnitValue(cf);
|
||||
}
|
||||
return static_cast<PQ &>(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -407,6 +409,7 @@ template class CPhysicalQuantity<CTemperatureUnit, CTemperature>;
|
||||
template class CPhysicalQuantity<CSpeedUnit, CSpeed>;
|
||||
template class CPhysicalQuantity<CAngleUnit, CAngle>;
|
||||
template class CPhysicalQuantity<CTimeUnit, CTime>;
|
||||
template class CPhysicalQuantity<CAccelerationUnit, CAcceleration>;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
@@ -108,11 +108,11 @@ public:
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Switch unit, e.g. feet meter
|
||||
* \brief Switch unit, e.g. feet to meter
|
||||
* \param newUnit
|
||||
* \return
|
||||
*/
|
||||
CPhysicalQuantity &switchUnit(const MU &newUnit);
|
||||
PQ &switchUnit(const MU &newUnit);
|
||||
|
||||
/*!
|
||||
* \brief Value in SI base unit? Meter is an SI base unit, hertz not!
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
@@ -69,7 +69,8 @@ double CAngleUnit::conversionSexagesimalToSi(const CMeasurementUnit &, double va
|
||||
QString CAngleUnit::toQStringRounded(double value, int digits) const
|
||||
{
|
||||
QString s;
|
||||
if ((*this) == CAngleUnit::sexagesimalDeg()) {
|
||||
if ((*this) == CAngleUnit::sexagesimalDeg())
|
||||
{
|
||||
// special formatting for sexagesimal degrees
|
||||
double de = floor(value);
|
||||
double mi = floor((value - de) * 100.0);
|
||||
@@ -77,7 +78,9 @@ QString CAngleUnit::toQStringRounded(double value, int digits) const
|
||||
QString ses = QLocale::system().toString(se, 'f', 2);
|
||||
s = QString::number(de).append(this->getUnitName()).append(QString::number(mi))
|
||||
.append("'").append(ses).append("\"");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
s = CMeasurementUnit::toQStringRounded(value, digits);
|
||||
}
|
||||
return s;
|
||||
|
||||
@@ -731,7 +731,7 @@ public:
|
||||
*/
|
||||
static const CAccelerationUnit &m_s2()
|
||||
{
|
||||
static CAccelerationUnit ms2("meter/second^2", "m/s^2", true, false, 1, CMeasurementPrefix::None(), 1);
|
||||
static CAccelerationUnit ms2("meter/second²", "m/s²", true, false, 1, CMeasurementPrefix::None(), 1);
|
||||
return ms2;
|
||||
}
|
||||
|
||||
@@ -741,13 +741,11 @@ public:
|
||||
*/
|
||||
static const CAccelerationUnit &ft_s2()
|
||||
{
|
||||
static CAccelerationUnit fts2("feet/seconds^s", "ft/s^2", true, false, 3.28084, CMeasurementPrefix::m(), 0);
|
||||
static CAccelerationUnit fts2("feet/seconds²", "ft/s²", true, false, 3.28084, CMeasurementPrefix::m(), 0);
|
||||
return fts2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 +/-
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user