mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
Implemented commutative multiplications as friends in the templates, further test cases (unit tests), fixed Doxygen attributes, renamed test classes
This commit is contained in:
@@ -11,8 +11,7 @@ int BlackMiscTest::CSamplesVectorMatrix::samples()
|
|||||||
CVector3D v2(1, 2, 3);
|
CVector3D v2(1, 2, 3);
|
||||||
qDebug() << v1 << "value:" << v2[2] << v2.magnitude();
|
qDebug() << v1 << "value:" << v2[2] << v2.magnitude();
|
||||||
v2 *= v2; // v2 * v2
|
v2 *= v2; // v2 * v2
|
||||||
qDebug() << v2;
|
qDebug() << v2 << 2 * v1 << v1 *v1;
|
||||||
// v2 = v1 * v1;
|
|
||||||
|
|
||||||
CMatrix3x3 m;
|
CMatrix3x3 m;
|
||||||
CMatrix3x3 mr = m;
|
CMatrix3x3 mr = m;
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Set longitude
|
* \brief Set longitude
|
||||||
* \param latitude
|
* \param longitude
|
||||||
*/
|
*/
|
||||||
void setLongitude(CLongitude longitude)
|
void setLongitude(CLongitude longitude)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,29 +70,24 @@ CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateGeodetic &geo
|
|||||||
|
|
||||||
CLatitude lat = geo.latitude();
|
CLatitude lat = geo.latitude();
|
||||||
CLongitude lon = geo.longitude();
|
CLongitude lon = geo.longitude();
|
||||||
double latDeg = lat.value(CAngleUnit::deg());
|
|
||||||
double lonDeg = lon.value(CAngleUnit::deg());
|
|
||||||
|
|
||||||
double phi = lat.value(CAngleUnit::rad());
|
double phi = lat.value(CAngleUnit::rad());
|
||||||
double lambdaRad = lon.value(CAngleUnit::rad());
|
double lambdaRad = lon.value(CAngleUnit::rad());
|
||||||
double sphi = sin(phi);
|
double sphi = sin(phi);
|
||||||
double cphi = 0;
|
double cphi = cos(phi);
|
||||||
if (abs(latDeg) != 90) cphi = cos(phi);
|
|
||||||
|
|
||||||
double n = EarthRadiusMeters() / sqrt(1 - e2() * CMath::square(sphi));
|
double n = EarthRadiusMeters() / sqrt(1 - e2() * CMath::square(sphi));
|
||||||
|
|
||||||
double slambda = 0;
|
double slambda = sin(lambdaRad);
|
||||||
if (lonDeg != -180) slambda = sin(lambdaRad);
|
|
||||||
|
|
||||||
double clambda = 0;
|
double clambda = cos(lambdaRad);
|
||||||
if (abs(lonDeg) != 90) clambda = cos(lambdaRad);
|
|
||||||
|
|
||||||
double h = geo.height().convertedSiValueToDouble();
|
double h = geo.height().convertedSiValueToDouble();
|
||||||
double X = (n + h) * cphi;
|
double x = (n + h) * cphi;
|
||||||
double Y = X * slambda;
|
double y = x * slambda;
|
||||||
X *= clambda;
|
x *= clambda;
|
||||||
double Z = (e2m() * n + h) * sphi;
|
double z = (e2m() * n + h) * sphi;
|
||||||
CCoordinateEcef result(X, Y, Z);
|
CCoordinateEcef result(x, y, z);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief ECEF to Geodetic
|
* \brief ECEF to Geodetic
|
||||||
* \param geo
|
* \param ecef
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
static CCoordinateGeodetic toGeodetic(const CCoordinateEcef &ecef);
|
static CCoordinateGeodetic toGeodetic(const CCoordinateEcef &ecef);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Copy constructor
|
* \brief Copy constructor
|
||||||
* \param other
|
* \param otherMatrix
|
||||||
*/
|
*/
|
||||||
CMatrix1x3(const CMatrix1x3 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
CMatrix1x3(const CMatrix1x3 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Copy constructor
|
* \brief Copy constructor
|
||||||
* \param other
|
* \param otherMatrix
|
||||||
*/
|
*/
|
||||||
CMatrix3x1(const CMatrix3x1 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
CMatrix3x1(const CMatrix3x1 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Copy constructor
|
* \brief Copy constructor
|
||||||
* \param other
|
* \param otherMatrix
|
||||||
*/
|
*/
|
||||||
CMatrix3x3(const CMatrix3x3 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
CMatrix3x3(const CMatrix3x3 &otherMatrix) : CMatrixBase(otherMatrix) {}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Operator *
|
* \brief Operator *
|
||||||
* \param multiply
|
* \param otherMatrix
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
CMatrix3x3 operator *(const CMatrix3x3 &otherMatrix) const
|
CMatrix3x3 operator *(const CMatrix3x3 &otherMatrix) const
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ template<class ImplMatrix, int Rows, int Columns> bool CMatrixBase<ImplMatrix, R
|
|||||||
/*
|
/*
|
||||||
* Round all values
|
* Round all values
|
||||||
*/
|
*/
|
||||||
template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, Rows, Columns>::round()
|
template<class ImplMatrix, int Rows, int Columns> ImplMatrix &CMatrixBase<ImplMatrix, Rows, Columns>::round()
|
||||||
{
|
{
|
||||||
for (int r = 0; r < Rows; r++)
|
for (int r = 0; r < Rows; r++)
|
||||||
{
|
{
|
||||||
@@ -96,6 +96,7 @@ template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, R
|
|||||||
this->m_matrix(r, c) = CMath::roundEpsilon(this->m_matrix(r, c), 1E-10);
|
this->m_matrix(r, c) = CMath::roundEpsilon(this->m_matrix(r, c), 1E-10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return static_cast<ImplMatrix &>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Copy constructor
|
* \brief Copy constructor
|
||||||
* \param other
|
* \param otherMatrix
|
||||||
*/
|
*/
|
||||||
CMatrixBase(const CMatrixBase &otherMatrix) : m_matrix(otherMatrix.m_matrix) {}
|
CMatrixBase(const CMatrixBase &otherMatrix) : m_matrix(otherMatrix.m_matrix) {}
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Assigment operator =
|
* \brief Assigment operator =
|
||||||
* \param multiply
|
* \param otherMatrix
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
CMatrixBase &operator =(const CMatrixBase &otherMatrix)
|
CMatrixBase &operator =(const CMatrixBase &otherMatrix)
|
||||||
@@ -116,11 +116,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Multiply with 3D vector operator *
|
* \brief Operator to support commutative multiplication
|
||||||
* \param vector
|
* \param factor
|
||||||
|
* \param otherMatrix
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
template<class ImplVector> ImplVector operator*(const ImplVector vector) const;
|
friend ImplMatrix operator *(double factor, const ImplMatrix &otherMatrix)
|
||||||
|
{
|
||||||
|
return otherMatrix * factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Multiply with 3D vector operator *
|
||||||
|
* \param matrix
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
template<class ImplVector> ImplVector operator*(const ImplVector matrix) const;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Operator /=
|
* \brief Operator /=
|
||||||
@@ -267,7 +278,7 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
* \brief Round all values
|
* \brief Round all values
|
||||||
*/
|
*/
|
||||||
void round();
|
ImplMatrix &round();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Get element
|
* \brief Get element
|
||||||
@@ -286,7 +297,8 @@ public:
|
|||||||
void setElement(size_t row, size_t column, double value);
|
void setElement(size_t row, size_t column, double value);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Get element by ()
|
* \brief Get element by operator () modifying
|
||||||
|
* \param row
|
||||||
* \param column
|
* \param column
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
@@ -297,7 +309,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Get element by ()
|
* \brief Get element by operator () read only
|
||||||
|
* \param row
|
||||||
* \param column
|
* \param column
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ protected:
|
|||||||
/*!
|
/*!
|
||||||
* \brief Default constructor
|
* \brief Default constructor
|
||||||
*/
|
*/
|
||||||
CVector3DBase() {}
|
CVector3DBase() : m_i(0.0), m_j(0.0), m_k(0.0) {}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructor by values
|
* \brief Constructor by values
|
||||||
@@ -124,8 +124,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Get element by ()
|
* \brief Get row element by ()
|
||||||
* \param column
|
* \param row
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
double operator()(size_t row) const { return this->getElement(row); }
|
double operator()(size_t row) const { return this->getElement(row); }
|
||||||
@@ -272,6 +272,17 @@ public:
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Operator to support commutative multiplication
|
||||||
|
* \param factor
|
||||||
|
* \param otherVector
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
friend ImplClass operator *(double factor, const ImplClass &otherVector)
|
||||||
|
{
|
||||||
|
return otherVector * factor;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Divide by scalar
|
* \brief Divide by scalar
|
||||||
* \param divisor
|
* \param divisor
|
||||||
@@ -346,8 +357,7 @@ public:
|
|||||||
void matrixMultiplication(const CMatrix3x3 &matrix);
|
void matrixMultiplication(const CMatrix3x3 &matrix);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Reciporcal value
|
* \brief Reciprocal value
|
||||||
* \param otherVector
|
|
||||||
* \return
|
* \return
|
||||||
*/
|
*/
|
||||||
ImplClass reciprocalValues() const
|
ImplClass reciprocalValues() const
|
||||||
@@ -394,15 +404,16 @@ public:
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Round this vector
|
* \brief Round this vector
|
||||||
|
* \return
|
||||||
*/
|
*/
|
||||||
void round()
|
ImplClass &round()
|
||||||
{
|
{
|
||||||
const double epsilon = 1E-10;
|
const double epsilon = 1E-10;
|
||||||
this->m_i = BlackMisc::Math::CMath::roundEpsilon(this->m_i, epsilon);
|
this->m_i = BlackMisc::Math::CMath::roundEpsilon(this->m_i, epsilon);
|
||||||
this->m_j = BlackMisc::Math::CMath::roundEpsilon(this->m_j, epsilon);
|
this->m_j = BlackMisc::Math::CMath::roundEpsilon(this->m_j, epsilon);
|
||||||
this->m_k = BlackMisc::Math::CMath::roundEpsilon(this->m_k, epsilon);
|
this->m_k = BlackMisc::Math::CMath::roundEpsilon(this->m_k, epsilon);
|
||||||
|
return static_cast<ImplClass &>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -278,6 +278,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
PQ operator *(double multiply) const;
|
PQ operator *(double multiply) const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Operator to support commutative multiplication
|
||||||
|
* \param factor
|
||||||
|
* \param otherQuantity
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
friend PQ operator *(double factor, const PQ &otherQuantity)
|
||||||
|
{
|
||||||
|
return otherQuantity * factor;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Operator /
|
* \brief Operator /
|
||||||
* \param divide
|
* \param divide
|
||||||
|
|||||||
@@ -6,18 +6,20 @@ TEMPLATE = app
|
|||||||
CONFIG += console
|
CONFIG += console
|
||||||
CONFIG -= app_bundle
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
DEPENDPATH += . ../../src
|
DEPENDPATH += . ../../src/blackmisc
|
||||||
INCLUDEPATH += . ../../src
|
INCLUDEPATH += . ../../src
|
||||||
SOURCES += main.cpp testmain.cpp \
|
SOURCES += main.cpp testmain.cpp \
|
||||||
testphysicalquantitiesbase.cpp \
|
testphysicalquantities.cpp \
|
||||||
testaviationbase.cpp \
|
testvectormatrix.cpp \
|
||||||
testvectormatrixbase.cpp
|
testaviation.cpp \
|
||||||
|
testgeo.cpp
|
||||||
|
|
||||||
HEADERS += testmain.h \
|
HEADERS += testmain.h \
|
||||||
testphysicalquantitiesbase.h \
|
|
||||||
blackmisctest.h \
|
blackmisctest.h \
|
||||||
testaviationbase.h \
|
testphysicalquantities.h \
|
||||||
testvectormatrixbase.h
|
testvectormatrix.h \
|
||||||
|
testaviation.h \
|
||||||
|
testgeo.h
|
||||||
|
|
||||||
win32-msvc* {
|
win32-msvc* {
|
||||||
PRE_TARGETDEPS += ../../lib/blackmisc.lib
|
PRE_TARGETDEPS += ../../lib/blackmisc.lib
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "testaviationbase.h"
|
#include "testaviation.h"
|
||||||
|
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
@@ -13,7 +13,7 @@ namespace BlackMiscTest {
|
|||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
CTestAviationBase::CTestAviationBase(QObject *parent): QObject(parent)
|
CTestAviation::CTestAviation(QObject *parent): QObject(parent)
|
||||||
{
|
{
|
||||||
// void
|
// void
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ CTestAviationBase::CTestAviationBase(QObject *parent): QObject(parent)
|
|||||||
/*
|
/*
|
||||||
* Basic tests
|
* Basic tests
|
||||||
*/
|
*/
|
||||||
void CTestAviationBase::headingBasics()
|
void CTestAviation::headingBasics()
|
||||||
{
|
{
|
||||||
CHeading h1(180, true, CAngleUnit::deg());
|
CHeading h1(180, true, CAngleUnit::deg());
|
||||||
CHeading h2(180, false, CAngleUnit::deg());
|
CHeading h2(180, false, CAngleUnit::deg());
|
||||||
@@ -45,7 +45,7 @@ void CTestAviationBase::headingBasics()
|
|||||||
/*
|
/*
|
||||||
* Vertical positions
|
* Vertical positions
|
||||||
*/
|
*/
|
||||||
void CTestAviationBase::verticalPosition()
|
void CTestAviation::verticalPosition()
|
||||||
{
|
{
|
||||||
CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 3000.0);
|
CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 3000.0);
|
||||||
CAviationVerticalPositions vp2 = vp1;
|
CAviationVerticalPositions vp2 = vp1;
|
||||||
@@ -55,7 +55,7 @@ void CTestAviationBase::verticalPosition()
|
|||||||
/*
|
/*
|
||||||
* COM and NAV units
|
* COM and NAV units
|
||||||
*/
|
*/
|
||||||
void CTestAviationBase::comAndNav()
|
void CTestAviation::comAndNav()
|
||||||
{
|
{
|
||||||
CComSystem c1 = CComSystem::getCom1System(122.8);
|
CComSystem c1 = CComSystem::getCom1System(122.8);
|
||||||
CComSystem c2 = CComSystem::getCom2System(122.8);
|
CComSystem c2 = CComSystem::getCom2System(122.8);
|
||||||
@@ -72,7 +72,7 @@ void CTestAviationBase::comAndNav()
|
|||||||
/*
|
/*
|
||||||
* COM and NAV units
|
* COM and NAV units
|
||||||
*/
|
*/
|
||||||
void CTestAviationBase::transponder()
|
void CTestAviation::transponder()
|
||||||
{
|
{
|
||||||
CTransponder t1 = CTransponder::getStandardTransponder(7000, CTransponder::StateStandby);
|
CTransponder t1 = CTransponder::getStandardTransponder(7000, CTransponder::StateStandby);
|
||||||
CTransponder t2 = t1;
|
CTransponder t2 = t1;
|
||||||
@@ -20,7 +20,7 @@ namespace BlackMiscTest
|
|||||||
/*!
|
/*!
|
||||||
* \brief Aviation classes basic tests
|
* \brief Aviation classes basic tests
|
||||||
*/
|
*/
|
||||||
class CTestAviationBase : public QObject
|
class CTestAviation : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ public:
|
|||||||
* \brief Standard test case constructor
|
* \brief Standard test case constructor
|
||||||
* \param parent
|
* \param parent
|
||||||
*/
|
*/
|
||||||
explicit CTestAviationBase(QObject *parent = 0);
|
explicit CTestAviation(QObject *parent = 0);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
/*!
|
/*!
|
||||||
32
tests/blackmisc/testgeo.cpp
Normal file
32
tests/blackmisc/testgeo.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "testgeo.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc::Geo;
|
||||||
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
|
||||||
|
namespace BlackMiscTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Geo classes tests
|
||||||
|
*/
|
||||||
|
void CTestGeo::geoBasics()
|
||||||
|
{
|
||||||
|
CLatitude lati(10, CAngleUnit::deg());
|
||||||
|
QVERIFY2(lati * 2 == lati + lati, "Latitude addition should be equal");
|
||||||
|
lati += CLatitude(20, CAngleUnit::deg());
|
||||||
|
QVERIFY2(lati.unitValueToDoubleRounded() == 30.0, "Latitude should be 30 degrees");
|
||||||
|
|
||||||
|
double lat = 27.999999, lon = 86.999999, h = 8820.999999; // Mt Everest
|
||||||
|
CCoordinateGeodetic startGeoVec(lat, lon, h);
|
||||||
|
CCoordinateEcef mediumEcefVec = CCoordinateTransformation::toEcef(startGeoVec);
|
||||||
|
CCoordinateGeodetic endGeoVec = CCoordinateTransformation::toGeodetic(mediumEcefVec);
|
||||||
|
QVERIFY2(startGeoVec == endGeoVec, "Reconverted geo vector should be equal ");
|
||||||
|
|
||||||
|
CCoordinateNed nedVec = CCoordinateTransformation::toNed(mediumEcefVec, startGeoVec);
|
||||||
|
CCoordinateEcef ecefReconvert = CCoordinateTransformation::toEcef(nedVec);
|
||||||
|
|
||||||
|
QVERIFY2(mediumEcefVec != ecefReconvert, "Reconverted geo vector, expect some minor rounding issues");
|
||||||
|
QVERIFY2(mediumEcefVec.round() == ecefReconvert.round(), "Reconverted geo vector should be equal");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
38
tests/blackmisc/testgeo.h
Normal file
38
tests/blackmisc/testgeo.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* 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 BLACKMISCTEST_TESTGEO_H
|
||||||
|
#define BLACKMISCTEST_TESTGEO_H
|
||||||
|
|
||||||
|
#include "blackmisc/coordinatetransformation.h"
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
namespace BlackMiscTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Geo classes tests
|
||||||
|
*/
|
||||||
|
class CTestGeo : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* \brief Standard test case constructor
|
||||||
|
* \param parent
|
||||||
|
*/
|
||||||
|
explicit CTestGeo(QObject *parent = 0) : QObject(parent) {}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
/*!
|
||||||
|
* \brief Basic unit tests for geo classes
|
||||||
|
*/
|
||||||
|
void geoBasics();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
@@ -14,12 +14,14 @@ int CTestMain::unitMain(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
{
|
{
|
||||||
CTestPhysicalQuantitiesBase pqBaseTests ;
|
CTestPhysicalQuantities pqBaseTests ;
|
||||||
CTestAviationBase avBaseTests;
|
CTestAviation avBaseTests;
|
||||||
CTestVectorMatrixBase vmTests;
|
CTestVectorMatrix vmTests;
|
||||||
|
CTestGeo geoTests;
|
||||||
status |= QTest::qExec(&pqBaseTests, argc, argv);
|
status |= QTest::qExec(&pqBaseTests, argc, argv);
|
||||||
status |= QTest::qExec(&avBaseTests, argc, argv);
|
status |= QTest::qExec(&avBaseTests, argc, argv);
|
||||||
status |= QTest::qExec(&vmTests, argc, argv);
|
status |= QTest::qExec(&vmTests, argc, argv);
|
||||||
|
status |= QTest::qExec(&geoTests, argc, argv);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,10 @@
|
|||||||
#ifndef BLACKMISCTEST_TESTMAIN_H
|
#ifndef BLACKMISCTEST_TESTMAIN_H
|
||||||
#define BLACKMISCTEST_TESTMAIN_H
|
#define BLACKMISCTEST_TESTMAIN_H
|
||||||
|
|
||||||
#include "testphysicalquantitiesbase.h"
|
#include "testphysicalquantities.h"
|
||||||
#include "testaviationbase.h"
|
#include "testaviation.h"
|
||||||
#include "testvectormatrixbase.h"
|
#include "testvectormatrix.h"
|
||||||
|
#include "testgeo.h"
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
namespace BlackMiscTest
|
namespace BlackMiscTest
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "testphysicalquantitiesbase.h"
|
#include "testphysicalquantities.h"
|
||||||
|
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ namespace BlackMiscTest
|
|||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
CTestPhysicalQuantitiesBase::CTestPhysicalQuantitiesBase(QObject *parent) : QObject(parent)
|
CTestPhysicalQuantities::CTestPhysicalQuantities(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
// void
|
// void
|
||||||
}
|
}
|
||||||
@@ -21,9 +21,9 @@ CTestPhysicalQuantitiesBase::CTestPhysicalQuantitiesBase(QObject *parent) : QObj
|
|||||||
/*
|
/*
|
||||||
* Basic unit tests for physical units
|
* Basic unit tests for physical units
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::unitsBasics()
|
void CTestPhysicalQuantities::unitsBasics()
|
||||||
{
|
{
|
||||||
QVERIFY(CMeasurementPrefix::k() > CMeasurementPrefix::h());
|
QVERIFY2(CMeasurementPrefix::k() > CMeasurementPrefix::h(), "kilo > hecto");
|
||||||
|
|
||||||
// some tests on units
|
// some tests on units
|
||||||
CLengthUnit du1 = CLengthUnit::m(); // Copy
|
CLengthUnit du1 = CLengthUnit::m(); // Copy
|
||||||
@@ -42,15 +42,15 @@ void CTestPhysicalQuantitiesBase::unitsBasics()
|
|||||||
/*
|
/*
|
||||||
* Distance tests
|
* Distance tests
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::lengthBasics()
|
void CTestPhysicalQuantities::lengthBasics()
|
||||||
{
|
{
|
||||||
CLength d1(1, CLengthUnit::m()); // 1m
|
CLength d1(1, CLengthUnit::m()); // 1m
|
||||||
CLength d2(100, CLengthUnit::cm());
|
CLength d2(100, CLengthUnit::cm());
|
||||||
CLength d3(1.852 * 1000, CLengthUnit::m()); // 1852m
|
CLength d3(1.852 * 1000, CLengthUnit::m()); // 1852m
|
||||||
CLength d4(1, CLengthUnit::NM());
|
CLength d4(1, CLengthUnit::NM());
|
||||||
|
|
||||||
QVERIFY2(d1 == d2, "1meter shall be 100cm");
|
QVERIFY2(d1 == d2, "1meter shall be 100cm");
|
||||||
QVERIFY2(d3 == d4, "1852meters shall be 1NM");
|
QVERIFY2(d3 == d4, "1852meters shall be 1NM");
|
||||||
|
QVERIFY2(d1 * 2 == 2 * d1, "Commutative multiplication");
|
||||||
|
|
||||||
d3 *= 2; // SI value
|
d3 *= 2; // SI value
|
||||||
d4 *= 2.0; // SI value !
|
d4 *= 2.0; // SI value !
|
||||||
@@ -73,7 +73,7 @@ void CTestPhysicalQuantitiesBase::lengthBasics()
|
|||||||
/*
|
/*
|
||||||
* Unit tests for speed
|
* Unit tests for speed
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::speedBasics()
|
void CTestPhysicalQuantities::speedBasics()
|
||||||
{
|
{
|
||||||
CSpeed s1(100, CSpeedUnit::km_h());
|
CSpeed s1(100, CSpeedUnit::km_h());
|
||||||
CSpeed s2(1000, CSpeedUnit::ft_min());
|
CSpeed s2(1000, CSpeedUnit::ft_min());
|
||||||
@@ -84,7 +84,7 @@ void CTestPhysicalQuantitiesBase::speedBasics()
|
|||||||
/*
|
/*
|
||||||
* Frequency unit tests
|
* Frequency unit tests
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::frequencyTests()
|
void CTestPhysicalQuantities::frequencyTests()
|
||||||
{
|
{
|
||||||
CFrequency f1(1, CFrequencyUnit::MHz());
|
CFrequency f1(1, CFrequencyUnit::MHz());
|
||||||
QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(), 2) == 1000, "Mega is 1000kHz");
|
QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(), 2) == 1000, "Mega is 1000kHz");
|
||||||
@@ -97,7 +97,7 @@ void CTestPhysicalQuantitiesBase::frequencyTests()
|
|||||||
/*
|
/*
|
||||||
* Angle tests
|
* Angle tests
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::angleTests()
|
void CTestPhysicalQuantities::angleTests()
|
||||||
{
|
{
|
||||||
CAngle a1(180, CAngleUnit::deg());
|
CAngle a1(180, CAngleUnit::deg());
|
||||||
CAngle a2(1.5 * CAngle::pi(), CAngleUnit::rad());
|
CAngle a2(1.5 * CAngle::pi(), CAngleUnit::rad());
|
||||||
@@ -111,7 +111,7 @@ void CTestPhysicalQuantitiesBase::angleTests()
|
|||||||
/*
|
/*
|
||||||
* Weight tests
|
* Weight tests
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::massTests()
|
void CTestPhysicalQuantities::massTests()
|
||||||
{
|
{
|
||||||
CMass w1(1000, CMassUnit::kg());
|
CMass w1(1000, CMassUnit::kg());
|
||||||
CMass w2(w1.unitValueToInteger(), CMassUnit::kg());
|
CMass w2(w1.unitValueToInteger(), CMassUnit::kg());
|
||||||
@@ -125,7 +125,7 @@ void CTestPhysicalQuantitiesBase::massTests()
|
|||||||
/*
|
/*
|
||||||
* Pressure tests
|
* Pressure tests
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::pressureTests()
|
void CTestPhysicalQuantities::pressureTests()
|
||||||
{
|
{
|
||||||
CPressure p1(1013.25, CPressureUnit::hPa());
|
CPressure p1(1013.25, CPressureUnit::hPa());
|
||||||
CPressure p2(29.92, CPressureUnit::inHg());
|
CPressure p2(29.92, CPressureUnit::inHg());
|
||||||
@@ -142,7 +142,7 @@ void CTestPhysicalQuantitiesBase::pressureTests()
|
|||||||
/*
|
/*
|
||||||
* Temperature tests
|
* Temperature tests
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::temperatureTests()
|
void CTestPhysicalQuantities::temperatureTests()
|
||||||
{
|
{
|
||||||
CTemperature t1(0, CTemperatureUnit::C()); // 0C
|
CTemperature t1(0, CTemperatureUnit::C()); // 0C
|
||||||
CTemperature t2(1, CTemperatureUnit::F()); // 1F
|
CTemperature t2(1, CTemperatureUnit::F()); // 1F
|
||||||
@@ -157,7 +157,7 @@ void CTestPhysicalQuantitiesBase::temperatureTests()
|
|||||||
/*
|
/*
|
||||||
* Temperature tests
|
* Temperature tests
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::timeTests()
|
void CTestPhysicalQuantities::timeTests()
|
||||||
{
|
{
|
||||||
CTime t1(1, CTimeUnit::h());
|
CTime t1(1, CTimeUnit::h());
|
||||||
QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s");
|
QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s");
|
||||||
@@ -166,7 +166,7 @@ void CTestPhysicalQuantitiesBase::timeTests()
|
|||||||
/*
|
/*
|
||||||
* Just testing obvious memory create / destruct flaws
|
* Just testing obvious memory create / destruct flaws
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::memoryTests()
|
void CTestPhysicalQuantities::memoryTests()
|
||||||
{
|
{
|
||||||
CLength *c = new CLength(100, CLengthUnit::m());
|
CLength *c = new CLength(100, CLengthUnit::m());
|
||||||
c->switchUnit(CLengthUnit::NM());
|
c->switchUnit(CLengthUnit::NM());
|
||||||
@@ -184,7 +184,7 @@ void CTestPhysicalQuantitiesBase::memoryTests()
|
|||||||
/*
|
/*
|
||||||
* @brief Just testing obvious memory create / destruct flaws
|
* @brief Just testing obvious memory create / destruct flaws
|
||||||
*/
|
*/
|
||||||
void CTestPhysicalQuantitiesBase::basicArithmetic()
|
void CTestPhysicalQuantities::basicArithmetic()
|
||||||
{
|
{
|
||||||
CPressure p1 = CPhysicalQuantitiesConstants::InternationalStandardSeaLevelPressure();
|
CPressure p1 = CPhysicalQuantitiesConstants::InternationalStandardSeaLevelPressure();
|
||||||
CPressure p2(p1);
|
CPressure p2(p1);
|
||||||
@@ -15,7 +15,7 @@ namespace BlackMiscTest
|
|||||||
/*!
|
/*!
|
||||||
* \brief Physical quantities, basic tests
|
* \brief Physical quantities, basic tests
|
||||||
*/
|
*/
|
||||||
class CTestPhysicalQuantitiesBase : public QObject
|
class CTestPhysicalQuantities : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -24,7 +24,8 @@ public:
|
|||||||
* \brief Standard test case constructor
|
* \brief Standard test case constructor
|
||||||
* \param parent
|
* \param parent
|
||||||
*/
|
*/
|
||||||
explicit CTestPhysicalQuantitiesBase(QObject *parent = 0);
|
explicit CTestPhysicalQuantities(QObject *parent = 0);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
/*!
|
/*!
|
||||||
* \brief Basic unit tests for physical units
|
* \brief Basic unit tests for physical units
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "testvectormatrixbase.h"
|
#include "testvectormatrix.h"
|
||||||
|
|
||||||
using namespace BlackMisc::Math;
|
using namespace BlackMisc::Math;
|
||||||
|
|
||||||
@@ -13,12 +13,13 @@ namespace BlackMiscTest
|
|||||||
/*
|
/*
|
||||||
* Basic tests vector
|
* Basic tests vector
|
||||||
*/
|
*/
|
||||||
void CTestVectorMatrixBase::vectorBasics()
|
void CTestVectorMatrix::vectorBasics()
|
||||||
{
|
{
|
||||||
CVector3D v1(1);
|
CVector3D v1(1);
|
||||||
v1 *= 2.0;
|
v1 *= 2.0;
|
||||||
CVector3D v2(2);
|
CVector3D v2(2);
|
||||||
QVERIFY2(v1 == v2, "Vectors should be equal");
|
QVERIFY2(v1 == v2, "Vectors should be equal");
|
||||||
|
QVERIFY2(v1 * 2 == 2 * v2, "Commutative vector multiplication failed");
|
||||||
CVector3D v3(1, 1, 1);
|
CVector3D v3(1, 1, 1);
|
||||||
CVector3D v4(2, 2, 2);
|
CVector3D v4(2, 2, 2);
|
||||||
CVector3D v5 = v3.crossProduct(v4);
|
CVector3D v5 = v3.crossProduct(v4);
|
||||||
@@ -33,7 +34,7 @@ void CTestVectorMatrixBase::vectorBasics()
|
|||||||
* Matrix tests
|
* Matrix tests
|
||||||
* http://www.bluebit.gr/matrix-calculator/
|
* http://www.bluebit.gr/matrix-calculator/
|
||||||
*/
|
*/
|
||||||
void CTestVectorMatrixBase::matrixBasics()
|
void CTestVectorMatrix::matrixBasics()
|
||||||
{
|
{
|
||||||
CMatrix3x3 m1;
|
CMatrix3x3 m1;
|
||||||
CMatrix3x3 m2 = m1 - m1;
|
CMatrix3x3 m2 = m1 - m1;
|
||||||
@@ -55,6 +56,7 @@ void CTestVectorMatrixBase::matrixBasics()
|
|||||||
m2 = m1 + m1;
|
m2 = m1 + m1;
|
||||||
m1 = m1 * 2.0;
|
m1 = m1 * 2.0;
|
||||||
QVERIFY2(m1 == m2, "2* Identity should be Identity + Identity");
|
QVERIFY2(m1 == m2, "2* Identity should be Identity + Identity");
|
||||||
|
QVERIFY2(m1 * 2 == 2 * m1, "Commutative matrix multiplication failed");
|
||||||
|
|
||||||
m1 /= 2.0;
|
m1 /= 2.0;
|
||||||
m2 -= m1;
|
m2 -= m1;
|
||||||
@@ -13,9 +13,9 @@ namespace BlackMiscTest
|
|||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Vector and Matrix classes basic tests
|
* \brief Vector and Matrix classes tests
|
||||||
*/
|
*/
|
||||||
class CTestVectorMatrixBase : public QObject
|
class CTestVectorMatrix : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -24,13 +24,14 @@ public:
|
|||||||
* \brief Standard test case constructor
|
* \brief Standard test case constructor
|
||||||
* \param parent
|
* \param parent
|
||||||
*/
|
*/
|
||||||
explicit CTestVectorMatrixBase(QObject *parent = 0) : QObject(parent) {}
|
explicit CTestVectorMatrix(QObject *parent = 0) : QObject(parent) {}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
/*!
|
/*!
|
||||||
* \brief Basic unit tests for physical units
|
* \brief Basic unit tests for physical units
|
||||||
*/
|
*/
|
||||||
void vectorBasics();
|
void vectorBasics();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Vertical positions
|
* \brief Vertical positions
|
||||||
*/
|
*/
|
||||||
Reference in New Issue
Block a user