From 9d0062a3b5c8a8dd72b84a61b9296c415862d44c Mon Sep 17 00:00:00 2001 From: Philip Top Date: Mon, 28 Aug 2023 06:47:29 -0700 Subject: [PATCH 1/7] change the order of to_string processing for meters and seconds to make some units containing combinations of those units work better. --- test/test_unit_strings.cpp | 10 ++++++++++ units/units.cpp | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/test_unit_strings.cpp b/test/test_unit_strings.cpp index 78d98d94..69c16f76 100644 --- a/test/test_unit_strings.cpp +++ b/test/test_unit_strings.cpp @@ -442,6 +442,15 @@ TEST(unitStrings, watthours) EXPECT_EQ(str, "GWh*m"); } +TEST(unitStrings, mm) +{ + auto speedUnit = unit_from_string("mm/s"); + EXPECT_EQ(to_string(speedUnit),"mm/s"); + + auto accUnit = unit_from_string("mm/s^2"); + EXPECT_EQ(to_string(accUnit),"mm/s^2"); +} + TEST(unitStrings, customUnits) { EXPECT_EQ(to_string(precise::generate_custom_unit(762)), "CXUN[762]"); @@ -1493,6 +1502,7 @@ TEST(commoditizedUnits, prefixed) EXPECT_TRUE(commu2.has_same_base(precise::data::byte)); } + TEST(commoditizedUnits, numericalWords) { auto commu = unit_from_string("20{unicorns}"); diff --git a/units/units.cpp b/units/units.cpp index 5ca4512f..4dc2c1ba 100644 --- a/units/units.cpp +++ b/units/units.cpp @@ -164,9 +164,10 @@ static const umap base_unit_names = getDefinedBaseUnitNames(); using ustr = std::pair; // units to divide into tests to explore common multiplier units -static UNITS_CPP14_CONSTEXPR_OBJECT std::array testUnits{ - {ustr{precise::m, "m"}, - ustr{precise::s, "s"}, +static UNITS_CPP14_CONSTEXPR_OBJECT std::array testUnits{ + {ustr{precise::s, "s"}, + ustr{precise::s.pow(2), "s^2"}, + ustr{precise::m, "m"}, ustr{precise::kg, "kg"}, ustr{precise::mol, "mol"}, ustr{precise::currency, "$"}, From dc45761d5c3a98edb239aa4e2822825420c28017 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 13:48:31 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/test_unit_strings.cpp | 5 ++--- units/units.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/test_unit_strings.cpp b/test/test_unit_strings.cpp index 69c16f76..fc22f4c9 100644 --- a/test/test_unit_strings.cpp +++ b/test/test_unit_strings.cpp @@ -445,10 +445,10 @@ TEST(unitStrings, watthours) TEST(unitStrings, mm) { auto speedUnit = unit_from_string("mm/s"); - EXPECT_EQ(to_string(speedUnit),"mm/s"); + EXPECT_EQ(to_string(speedUnit), "mm/s"); auto accUnit = unit_from_string("mm/s^2"); - EXPECT_EQ(to_string(accUnit),"mm/s^2"); + EXPECT_EQ(to_string(accUnit), "mm/s^2"); } TEST(unitStrings, customUnits) @@ -1502,7 +1502,6 @@ TEST(commoditizedUnits, prefixed) EXPECT_TRUE(commu2.has_same_base(precise::data::byte)); } - TEST(commoditizedUnits, numericalWords) { auto commu = unit_from_string("20{unicorns}"); diff --git a/units/units.cpp b/units/units.cpp index 4dc2c1ba..bc30bb77 100644 --- a/units/units.cpp +++ b/units/units.cpp @@ -166,7 +166,7 @@ using ustr = std::pair; // units to divide into tests to explore common multiplier units static UNITS_CPP14_CONSTEXPR_OBJECT std::array testUnits{ {ustr{precise::s, "s"}, - ustr{precise::s.pow(2), "s^2"}, + ustr{precise::s.pow(2), "s^2"}, ustr{precise::m, "m"}, ustr{precise::kg, "kg"}, ustr{precise::mol, "mol"}, From 97ac486d35d800c47e725dffac8ca390165cc417 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Mon, 28 Aug 2023 06:51:24 -0700 Subject: [PATCH 3/7] code comments and switch second order --- units/units.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/units/units.cpp b/units/units.cpp index 4dc2c1ba..20cb1c75 100644 --- a/units/units.cpp +++ b/units/units.cpp @@ -166,7 +166,7 @@ using ustr = std::pair; // units to divide into tests to explore common multiplier units static UNITS_CPP14_CONSTEXPR_OBJECT std::array testUnits{ {ustr{precise::s, "s"}, - ustr{precise::s.pow(2), "s^2"}, + ustr{precise::s.pow(2), "s^2"}, //second squared need to come before meter to deal with accelleration units ustr{precise::m, "m"}, ustr{precise::kg, "kg"}, ustr{precise::mol, "mol"}, @@ -199,8 +199,8 @@ static UNITS_CPP14_CONSTEXPR_OBJECT std::array testUnits{ // units to divide into tests to explore common multiplier units which can be // multiplied by power static UNITS_CPP14_CONSTEXPR_OBJECT std::array testPowerUnits{ - {ustr{precise::m, "m"}, - ustr{precise::s, "s"}, + {ustr{precise::s, "s"}, + ustr{precise::m, "m"}, ustr{precise::radian, "rad"}, ustr{precise::km, "km"}, ustr{precise::ft, "ft"}, From 2f898c8a03f6253e9778c0b02689655ed4cc9c1b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:42:37 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- units/units.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/units/units.cpp b/units/units.cpp index 20cb1c75..a83cce9e 100644 --- a/units/units.cpp +++ b/units/units.cpp @@ -166,7 +166,8 @@ using ustr = std::pair; // units to divide into tests to explore common multiplier units static UNITS_CPP14_CONSTEXPR_OBJECT std::array testUnits{ {ustr{precise::s, "s"}, - ustr{precise::s.pow(2), "s^2"}, //second squared need to come before meter to deal with accelleration units + ustr{precise::s.pow(2), "s^2"}, // second squared need to come before + // meter to deal with accelleration units ustr{precise::m, "m"}, ustr{precise::kg, "kg"}, ustr{precise::mol, "mol"}, From b20621ed9c4b21e3032bb2c3a805079720663abe Mon Sep 17 00:00:00 2001 From: Philip Top Date: Mon, 28 Aug 2023 07:45:29 -0700 Subject: [PATCH 5/7] fix suppressions --- config/cppcheck_suppressions.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/cppcheck_suppressions.txt b/config/cppcheck_suppressions.txt index a173c36d..8970af91 100644 --- a/config/cppcheck_suppressions.txt +++ b/config/cppcheck_suppressions.txt @@ -1,6 +1,6 @@ unusedFunction:units/x12_conv.cpp:1024 unusedFunction:units/r20_conv.cpp:2738 unusedFunction:units/x12_conv.cpp:1009 -passedByValue:units/units.cpp:223 -passedByValue:units/units.cpp:1155 -passedByValue:units/units.cpp:1172 +passedByValue:units/units.cpp:224 +passedByValue:units/units.cpp:1156 +passedByValue:units/units.cpp:1173 From b20477b08ce566345f61b8a0e9617ab028cb2900 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Tue, 29 Aug 2023 06:09:24 -0700 Subject: [PATCH 6/7] add a few more tests --- test/test_unit_strings.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_unit_strings.cpp b/test/test_unit_strings.cpp index fc22f4c9..063a19e2 100644 --- a/test/test_unit_strings.cpp +++ b/test/test_unit_strings.cpp @@ -449,6 +449,13 @@ TEST(unitStrings, mm) auto accUnit = unit_from_string("mm/s^2"); EXPECT_EQ(to_string(accUnit), "mm/s^2"); + + speedUnit = unit_from_string("km/s"); + EXPECT_EQ(to_string(speedUnit), "km/s"); + + accUnit = unit_from_string("km/s^2"); + EXPECT_EQ(to_string(accUnit), "km/s^2"); + } TEST(unitStrings, customUnits) From cceacf9de319144e0b07f043eae66cd70676ba95 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Aug 2023 13:09:45 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/test_unit_strings.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_unit_strings.cpp b/test/test_unit_strings.cpp index 063a19e2..5697562d 100644 --- a/test/test_unit_strings.cpp +++ b/test/test_unit_strings.cpp @@ -455,7 +455,6 @@ TEST(unitStrings, mm) accUnit = unit_from_string("km/s^2"); EXPECT_EQ(to_string(accUnit), "km/s^2"); - } TEST(unitStrings, customUnits)