Merge pull request #23384 from 3x380V/units

Base: Units update
This commit is contained in:
Chris Hennes
2025-09-07 20:22:54 -05:00
committed by GitHub
21 changed files with 309 additions and 293 deletions

View File

@@ -198,25 +198,25 @@ protected:
TEST_F(BaseQuantityLoc, psi_parse_spaced)
{
const auto qParsed = Quantity::parse("1 psi");
EXPECT_EQ(qParsed.getValue(), 6.8947448254939996);
EXPECT_EQ(qParsed.getValue(), 6.8947572931683609);
}
TEST_F(BaseQuantityLoc, psi_parse_no_space)
{
const auto qParsed = Quantity::parse("1psi");
EXPECT_EQ(qParsed.getValue(), 6.8947448254939996);
EXPECT_EQ(qParsed.getValue(), 6.8947572931683609);
}
TEST_F(BaseQuantityLoc, psi_parse_user_str)
{
const auto qParsed = Quantity::parse("1 psi");
EXPECT_EQ(qParsed.getUserString(), "6894.74 Pa");
EXPECT_EQ(qParsed.getUserString(), "6894.76 Pa");
}
TEST_F(BaseQuantityLoc, psi_parse_safe_user_str)
{
const auto qParsed = Quantity::parse("1 psi");
EXPECT_EQ(qParsed.getSafeUserString(), "6894.74 Pa");
EXPECT_EQ(qParsed.getSafeUserString(), "6894.76 Pa");
}
TEST_F(BaseQuantityLoc, psi_parse_unit_type)
@@ -228,7 +228,7 @@ TEST_F(BaseQuantityLoc, psi_parse_unit_type)
TEST_F(BaseQuantityLoc, psi_to_Pa)
{
const auto result = Quantity::parse("1 psi").getValueAs(Quantity::Pascal);
const auto expect = 6894.7448254939991;
const auto expect = 6894.7572931683608;
EXPECT_EQ(result, expect);
}
@@ -236,7 +236,7 @@ TEST_F(BaseQuantityLoc, psi_to_Pa)
TEST_F(BaseQuantityLoc, psi_to_KPa)
{
const auto result = Quantity::parse("1 psi").getValueAs(Quantity::KiloPascal);
const auto expect = 6.8947448254939996;
const auto expect = 6.8947572931683609;
EXPECT_EQ(result, expect);
}
@@ -244,7 +244,7 @@ TEST_F(BaseQuantityLoc, psi_to_KPa)
TEST_F(BaseQuantityLoc, psi_to_MPa)
{
const auto result = Quantity::parse("1 psi").getValueAs(Quantity::MegaPascal);
const auto expect = 0.0068947448254939999;
const auto expect = 0.0068947572931683607;
EXPECT_EQ(result, expect);
}

View File

@@ -69,7 +69,7 @@ protected:
UnitsApi::setSchema(name);
Quantity quantity {value, unit};
QuantityFormat format = quantity.getFormat();
format.precision = precision;
format.setPrecision(precision);
quantity.setFormat(format);
return quantity.getSafeUserString();
}
@@ -298,7 +298,7 @@ TEST_F(SchemaTest, imperial_decimal_0_mm_precision_1)
TEST_F(SchemaTest, imperial_civil_0_mm_precision_0)
{
const std::string result = setWithPrecision("ImperialCivil", 0.0, Unit::Length, 0);
const auto expect {"0 mm"};
const auto expect {"0 ft"};
EXPECT_EQ(result, expect);
}
@@ -306,7 +306,7 @@ TEST_F(SchemaTest, imperial_civil_0_mm_precision_0)
TEST_F(SchemaTest, imperial_civil_0_mm_precision_1)
{
const std::string result = setWithPrecision("ImperialCivil", 0.0, Unit::Length, 1);
const auto expect {"0.0 mm"};
const auto expect {"0.0 ft"};
EXPECT_EQ(result, expect);
}

View File

@@ -51,18 +51,18 @@ private Q_SLOTS:
{
auto quant = qsb->value();
auto format = quant.getFormat();
format.precision = 7;
format.setPrecision(7);
quant.setFormat(format);
qsb->setValue(quant);
auto val1 = qsb->value();
QCOMPARE(val1.getFormat().precision, 7);
QCOMPARE(val1.getFormat().getPrecision(), 7);
// format shouldn't change after setting a double
qsb->setValue(3.5);
auto val2 = qsb->value();
QCOMPARE(val2.getFormat().precision, 7);
QCOMPARE(val2.getFormat().getPrecision(), 7);
}
private: