From a31e405b6bd42b630b95d1f51358466aba841b6c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 25 Apr 2013 01:56:18 +0200 Subject: [PATCH] Implemented commutative multiplications as friends in the templates, further test cases (unit tests), fixed Doxygen attributes, renamed test classes --- .../samplesvectormatrix.cpp | 3 +- src/blackmisc/coordinategeodetic.h | 2 +- src/blackmisc/coordinatetransformation.cpp | 21 ++++------ src/blackmisc/coordinatetransformation.h | 2 +- src/blackmisc/mathmatrix1x3.h | 2 +- src/blackmisc/mathmatrix3x1.h | 2 +- src/blackmisc/mathmatrix3x3.h | 4 +- src/blackmisc/mathmatrixbase.cpp | 3 +- src/blackmisc/mathmatrixbase.h | 29 ++++++++++---- src/blackmisc/mathvector3dbase.h | 25 ++++++++---- src/blackmisc/pqphysicalquantity.h | 23 ++++++++--- tests/blackmisc/test_blackmisc.pro | 16 ++++---- ...{testaviationbase.cpp => testaviation.cpp} | 12 +++--- .../{testaviationbase.h => testaviation.h} | 4 +- tests/blackmisc/testgeo.cpp | 32 ++++++++++++++++ tests/blackmisc/testgeo.h | 38 +++++++++++++++++++ tests/blackmisc/testmain.cpp | 8 ++-- tests/blackmisc/testmain.h | 7 ++-- ...iesbase.cpp => testphysicalquantities.cpp} | 30 +++++++-------- ...ntitiesbase.h => testphysicalquantities.h} | 7 ++-- ...tormatrixbase.cpp => testvectormatrix.cpp} | 8 ++-- ...tvectormatrixbase.h => testvectormatrix.h} | 7 ++-- 22 files changed, 197 insertions(+), 88 deletions(-) rename tests/blackmisc/{testaviationbase.cpp => testaviation.cpp} (91%) rename tests/blackmisc/{testaviationbase.h => testaviation.h} (92%) create mode 100644 tests/blackmisc/testgeo.cpp create mode 100644 tests/blackmisc/testgeo.h rename tests/blackmisc/{testphysicalquantitiesbase.cpp => testphysicalquantities.cpp} (89%) rename tests/blackmisc/{testphysicalquantitiesbase.h => testphysicalquantities.h} (90%) rename tests/blackmisc/{testvectormatrixbase.cpp => testvectormatrix.cpp} (89%) rename tests/blackmisc/{testvectormatrixbase.h => testvectormatrix.h} (81%) diff --git a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp b/samples/blackmiscvectorgeo/samplesvectormatrix.cpp index 3408f8d54..ff49e1b27 100644 --- a/samples/blackmiscvectorgeo/samplesvectormatrix.cpp +++ b/samples/blackmiscvectorgeo/samplesvectormatrix.cpp @@ -11,8 +11,7 @@ int BlackMiscTest::CSamplesVectorMatrix::samples() CVector3D v2(1, 2, 3); qDebug() << v1 << "value:" << v2[2] << v2.magnitude(); v2 *= v2; // v2 * v2 - qDebug() << v2; - // v2 = v1 * v1; + qDebug() << v2 << 2 * v1 << v1 *v1; CMatrix3x3 m; CMatrix3x3 mr = m; diff --git a/src/blackmisc/coordinategeodetic.h b/src/blackmisc/coordinategeodetic.h index c2cf1b9a3..4ba2e890b 100644 --- a/src/blackmisc/coordinategeodetic.h +++ b/src/blackmisc/coordinategeodetic.h @@ -124,7 +124,7 @@ public: /*! * \brief Set longitude - * \param latitude + * \param longitude */ void setLongitude(CLongitude longitude) { diff --git a/src/blackmisc/coordinatetransformation.cpp b/src/blackmisc/coordinatetransformation.cpp index 9ca6edf5b..fd68b659c 100644 --- a/src/blackmisc/coordinatetransformation.cpp +++ b/src/blackmisc/coordinatetransformation.cpp @@ -70,29 +70,24 @@ CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateGeodetic &geo CLatitude lat = geo.latitude(); CLongitude lon = geo.longitude(); - double latDeg = lat.value(CAngleUnit::deg()); - double lonDeg = lon.value(CAngleUnit::deg()); double phi = lat.value(CAngleUnit::rad()); double lambdaRad = lon.value(CAngleUnit::rad()); double sphi = sin(phi); - double cphi = 0; - if (abs(latDeg) != 90) cphi = cos(phi); + double cphi = cos(phi); double n = EarthRadiusMeters() / sqrt(1 - e2() * CMath::square(sphi)); - double slambda = 0; - if (lonDeg != -180) slambda = sin(lambdaRad); + double slambda = sin(lambdaRad); - double clambda = 0; - if (abs(lonDeg) != 90) clambda = cos(lambdaRad); + double clambda = cos(lambdaRad); double h = geo.height().convertedSiValueToDouble(); - double X = (n + h) * cphi; - double Y = X * slambda; - X *= clambda; - double Z = (e2m() * n + h) * sphi; - CCoordinateEcef result(X, Y, Z); + double x = (n + h) * cphi; + double y = x * slambda; + x *= clambda; + double z = (e2m() * n + h) * sphi; + CCoordinateEcef result(x, y, z); return result; } diff --git a/src/blackmisc/coordinatetransformation.h b/src/blackmisc/coordinatetransformation.h index 26afb12aa..581a29ec9 100644 --- a/src/blackmisc/coordinatetransformation.h +++ b/src/blackmisc/coordinatetransformation.h @@ -121,7 +121,7 @@ public: /*! * \brief ECEF to Geodetic - * \param geo + * \param ecef * \return */ static CCoordinateGeodetic toGeodetic(const CCoordinateEcef &ecef); diff --git a/src/blackmisc/mathmatrix1x3.h b/src/blackmisc/mathmatrix1x3.h index 6a90a32ac..614c456cc 100644 --- a/src/blackmisc/mathmatrix1x3.h +++ b/src/blackmisc/mathmatrix1x3.h @@ -27,7 +27,7 @@ public: /*! * \brief Copy constructor - * \param other + * \param otherMatrix */ CMatrix1x3(const CMatrix1x3 &otherMatrix) : CMatrixBase(otherMatrix) {} diff --git a/src/blackmisc/mathmatrix3x1.h b/src/blackmisc/mathmatrix3x1.h index eec8fd622..c2da2aefd 100644 --- a/src/blackmisc/mathmatrix3x1.h +++ b/src/blackmisc/mathmatrix3x1.h @@ -42,7 +42,7 @@ public: /*! * \brief Copy constructor - * \param other + * \param otherMatrix */ CMatrix3x1(const CMatrix3x1 &otherMatrix) : CMatrixBase(otherMatrix) {} diff --git a/src/blackmisc/mathmatrix3x3.h b/src/blackmisc/mathmatrix3x3.h index 57fef0079..970c09d8c 100644 --- a/src/blackmisc/mathmatrix3x3.h +++ b/src/blackmisc/mathmatrix3x3.h @@ -26,7 +26,7 @@ public: /*! * \brief Copy constructor - * \param other + * \param otherMatrix */ CMatrix3x3(const CMatrix3x3 &otherMatrix) : CMatrixBase(otherMatrix) {} @@ -101,7 +101,7 @@ public: /*! * \brief Operator * - * \param multiply + * \param otherMatrix * \return */ CMatrix3x3 operator *(const CMatrix3x3 &otherMatrix) const diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index e5ad28153..bcc498aa7 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -87,7 +87,7 @@ template bool CMatrixBase void CMatrixBase::round() +template ImplMatrix &CMatrixBase::round() { for (int r = 0; r < Rows; r++) { @@ -96,6 +96,7 @@ template void CMatrixBasem_matrix(r, c) = CMath::roundEpsilon(this->m_matrix(r, c), 1E-10); } } + return static_cast(*this); } /* diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index 1156d91a0..7066f3e71 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -39,7 +39,7 @@ public: /*! * \brief Copy constructor - * \param other + * \param otherMatrix */ CMatrixBase(const CMatrixBase &otherMatrix) : m_matrix(otherMatrix.m_matrix) {} @@ -81,7 +81,7 @@ public: /*! * \brief Assigment operator = - * \param multiply + * \param otherMatrix * \return */ CMatrixBase &operator =(const CMatrixBase &otherMatrix) @@ -116,11 +116,22 @@ public: } /*! - * \brief Multiply with 3D vector operator * - * \param vector + * \brief Operator to support commutative multiplication + * \param factor + * \param otherMatrix * \return */ - template 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 ImplVector operator*(const ImplVector matrix) const; /*! * \brief Operator /= @@ -267,7 +278,7 @@ public: /*! * \brief Round all values */ - void round(); + ImplMatrix &round(); /*! * \brief Get element @@ -286,7 +297,8 @@ public: void setElement(size_t row, size_t column, double value); /*! - * \brief Get element by () + * \brief Get element by operator () modifying + * \param row * \param column * \return */ @@ -297,7 +309,8 @@ public: } /*! - * \brief Get element by () + * \brief Get element by operator () read only + * \param row * \param column * \return */ diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 240b5422b..b0a421550 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -33,7 +33,7 @@ protected: /*! * \brief Default constructor */ - CVector3DBase() {} + CVector3DBase() : m_i(0.0), m_j(0.0), m_k(0.0) {} /*! * \brief Constructor by values @@ -124,8 +124,8 @@ public: /*! - * \brief Get element by () - * \param column + * \brief Get row element by () + * \param row * \return */ double operator()(size_t row) const { return this->getElement(row); } @@ -272,6 +272,17 @@ public: 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 * \param divisor @@ -346,8 +357,7 @@ public: void matrixMultiplication(const CMatrix3x3 &matrix); /*! - * \brief Reciporcal value - * \param otherVector + * \brief Reciprocal value * \return */ ImplClass reciprocalValues() const @@ -394,15 +404,16 @@ public: /*! * \brief Round this vector + * \return */ - void round() + ImplClass &round() { const double epsilon = 1E-10; this->m_i = BlackMisc::Math::CMath::roundEpsilon(this->m_i, epsilon); this->m_j = BlackMisc::Math::CMath::roundEpsilon(this->m_j, epsilon); this->m_k = BlackMisc::Math::CMath::roundEpsilon(this->m_k, epsilon); + return static_cast(*this); } - }; } // namespace diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 8ae257476..5415325ea 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -219,7 +219,7 @@ public: qint32 convertedSiValueToInteger() const { return static_cast( - BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0)); + BlackMisc::Math::CMath::round(this->m_convertedSiUnitValueD, 0)); } /*! @@ -257,11 +257,11 @@ public: */ void substractUnitValue(double value); - /*! - * \brief Multiply operator *= - * \param multiply - * \return - */ + /*! + * \brief Multiply operator *= + * \param multiply + * \return + */ CPhysicalQuantity &operator *=(double multiply); /*! @@ -278,6 +278,17 @@ public: */ 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 / * \param divide diff --git a/tests/blackmisc/test_blackmisc.pro b/tests/blackmisc/test_blackmisc.pro index 041388c09..8a5299da1 100644 --- a/tests/blackmisc/test_blackmisc.pro +++ b/tests/blackmisc/test_blackmisc.pro @@ -6,18 +6,20 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -DEPENDPATH += . ../../src +DEPENDPATH += . ../../src/blackmisc INCLUDEPATH += . ../../src SOURCES += main.cpp testmain.cpp \ - testphysicalquantitiesbase.cpp \ - testaviationbase.cpp \ - testvectormatrixbase.cpp + testphysicalquantities.cpp \ + testvectormatrix.cpp \ + testaviation.cpp \ + testgeo.cpp HEADERS += testmain.h \ - testphysicalquantitiesbase.h \ blackmisctest.h \ - testaviationbase.h \ - testvectormatrixbase.h + testphysicalquantities.h \ + testvectormatrix.h \ + testaviation.h \ + testgeo.h win32-msvc* { PRE_TARGETDEPS += ../../lib/blackmisc.lib diff --git a/tests/blackmisc/testaviationbase.cpp b/tests/blackmisc/testaviation.cpp similarity index 91% rename from tests/blackmisc/testaviationbase.cpp rename to tests/blackmisc/testaviation.cpp index 3bea0e45c..af57f6a74 100644 --- a/tests/blackmisc/testaviationbase.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -3,7 +3,7 @@ * 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/. */ -#include "testaviationbase.h" +#include "testaviation.h" using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; @@ -13,7 +13,7 @@ namespace BlackMiscTest { /* * Constructor */ -CTestAviationBase::CTestAviationBase(QObject *parent): QObject(parent) +CTestAviation::CTestAviation(QObject *parent): QObject(parent) { // void } @@ -21,7 +21,7 @@ CTestAviationBase::CTestAviationBase(QObject *parent): QObject(parent) /* * Basic tests */ -void CTestAviationBase::headingBasics() +void CTestAviation::headingBasics() { CHeading h1(180, true, CAngleUnit::deg()); CHeading h2(180, false, CAngleUnit::deg()); @@ -45,7 +45,7 @@ void CTestAviationBase::headingBasics() /* * Vertical positions */ -void CTestAviationBase::verticalPosition() +void CTestAviation::verticalPosition() { CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 3000.0); CAviationVerticalPositions vp2 = vp1; @@ -55,7 +55,7 @@ void CTestAviationBase::verticalPosition() /* * COM and NAV units */ -void CTestAviationBase::comAndNav() +void CTestAviation::comAndNav() { CComSystem c1 = CComSystem::getCom1System(122.8); CComSystem c2 = CComSystem::getCom2System(122.8); @@ -72,7 +72,7 @@ void CTestAviationBase::comAndNav() /* * COM and NAV units */ -void CTestAviationBase::transponder() +void CTestAviation::transponder() { CTransponder t1 = CTransponder::getStandardTransponder(7000, CTransponder::StateStandby); CTransponder t2 = t1; diff --git a/tests/blackmisc/testaviationbase.h b/tests/blackmisc/testaviation.h similarity index 92% rename from tests/blackmisc/testaviationbase.h rename to tests/blackmisc/testaviation.h index f7f62e530..45ffbd2f0 100644 --- a/tests/blackmisc/testaviationbase.h +++ b/tests/blackmisc/testaviation.h @@ -20,7 +20,7 @@ namespace BlackMiscTest /*! * \brief Aviation classes basic tests */ -class CTestAviationBase : public QObject +class CTestAviation : public QObject { Q_OBJECT @@ -29,7 +29,7 @@ public: * \brief Standard test case constructor * \param parent */ - explicit CTestAviationBase(QObject *parent = 0); + explicit CTestAviation(QObject *parent = 0); private slots: /*! diff --git a/tests/blackmisc/testgeo.cpp b/tests/blackmisc/testgeo.cpp new file mode 100644 index 000000000..26d6c15e4 --- /dev/null +++ b/tests/blackmisc/testgeo.cpp @@ -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 diff --git a/tests/blackmisc/testgeo.h b/tests/blackmisc/testgeo.h new file mode 100644 index 000000000..6f426fe5c --- /dev/null +++ b/tests/blackmisc/testgeo.h @@ -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 + +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 diff --git a/tests/blackmisc/testmain.cpp b/tests/blackmisc/testmain.cpp index a4d0859d5..a290a10d4 100644 --- a/tests/blackmisc/testmain.cpp +++ b/tests/blackmisc/testmain.cpp @@ -14,12 +14,14 @@ int CTestMain::unitMain(int argc, char *argv[]) { int status = 0; { - CTestPhysicalQuantitiesBase pqBaseTests ; - CTestAviationBase avBaseTests; - CTestVectorMatrixBase vmTests; + CTestPhysicalQuantities pqBaseTests ; + CTestAviation avBaseTests; + CTestVectorMatrix vmTests; + CTestGeo geoTests; status |= QTest::qExec(&pqBaseTests, argc, argv); status |= QTest::qExec(&avBaseTests, argc, argv); status |= QTest::qExec(&vmTests, argc, argv); + status |= QTest::qExec(&geoTests, argc, argv); } return status; } diff --git a/tests/blackmisc/testmain.h b/tests/blackmisc/testmain.h index 259799c55..8849b1925 100644 --- a/tests/blackmisc/testmain.h +++ b/tests/blackmisc/testmain.h @@ -6,9 +6,10 @@ #ifndef BLACKMISCTEST_TESTMAIN_H #define BLACKMISCTEST_TESTMAIN_H -#include "testphysicalquantitiesbase.h" -#include "testaviationbase.h" -#include "testvectormatrixbase.h" +#include "testphysicalquantities.h" +#include "testaviation.h" +#include "testvectormatrix.h" +#include "testgeo.h" #include namespace BlackMiscTest diff --git a/tests/blackmisc/testphysicalquantitiesbase.cpp b/tests/blackmisc/testphysicalquantities.cpp similarity index 89% rename from tests/blackmisc/testphysicalquantitiesbase.cpp rename to tests/blackmisc/testphysicalquantities.cpp index 48d53e2b5..267de0b65 100644 --- a/tests/blackmisc/testphysicalquantitiesbase.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -3,7 +3,7 @@ * 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/. */ -#include "testphysicalquantitiesbase.h" +#include "testphysicalquantities.h" using namespace BlackMisc::PhysicalQuantities; @@ -13,7 +13,7 @@ namespace BlackMiscTest /* * Constructor */ -CTestPhysicalQuantitiesBase::CTestPhysicalQuantitiesBase(QObject *parent) : QObject(parent) +CTestPhysicalQuantities::CTestPhysicalQuantities(QObject *parent) : QObject(parent) { // void } @@ -21,9 +21,9 @@ CTestPhysicalQuantitiesBase::CTestPhysicalQuantitiesBase(QObject *parent) : QObj /* * 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 CLengthUnit du1 = CLengthUnit::m(); // Copy @@ -42,15 +42,15 @@ void CTestPhysicalQuantitiesBase::unitsBasics() /* * Distance tests */ -void CTestPhysicalQuantitiesBase::lengthBasics() +void CTestPhysicalQuantities::lengthBasics() { CLength d1(1, CLengthUnit::m()); // 1m CLength d2(100, CLengthUnit::cm()); CLength d3(1.852 * 1000, CLengthUnit::m()); // 1852m CLength d4(1, CLengthUnit::NM()); - QVERIFY2(d1 == d2, "1meter shall be 100cm"); QVERIFY2(d3 == d4, "1852meters shall be 1NM"); + QVERIFY2(d1 * 2 == 2 * d1, "Commutative multiplication"); d3 *= 2; // SI value d4 *= 2.0; // SI value ! @@ -73,7 +73,7 @@ void CTestPhysicalQuantitiesBase::lengthBasics() /* * Unit tests for speed */ -void CTestPhysicalQuantitiesBase::speedBasics() +void CTestPhysicalQuantities::speedBasics() { CSpeed s1(100, CSpeedUnit::km_h()); CSpeed s2(1000, CSpeedUnit::ft_min()); @@ -84,7 +84,7 @@ void CTestPhysicalQuantitiesBase::speedBasics() /* * Frequency unit tests */ -void CTestPhysicalQuantitiesBase::frequencyTests() +void CTestPhysicalQuantities::frequencyTests() { CFrequency f1(1, CFrequencyUnit::MHz()); QVERIFY2(f1.valueRounded(CFrequencyUnit::kHz(), 2) == 1000, "Mega is 1000kHz"); @@ -97,7 +97,7 @@ void CTestPhysicalQuantitiesBase::frequencyTests() /* * Angle tests */ -void CTestPhysicalQuantitiesBase::angleTests() +void CTestPhysicalQuantities::angleTests() { CAngle a1(180, CAngleUnit::deg()); CAngle a2(1.5 * CAngle::pi(), CAngleUnit::rad()); @@ -111,7 +111,7 @@ void CTestPhysicalQuantitiesBase::angleTests() /* * Weight tests */ -void CTestPhysicalQuantitiesBase::massTests() +void CTestPhysicalQuantities::massTests() { CMass w1(1000, CMassUnit::kg()); CMass w2(w1.unitValueToInteger(), CMassUnit::kg()); @@ -125,7 +125,7 @@ void CTestPhysicalQuantitiesBase::massTests() /* * Pressure tests */ -void CTestPhysicalQuantitiesBase::pressureTests() +void CTestPhysicalQuantities::pressureTests() { CPressure p1(1013.25, CPressureUnit::hPa()); CPressure p2(29.92, CPressureUnit::inHg()); @@ -142,7 +142,7 @@ void CTestPhysicalQuantitiesBase::pressureTests() /* * Temperature tests */ -void CTestPhysicalQuantitiesBase::temperatureTests() +void CTestPhysicalQuantities::temperatureTests() { CTemperature t1(0, CTemperatureUnit::C()); // 0C CTemperature t2(1, CTemperatureUnit::F()); // 1F @@ -157,7 +157,7 @@ void CTestPhysicalQuantitiesBase::temperatureTests() /* * Temperature tests */ -void CTestPhysicalQuantitiesBase::timeTests() +void CTestPhysicalQuantities::timeTests() { CTime t1(1, CTimeUnit::h()); QVERIFY2(t1.convertedSiValueToInteger() == 3600, "1hour shall be 3600s"); @@ -166,7 +166,7 @@ void CTestPhysicalQuantitiesBase::timeTests() /* * Just testing obvious memory create / destruct flaws */ -void CTestPhysicalQuantitiesBase::memoryTests() +void CTestPhysicalQuantities::memoryTests() { CLength *c = new CLength(100, CLengthUnit::m()); c->switchUnit(CLengthUnit::NM()); @@ -184,7 +184,7 @@ void CTestPhysicalQuantitiesBase::memoryTests() /* * @brief Just testing obvious memory create / destruct flaws */ -void CTestPhysicalQuantitiesBase::basicArithmetic() +void CTestPhysicalQuantities::basicArithmetic() { CPressure p1 = CPhysicalQuantitiesConstants::InternationalStandardSeaLevelPressure(); CPressure p2(p1); diff --git a/tests/blackmisc/testphysicalquantitiesbase.h b/tests/blackmisc/testphysicalquantities.h similarity index 90% rename from tests/blackmisc/testphysicalquantitiesbase.h rename to tests/blackmisc/testphysicalquantities.h index bc7cd7290..9a8f6c123 100644 --- a/tests/blackmisc/testphysicalquantitiesbase.h +++ b/tests/blackmisc/testphysicalquantities.h @@ -13,9 +13,9 @@ namespace BlackMiscTest { /*! - * \brief Physical quantities,basic tests + * \brief Physical quantities, basic tests */ -class CTestPhysicalQuantitiesBase : public QObject +class CTestPhysicalQuantities : public QObject { Q_OBJECT @@ -24,7 +24,8 @@ public: * \brief Standard test case constructor * \param parent */ - explicit CTestPhysicalQuantitiesBase(QObject *parent = 0); + explicit CTestPhysicalQuantities(QObject *parent = 0); + private slots: /*! * \brief Basic unit tests for physical units diff --git a/tests/blackmisc/testvectormatrixbase.cpp b/tests/blackmisc/testvectormatrix.cpp similarity index 89% rename from tests/blackmisc/testvectormatrixbase.cpp rename to tests/blackmisc/testvectormatrix.cpp index 7c25275b0..9cd78ad88 100644 --- a/tests/blackmisc/testvectormatrixbase.cpp +++ b/tests/blackmisc/testvectormatrix.cpp @@ -3,7 +3,7 @@ * 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/. */ -#include "testvectormatrixbase.h" +#include "testvectormatrix.h" using namespace BlackMisc::Math; @@ -13,12 +13,13 @@ namespace BlackMiscTest /* * Basic tests vector */ -void CTestVectorMatrixBase::vectorBasics() +void CTestVectorMatrix::vectorBasics() { CVector3D v1(1); v1 *= 2.0; CVector3D v2(2); QVERIFY2(v1 == v2, "Vectors should be equal"); + QVERIFY2(v1 * 2 == 2 * v2, "Commutative vector multiplication failed"); CVector3D v3(1, 1, 1); CVector3D v4(2, 2, 2); CVector3D v5 = v3.crossProduct(v4); @@ -33,7 +34,7 @@ void CTestVectorMatrixBase::vectorBasics() * Matrix tests * http://www.bluebit.gr/matrix-calculator/ */ -void CTestVectorMatrixBase::matrixBasics() +void CTestVectorMatrix::matrixBasics() { CMatrix3x3 m1; CMatrix3x3 m2 = m1 - m1; @@ -55,6 +56,7 @@ void CTestVectorMatrixBase::matrixBasics() m2 = m1 + m1; m1 = m1 * 2.0; QVERIFY2(m1 == m2, "2* Identity should be Identity + Identity"); + QVERIFY2(m1 * 2 == 2 * m1, "Commutative matrix multiplication failed"); m1 /= 2.0; m2 -= m1; diff --git a/tests/blackmisc/testvectormatrixbase.h b/tests/blackmisc/testvectormatrix.h similarity index 81% rename from tests/blackmisc/testvectormatrixbase.h rename to tests/blackmisc/testvectormatrix.h index f0080328e..616e5fbd5 100644 --- a/tests/blackmisc/testvectormatrixbase.h +++ b/tests/blackmisc/testvectormatrix.h @@ -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 @@ -24,13 +24,14 @@ public: * \brief Standard test case constructor * \param parent */ - explicit CTestVectorMatrixBase(QObject *parent = 0) : QObject(parent) {} + explicit CTestVectorMatrix(QObject *parent = 0) : QObject(parent) {} private slots: /*! * \brief Basic unit tests for physical units */ void vectorBasics(); + /*! * \brief Vertical positions */