Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/files/fuzz_issues/meas_fail32
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pdu
2 changes: 1 addition & 1 deletion test/fuzz_issue_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ TEST_P(measProblems, measFiles)
}
}

INSTANTIATE_TEST_SUITE_P(measFiles, measProblems, ::testing::Range(0, 32));
INSTANTIATE_TEST_SUITE_P(measFiles, measProblems, ::testing::Range(0, 33));

class meas64Problems : public ::testing::TestWithParam<int> {};

Expand Down
6 changes: 6 additions & 0 deletions test/test_unit_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,12 @@ TEST(specialOps, rootHertz)
// EXPECT_EQ(rh.pow(-6), s.pow(3));
}

TEST(specialOps, degC)
{
auto res = precise::degC.pow(2);
EXPECT_EQ(root(res, 2), precise::degC);
}

TEST(customUnits, definition)
{
auto cunit1 = precise::generate_custom_unit(4);
Expand Down
6 changes: 6 additions & 0 deletions test/test_unit_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ TEST(stringToUnits, hartree)
EXPECT_EQ(precise::energy::hartree, unit_from_string("E_h"));
}

TEST(stringToUnits, degC)
{
EXPECT_EQ(precise::degC, root(unit_from_string("degC^2"), 2));
EXPECT_EQ(to_string(precise::degC.pow(2)), "degC^2");
}

TEST(stringToUnits, conventional)
{
EXPECT_EQ(precise::conventional::coulomb90, unit_from_string("C_90"));
Expand Down
7 changes: 5 additions & 2 deletions units/unit_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,11 @@ namespace precise {
constexpr precise_unit psig = psi * eflag;
constexpr precise_unit inHg{3376.849669, Pa}; // at 60 degF
constexpr precise_unit mmHg{133.322387415, Pa};
constexpr precise_unit torr{1.0 / 760.0, atm* iflag}; // this is really
// close to mmHg
constexpr precise_unit torr{
1.0 / 760.0,
atm* iflag}; // this is really
// close to mmHg and can't use eflag since that means
// guage
constexpr precise_unit inH2O{248.843004, Pa}; // at 60 degF
constexpr precise_unit mmH2O{1.0 / 25.4, inH2O}; // at 60 degF

Expand Down
12 changes: 9 additions & 3 deletions units/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3286,10 +3286,16 @@ static bool cleanSpaces(std::string& unit_string, bool skipMultiply)
}
}
}
unit_string.erase(fnd, 1);
if (fnd > 0) {
skipMultiply = true;
if (fnd > 0 && unit_string[fnd - 1] == '.') {
// this now gets dealt with in the dotMultiply code
++fnd;
} else {
unit_string.erase(fnd, 1);
if (fnd > 0) {
skipMultiply = true;
}
}

fnd = unit_string.find_first_of(spaceChars, fnd);
}
return spacesRemoved;
Expand Down
4 changes: 2 additions & 2 deletions units/units_conversion_maps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SPDX-License-Identifier: BSD-3-Clause

namespace UNITS_NAMESPACE {

UNITS_CPP14_CONSTEXPR_OBJECT std::array<std::pair<unit, const char*>, 111>
UNITS_CPP14_CONSTEXPR_OBJECT std::array<std::pair<unit, const char*>, 112>
defined_unit_names_si{
{{m, "m"},
{m * m, "m^2"},
Expand Down Expand Up @@ -69,7 +69,7 @@ UNITS_CPP14_CONSTEXPR_OBJECT std::array<std::pair<unit, const char*>, 111>
{deg, "deg"},
{rad, "rad"},
{degC, u8"\u00B0C"},

{degC.pow(2), "degC^2"},
{cm, "cm"},
{km, "km"},
{km * km, "km^2"},
Expand Down
11 changes: 6 additions & 5 deletions units/units_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace detail {
radians_ + other.radians_,
static_cast<unsigned int>(per_unit_ | other.per_unit_),
static_cast<unsigned int>(i_flag_ ^ other.i_flag_),
static_cast<unsigned int>(e_flag_ ^ other.e_flag_),
static_cast<unsigned int>(e_flag_ | other.e_flag_),
static_cast<unsigned int>(equation_ | other.equation_),
};
}
Expand All @@ -171,7 +171,7 @@ namespace detail {
radians_ - other.radians_,
static_cast<unsigned int>(per_unit_ | other.per_unit_),
static_cast<unsigned int>(i_flag_ ^ other.i_flag_),
static_cast<unsigned int>(e_flag_ ^ other.e_flag_),
static_cast<unsigned int>(e_flag_ | other.e_flag_),
static_cast<unsigned int>(equation_ | other.equation_),
};
}
Expand Down Expand Up @@ -211,7 +211,8 @@ namespace detail {
radians_ * power,
per_unit_,
(power % 2 == 0) ? 0U : i_flag_,
(power % 2 == 0) ? 0U : e_flag_,
(power % 2 == 0) ? ((i_flag_ && e_flag_) ? 0U : e_flag_) :
e_flag_,
equation_};
}
constexpr unit_data root(int power) const
Expand All @@ -229,7 +230,7 @@ namespace detail {
radians_ / power,
per_unit_,
(power % 2 == 0) ? 0U : i_flag_,
(power % 2 == 0) ? 0U : e_flag_,
e_flag_,
0) :
unit_data(nullptr);
}
Expand Down Expand Up @@ -373,7 +374,7 @@ namespace detail {
candela_ % power == 0 && kelvin_ % power == 0 &&
mole_ % power == 0 && radians_ % power == 0 &&
currency_ % power == 0 && count_ % power == 0 &&
equation_ == 0U && e_flag_ == 0U;
equation_ == 0U;
}
constexpr int rootHertzModifier(int power) const
{
Expand Down