Formatting: Apply pre-commit to tests/src
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <QString>
|
||||
#include "Base/Builder3D.h"
|
||||
#include <QString>
|
||||
|
||||
TEST(Builder, one){
|
||||
QString ss{};
|
||||
TEST(Builder, one)
|
||||
{
|
||||
QString ss {};
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <QLocale>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Quantity.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
#include <Base/UnitsSchemaImperial1.h>
|
||||
#include <QLocale>
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
|
||||
// NOLINTBEGIN
|
||||
TEST(BaseQuantity, TestValid)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Length};
|
||||
Base::Quantity q2{1.0, Base::Unit::Area};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Length};
|
||||
Base::Quantity q2 {1.0, Base::Unit::Area};
|
||||
q2.setInvalid();
|
||||
|
||||
EXPECT_EQ(q1.isValid(), true);
|
||||
@@ -22,74 +22,76 @@ TEST(BaseQuantity, TestParse)
|
||||
Base::Quantity q1 = Base::Quantity::parse(QString::fromLatin1("1,234 kg"));
|
||||
|
||||
EXPECT_EQ(q1, Base::Quantity(1.2340, Base::Unit::Mass));
|
||||
EXPECT_THROW(boost::ignore_unused(Base::Quantity::parse(QString::fromLatin1("1,234,500.12 kg"))), Base::ParserError);
|
||||
EXPECT_THROW(
|
||||
boost::ignore_unused(Base::Quantity::parse(QString::fromLatin1("1,234,500.12 kg"))),
|
||||
Base::ParserError);
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestDim)
|
||||
{
|
||||
Base::Quantity q1{0, Base::Unit::Area};
|
||||
Base::Quantity q1 {0, Base::Unit::Area};
|
||||
|
||||
EXPECT_EQ(q1.isQuantity(), true);
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestNoDim)
|
||||
{
|
||||
Base::Quantity q1{};
|
||||
Base::Quantity q1 {};
|
||||
|
||||
EXPECT_EQ(q1.pow(2), Base::Quantity{0});
|
||||
EXPECT_EQ(q1.pow(2), Base::Quantity {0});
|
||||
EXPECT_EQ(q1.isDimensionless(), true);
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestPowEQ1)
|
||||
{
|
||||
Base::Quantity q1{2, Base::Unit::Area};
|
||||
Base::Quantity q1 {2, Base::Unit::Area};
|
||||
EXPECT_EQ(q1.pow(1), Base::Quantity(2, Base::Unit::Area));
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestPowEQ0)
|
||||
{
|
||||
Base::Quantity q1{2, Base::Unit::Area};
|
||||
EXPECT_EQ(q1.pow(0), Base::Quantity{1});
|
||||
Base::Quantity q1 {2, Base::Unit::Area};
|
||||
EXPECT_EQ(q1.pow(0), Base::Quantity {1});
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestPowGT1)
|
||||
{
|
||||
Base::Quantity q1{2, Base::Unit::Length};
|
||||
Base::Quantity q1 {2, Base::Unit::Length};
|
||||
EXPECT_EQ(q1.pow(2), Base::Quantity(4, Base::Unit::Area));
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestPowLT1)
|
||||
{
|
||||
Base::Quantity q1{8, Base::Unit::Volume};
|
||||
EXPECT_EQ(q1.pow(1.0/3.0), Base::Quantity(2, Base::Unit::Length));
|
||||
Base::Quantity q1 {8, Base::Unit::Volume};
|
||||
EXPECT_EQ(q1.pow(1.0 / 3.0), Base::Quantity(2, Base::Unit::Length));
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestPow3DIV2)
|
||||
{
|
||||
Base::Quantity unit{8, Base::Unit::Volume};
|
||||
EXPECT_THROW(unit.pow(3.0/2.0), Base::UnitsMismatchError);
|
||||
Base::Quantity unit {8, Base::Unit::Volume};
|
||||
EXPECT_THROW(unit.pow(3.0 / 2.0), Base::UnitsMismatchError);
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestString)
|
||||
{
|
||||
Base::Quantity q1{2, QString::fromLatin1("kg*m/s^2")};
|
||||
Base::Quantity q1 {2, QString::fromLatin1("kg*m/s^2")};
|
||||
EXPECT_EQ(q1.getUnit(), Base::Unit::Force);
|
||||
|
||||
Base::Quantity q2{2, QString::fromLatin1("kg*m^2/s^2")};
|
||||
Base::Quantity q2 {2, QString::fromLatin1("kg*m^2/s^2")};
|
||||
EXPECT_EQ(q2.getUnit(), Base::Unit::Work);
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestCopy)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Length};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Length};
|
||||
|
||||
EXPECT_EQ(Base::Quantity{q1}, q1);
|
||||
EXPECT_EQ(Base::Quantity {q1}, q1);
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestEqual)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Force};
|
||||
Base::Quantity q2{1.0, QString::fromLatin1("kg*mm/s^2")};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Force};
|
||||
Base::Quantity q2 {1.0, QString::fromLatin1("kg*mm/s^2")};
|
||||
|
||||
EXPECT_EQ(q1 == q1, true);
|
||||
EXPECT_EQ(q1 == q2, true);
|
||||
@@ -97,9 +99,9 @@ TEST(BaseQuantity, TestEqual)
|
||||
|
||||
TEST(BaseQuantity, TestNotEqual)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Force};
|
||||
Base::Quantity q2{2.0, QString::fromLatin1("kg*m/s^2")};
|
||||
Base::Quantity q3{1.0, Base::Unit::Work};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Force};
|
||||
Base::Quantity q2 {2.0, QString::fromLatin1("kg*m/s^2")};
|
||||
Base::Quantity q3 {1.0, Base::Unit::Work};
|
||||
|
||||
EXPECT_EQ(q1 != q2, true);
|
||||
EXPECT_EQ(q1 != q3, true);
|
||||
@@ -107,9 +109,9 @@ TEST(BaseQuantity, TestNotEqual)
|
||||
|
||||
TEST(BaseQuantity, TestLessOrGreater)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Force};
|
||||
Base::Quantity q2{2.0, QString::fromLatin1("kg*m/s^2")};
|
||||
Base::Quantity q3{2.0, Base::Unit::Work};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Force};
|
||||
Base::Quantity q2 {2.0, QString::fromLatin1("kg*m/s^2")};
|
||||
Base::Quantity q3 {2.0, Base::Unit::Work};
|
||||
|
||||
EXPECT_EQ(q1 < q2, true);
|
||||
EXPECT_EQ(q1 > q2, false);
|
||||
@@ -123,8 +125,8 @@ TEST(BaseQuantity, TestLessOrGreater)
|
||||
|
||||
TEST(BaseQuantity, TestAdd)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Length};
|
||||
Base::Quantity q2{1.0, Base::Unit::Area};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Length};
|
||||
Base::Quantity q2 {1.0, Base::Unit::Area};
|
||||
EXPECT_THROW(q1 + q2, Base::UnitsMismatchError);
|
||||
EXPECT_THROW(q1 += q2, Base::UnitsMismatchError);
|
||||
EXPECT_EQ(q1 + q1, Base::Quantity(2, Base::Unit::Length));
|
||||
@@ -133,8 +135,8 @@ TEST(BaseQuantity, TestAdd)
|
||||
|
||||
TEST(BaseQuantity, TestSub)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Length};
|
||||
Base::Quantity q2{1.0, Base::Unit::Area};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Length};
|
||||
Base::Quantity q2 {1.0, Base::Unit::Area};
|
||||
EXPECT_THROW(q1 - q2, Base::UnitsMismatchError);
|
||||
EXPECT_THROW(q1 -= q2, Base::UnitsMismatchError);
|
||||
EXPECT_EQ(q1 - q1, Base::Quantity(0, Base::Unit::Length));
|
||||
@@ -143,51 +145,53 @@ TEST(BaseQuantity, TestSub)
|
||||
|
||||
TEST(BaseQuantity, TestNeg)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Length};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Length};
|
||||
EXPECT_EQ(-q1, Base::Quantity(-1.0, Base::Unit::Length));
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestMult)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Length};
|
||||
Base::Quantity q2{1.0, Base::Unit::Area};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Length};
|
||||
Base::Quantity q2 {1.0, Base::Unit::Area};
|
||||
EXPECT_EQ(q1 * q2, Base::Quantity(1.0, Base::Unit::Volume));
|
||||
EXPECT_EQ(q1 * 2.0, Base::Quantity(2.0, Base::Unit::Length));
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestDiv)
|
||||
{
|
||||
Base::Quantity q1{1.0, Base::Unit::Length};
|
||||
Base::Quantity q2{1.0, Base::Unit::Area};
|
||||
Base::Quantity q1 {1.0, Base::Unit::Length};
|
||||
Base::Quantity q2 {1.0, Base::Unit::Area};
|
||||
EXPECT_EQ(q1 / q2, Base::Quantity(1.0, Base::Unit::InverseLength));
|
||||
EXPECT_EQ(q1 / 2.0, Base::Quantity(0.5, Base::Unit::Length));
|
||||
}
|
||||
|
||||
TEST(BaseQuantity, TestPow)
|
||||
{
|
||||
Base::Quantity q1{2.0, Base::Unit::Length};
|
||||
Base::Quantity q2{2.0, Base::Unit::Area};
|
||||
Base::Quantity q3{0.0};
|
||||
EXPECT_EQ(q1.pow(q3), Base::Quantity{1});
|
||||
Base::Quantity q1 {2.0, Base::Unit::Length};
|
||||
Base::Quantity q2 {2.0, Base::Unit::Area};
|
||||
Base::Quantity q3 {0.0};
|
||||
EXPECT_EQ(q1.pow(q3), Base::Quantity {1});
|
||||
EXPECT_EQ(q1.pow(2.0), Base::Quantity(4, Base::Unit::Area));
|
||||
EXPECT_THROW(q1.pow(q2), Base::UnitsMismatchError);
|
||||
}
|
||||
|
||||
class Quantity : public ::testing::Test {
|
||||
class Quantity: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override {
|
||||
void SetUp() override
|
||||
{
|
||||
QLocale loc(QLocale::C);
|
||||
QLocale::setDefault(loc);
|
||||
}
|
||||
void TearDown() override {
|
||||
}
|
||||
void TearDown() override
|
||||
{}
|
||||
};
|
||||
|
||||
TEST_F(Quantity, TestSchemeImperialTwo)
|
||||
{
|
||||
Base::Quantity quantity{1.0, Base::Unit::Length};
|
||||
Base::Quantity quantity {1.0, Base::Unit::Length};
|
||||
|
||||
double factor{};
|
||||
double factor {};
|
||||
QString unitString;
|
||||
auto scheme = Base::UnitsApi::createSchema(Base::UnitSystem::ImperialDecimal);
|
||||
QString result = scheme->schemaTranslate(quantity, factor, unitString);
|
||||
@@ -196,13 +200,13 @@ TEST_F(Quantity, TestSchemeImperialTwo)
|
||||
|
||||
TEST_F(Quantity, TestSchemeImperialOne)
|
||||
{
|
||||
Base::Quantity quantity{1.0, Base::Unit::Length};
|
||||
Base::Quantity quantity {1.0, Base::Unit::Length};
|
||||
|
||||
Base::QuantityFormat format = quantity.getFormat();
|
||||
format.precision = 1;
|
||||
quantity.setFormat(format);
|
||||
|
||||
double factor{};
|
||||
double factor {};
|
||||
QString unitString;
|
||||
auto scheme = Base::UnitsApi::createSchema(Base::UnitSystem::ImperialDecimal);
|
||||
QString result = scheme->schemaTranslate(quantity, factor, unitString);
|
||||
@@ -214,7 +218,7 @@ TEST_F(Quantity, TestSafeUserString)
|
||||
{
|
||||
Base::UnitsApi::setSchema(Base::UnitSystem::ImperialDecimal);
|
||||
|
||||
Base::Quantity quantity{1.0, Base::Unit::Length};
|
||||
Base::Quantity quantity {1.0, Base::Unit::Length};
|
||||
Base::QuantityFormat format = quantity.getFormat();
|
||||
format.precision = 1;
|
||||
quantity.setFormat(format);
|
||||
|
||||
@@ -69,10 +69,10 @@ TEST(Rotation, TestUniformScaleLT1)
|
||||
TEST(Rotation, TestRotationFailure)
|
||||
{
|
||||
Base::Matrix4D mat;
|
||||
mat.setCol(0, Base::Vector3d{1, 0, 0});
|
||||
mat.setCol(1, Base::Vector3d{1, 1, 0});
|
||||
mat.setCol(2, Base::Vector3d{0, 0, 1});
|
||||
mat.setCol(0, Base::Vector3d {1, 0, 0});
|
||||
mat.setCol(1, Base::Vector3d {1, 1, 0});
|
||||
mat.setCol(2, Base::Vector3d {0, 0, 1});
|
||||
|
||||
EXPECT_THROW(Base::Rotation{mat}, Base::ValueError);
|
||||
EXPECT_THROW(Base::Rotation {mat}, Base::ValueError);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "Base/Unit.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <Base/Exception.h>
|
||||
|
||||
// NOLINTBEGIN
|
||||
@@ -8,17 +8,17 @@ TEST(Unit, TestString)
|
||||
auto toString = [](const Base::Unit& unit) {
|
||||
return unit.getString().toStdString();
|
||||
};
|
||||
EXPECT_EQ(toString(Base::Unit(0,0,0,0,0,0,0,0)), "");
|
||||
EXPECT_EQ(toString(Base::Unit(1,0,0,0,0,0,0,0)), "mm");
|
||||
EXPECT_EQ(toString(Base::Unit(0,1,0,0,0,0,0,0)), "kg");
|
||||
EXPECT_EQ(toString(Base::Unit(0,0,1,0,0,0,0,0)), "s");
|
||||
EXPECT_EQ(toString(Base::Unit(0,0,0,1,0,0,0,0)), "A");
|
||||
EXPECT_EQ(toString(Base::Unit(0,0,0,0,1,0,0,0)), "K");
|
||||
EXPECT_EQ(toString(Base::Unit(0,0,0,0,0,1,0,0)), "mol");
|
||||
EXPECT_EQ(toString(Base::Unit(0,0,0,0,0,0,1,0)), "cd");
|
||||
EXPECT_EQ(toString(Base::Unit(0,0,0,0,0,0,0,1)), "deg");
|
||||
EXPECT_EQ(toString(Base::Unit(2,0,0,0,0,0,0,0)), "mm^2");
|
||||
EXPECT_EQ(toString(Base::Unit(1,1,-2,0,0,0,0,0)), "mm*kg/s^2");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 0, 0, 0, 0, 0, 0, 0)), "");
|
||||
EXPECT_EQ(toString(Base::Unit(1, 0, 0, 0, 0, 0, 0, 0)), "mm");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 1, 0, 0, 0, 0, 0, 0)), "kg");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 0, 1, 0, 0, 0, 0, 0)), "s");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 0, 0, 1, 0, 0, 0, 0)), "A");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 0, 0, 0, 1, 0, 0, 0)), "K");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 0, 0, 0, 0, 1, 0, 0)), "mol");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 0, 0, 0, 0, 0, 1, 0)), "cd");
|
||||
EXPECT_EQ(toString(Base::Unit(0, 0, 0, 0, 0, 0, 0, 1)), "deg");
|
||||
EXPECT_EQ(toString(Base::Unit(2, 0, 0, 0, 0, 0, 0, 0)), "mm^2");
|
||||
EXPECT_EQ(toString(Base::Unit(1, 1, -2, 0, 0, 0, 0, 0)), "mm*kg/s^2");
|
||||
}
|
||||
|
||||
TEST(Unit, TestTypeString)
|
||||
@@ -29,7 +29,7 @@ TEST(Unit, TestTypeString)
|
||||
EXPECT_EQ(toString(Base::Unit::Acceleration), "Acceleration");
|
||||
EXPECT_EQ(toString(Base::Unit::AmountOfSubstance), "AmountOfSubstance");
|
||||
EXPECT_EQ(toString(Base::Unit::Angle), "Angle");
|
||||
EXPECT_EQ(toString(Base::Unit::AngleOfFriction), "Angle"); // same unit as Angle
|
||||
EXPECT_EQ(toString(Base::Unit::AngleOfFriction), "Angle");// same unit as Angle
|
||||
EXPECT_EQ(toString(Base::Unit::Area), "Area");
|
||||
EXPECT_EQ(toString(Base::Unit::CurrentDensity), "CurrentDensity");
|
||||
EXPECT_EQ(toString(Base::Unit::Density), "Density");
|
||||
@@ -55,136 +55,139 @@ TEST(Unit, TestTypeString)
|
||||
EXPECT_EQ(toString(Base::Unit::MagneticFieldStrength), "MagneticFieldStrength");
|
||||
EXPECT_EQ(toString(Base::Unit::MagneticFlux), "MagneticFlux");
|
||||
EXPECT_EQ(toString(Base::Unit::MagneticFluxDensity), "MagneticFluxDensity");
|
||||
EXPECT_EQ(toString(Base::Unit::Magnetization), "MagneticFieldStrength"); // same as MagneticFieldStrength
|
||||
EXPECT_EQ(toString(Base::Unit::Magnetization),
|
||||
"MagneticFieldStrength");// same as MagneticFieldStrength
|
||||
EXPECT_EQ(toString(Base::Unit::Mass), "Mass");
|
||||
EXPECT_EQ(toString(Base::Unit::Pressure), "Pressure");
|
||||
EXPECT_EQ(toString(Base::Unit::Power), "Power");
|
||||
EXPECT_EQ(toString(Base::Unit::ShearModulus), "Pressure"); // same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::ShearModulus), "Pressure");// same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::SpecificEnergy), "SpecificEnergy");
|
||||
EXPECT_EQ(toString(Base::Unit::SpecificHeat), "SpecificHeat");
|
||||
EXPECT_EQ(toString(Base::Unit::Stiffness), "Stiffness");
|
||||
EXPECT_EQ(toString(Base::Unit::Stress), "Pressure"); // same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::Stress), "Pressure");// same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::Temperature), "Temperature");
|
||||
EXPECT_EQ(toString(Base::Unit::ThermalConductivity), "ThermalConductivity");
|
||||
EXPECT_EQ(toString(Base::Unit::ThermalExpansionCoefficient), "ThermalExpansionCoefficient");
|
||||
EXPECT_EQ(toString(Base::Unit::ThermalTransferCoefficient), "ThermalTransferCoefficient");
|
||||
EXPECT_EQ(toString(Base::Unit::TimeSpan), "TimeSpan");
|
||||
EXPECT_EQ(toString(Base::Unit::UltimateTensileStrength), "Pressure"); // same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::UltimateTensileStrength), "Pressure");// same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::VacuumPermittivity), "VacuumPermittivity");
|
||||
EXPECT_EQ(toString(Base::Unit::Velocity), "Velocity");
|
||||
EXPECT_EQ(toString(Base::Unit::Volume), "Volume");
|
||||
EXPECT_EQ(toString(Base::Unit::VolumeFlowRate), "VolumeFlowRate");
|
||||
EXPECT_EQ(toString(Base::Unit::VolumetricThermalExpansionCoefficient), "ThermalExpansionCoefficient");
|
||||
EXPECT_EQ(toString(Base::Unit::VolumetricThermalExpansionCoefficient),
|
||||
"ThermalExpansionCoefficient");
|
||||
EXPECT_EQ(toString(Base::Unit::Work), "Work");
|
||||
EXPECT_EQ(toString(Base::Unit::YieldStrength), "Pressure"); // same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::YoungsModulus), "Pressure"); // same unit as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::YieldStrength), "Pressure");// same as Pressure
|
||||
EXPECT_EQ(toString(Base::Unit::YoungsModulus), "Pressure");// same unit as Pressure
|
||||
}
|
||||
TEST(Unit, strings){
|
||||
EXPECT_STREQ(Base::Unit::Acceleration.getString().toStdString().c_str() , "mm/s^2");
|
||||
EXPECT_STREQ(Base::Unit::AmountOfSubstance.getString().toStdString().c_str() , "mol");
|
||||
EXPECT_STREQ(Base::Unit::Angle.getString().toStdString().c_str() , "deg");
|
||||
EXPECT_STREQ(Base::Unit::AngleOfFriction.getString().toStdString().c_str() , "deg");
|
||||
EXPECT_STREQ(Base::Unit::Area.getString().toStdString().c_str() , "mm^2");
|
||||
EXPECT_STREQ(Base::Unit::CurrentDensity.getString().toStdString().c_str() , "A/mm^2");
|
||||
EXPECT_STREQ(Base::Unit::Density.getString().toStdString().c_str() , "kg/mm^3");
|
||||
EXPECT_STREQ(Base::Unit::DissipationRate.getString().toStdString().c_str() , "mm^2/s^3");
|
||||
TEST(Unit, strings)
|
||||
{
|
||||
EXPECT_STREQ(Base::Unit::Acceleration.getString().toStdString().c_str(), "mm/s^2");
|
||||
EXPECT_STREQ(Base::Unit::AmountOfSubstance.getString().toStdString().c_str(), "mol");
|
||||
EXPECT_STREQ(Base::Unit::Angle.getString().toStdString().c_str(), "deg");
|
||||
EXPECT_STREQ(Base::Unit::AngleOfFriction.getString().toStdString().c_str(), "deg");
|
||||
EXPECT_STREQ(Base::Unit::Area.getString().toStdString().c_str(), "mm^2");
|
||||
EXPECT_STREQ(Base::Unit::CurrentDensity.getString().toStdString().c_str(), "A/mm^2");
|
||||
EXPECT_STREQ(Base::Unit::Density.getString().toStdString().c_str(), "kg/mm^3");
|
||||
EXPECT_STREQ(Base::Unit::DissipationRate.getString().toStdString().c_str(), "mm^2/s^3");
|
||||
}
|
||||
|
||||
TEST(Unit, TestEqual)
|
||||
{
|
||||
Base::Unit unit{1};
|
||||
EXPECT_EQ(unit.pow(2) == Base::Unit{2}, true);
|
||||
Base::Unit unit {1};
|
||||
EXPECT_EQ(unit.pow(2) == Base::Unit {2}, true);
|
||||
}
|
||||
|
||||
TEST(Unit, TestNotEqual)
|
||||
{
|
||||
Base::Unit unit{1};
|
||||
EXPECT_EQ(unit.pow(2) != Base::Unit{1}, true);
|
||||
Base::Unit unit {1};
|
||||
EXPECT_EQ(unit.pow(2) != Base::Unit {1}, true);
|
||||
}
|
||||
|
||||
TEST(Unit, TestMult)
|
||||
{
|
||||
EXPECT_EQ(Base::Unit{} * Base::Unit{}, Base::Unit{});
|
||||
EXPECT_EQ(Base::Unit {} * Base::Unit {}, Base::Unit {});
|
||||
EXPECT_EQ(Base::Unit(0, 1) * Base::Unit(1, 0), Base::Unit(1, 1));
|
||||
}
|
||||
|
||||
TEST(Unit, TestDiv)
|
||||
{
|
||||
EXPECT_EQ(Base::Unit{} * Base::Unit{}, Base::Unit{});
|
||||
EXPECT_EQ(Base::Unit {} * Base::Unit {}, Base::Unit {});
|
||||
EXPECT_EQ(Base::Unit(0, 1) / Base::Unit(1, 0), Base::Unit(-1, 1));
|
||||
}
|
||||
|
||||
TEST(Unit, TestPowNoDim)
|
||||
{
|
||||
Base::Unit unit{};
|
||||
EXPECT_EQ(unit.pow(2), Base::Unit{0});
|
||||
Base::Unit unit {};
|
||||
EXPECT_EQ(unit.pow(2), Base::Unit {0});
|
||||
EXPECT_EQ(unit.isEmpty(), true);
|
||||
}
|
||||
|
||||
TEST(Unit, TestPowEQ1)
|
||||
{
|
||||
Base::Unit unit{2};
|
||||
EXPECT_EQ(unit.pow(1), Base::Unit{2});
|
||||
Base::Unit unit {2};
|
||||
EXPECT_EQ(unit.pow(1), Base::Unit {2});
|
||||
}
|
||||
|
||||
TEST(Unit, TestPowEQ0)
|
||||
{
|
||||
Base::Unit unit{2};
|
||||
EXPECT_EQ(unit.pow(0), Base::Unit{0});
|
||||
Base::Unit unit {2};
|
||||
EXPECT_EQ(unit.pow(0), Base::Unit {0});
|
||||
}
|
||||
|
||||
TEST(Unit, TestPowGT1)
|
||||
{
|
||||
Base::Unit unit{2};
|
||||
EXPECT_EQ(unit.pow(2), Base::Unit{4});
|
||||
Base::Unit unit {2};
|
||||
EXPECT_EQ(unit.pow(2), Base::Unit {4});
|
||||
}
|
||||
|
||||
TEST(Unit, TestPowLT1)
|
||||
{
|
||||
Base::Unit unit{3};
|
||||
EXPECT_EQ(unit.pow(1.0/3.0), Base::Unit{1});
|
||||
Base::Unit unit {3};
|
||||
EXPECT_EQ(unit.pow(1.0 / 3.0), Base::Unit {1});
|
||||
}
|
||||
|
||||
TEST(Unit, TestPow3DIV2)
|
||||
{
|
||||
Base::Unit unit{3};
|
||||
EXPECT_THROW(unit.pow(3.0/2.0), Base::UnitsMismatchError);
|
||||
Base::Unit unit {3};
|
||||
EXPECT_THROW(unit.pow(3.0 / 2.0), Base::UnitsMismatchError);
|
||||
}
|
||||
|
||||
TEST(Unit, TestOverflow)
|
||||
{
|
||||
// this tests _that_ the expected exception is thrown
|
||||
EXPECT_THROW({
|
||||
try
|
||||
EXPECT_THROW(
|
||||
{
|
||||
Base::Unit unit{3};
|
||||
unit.pow(10000);
|
||||
}
|
||||
catch (const Base::OverflowError& e)
|
||||
{
|
||||
// and this tests that it has the correct message
|
||||
EXPECT_STREQ( "Unit overflow in pow()", e.what());
|
||||
throw;
|
||||
}
|
||||
}, Base::OverflowError);
|
||||
try {
|
||||
Base::Unit unit {3};
|
||||
unit.pow(10000);
|
||||
}
|
||||
catch (const Base::OverflowError& e) {
|
||||
// and this tests that it has the correct message
|
||||
EXPECT_STREQ("Unit overflow in pow()", e.what());
|
||||
throw;
|
||||
}
|
||||
},
|
||||
Base::OverflowError);
|
||||
}
|
||||
|
||||
TEST(Unit, TestUnderflow)
|
||||
{
|
||||
// this tests _that_ the expected exception is thrown
|
||||
EXPECT_THROW({
|
||||
try
|
||||
EXPECT_THROW(
|
||||
{
|
||||
Base::Unit unit{3};
|
||||
unit.pow(-10000);
|
||||
}
|
||||
catch (const Base::UnderflowError& e)
|
||||
{
|
||||
// and this tests that it has the correct message
|
||||
EXPECT_STREQ( "Unit underflow in pow()", e.what());
|
||||
throw;
|
||||
}
|
||||
}, Base::UnderflowError);
|
||||
try {
|
||||
Base::Unit unit {3};
|
||||
unit.pow(-10000);
|
||||
}
|
||||
catch (const Base::UnderflowError& e) {
|
||||
// and this tests that it has the correct message
|
||||
EXPECT_STREQ("Unit underflow in pow()", e.what());
|
||||
throw;
|
||||
}
|
||||
},
|
||||
Base::UnderflowError);
|
||||
}
|
||||
|
||||
// NOLINTEND
|
||||
|
||||
Reference in New Issue
Block a user