Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 23, 2023
1 parent 3a17e7e commit 78031ed
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 232 deletions.
9 changes: 3 additions & 6 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set(UNITS_TESTS
test_google_units
)

if (NOT UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
if(NOT UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
list(APPEND UNITS_TESTS test_r20)
endif()

Expand Down Expand Up @@ -72,10 +72,8 @@ else()
target_compile_definitions(
test_unit_strings PUBLIC -DENABLE_UNIT_TESTING=1 -DENABLE_UNIT_MAP_ACCESS=1
)
if (NOT UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
target_compile_definitions (
test_r20 PUBLIC -DENABLE_UNIT_MAP_ACCESS=1
)
if(NOT UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
target_compile_definitions(test_r20 PUBLIC -DENABLE_UNIT_MAP_ACCESS=1)
endif()

add_unit_test(test_leadingNumbers.cpp)
Expand All @@ -91,7 +89,6 @@ else()
endif()
endif()


target_compile_definitions(
test_conversions2 PUBLIC -DTEST_FILE_FOLDER="${TEST_FILE_FOLDER}"
)
Expand Down
2 changes: 1 addition & 1 deletion test/test_r20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ TEST(r20, conversions)
std::cout << correct << " r20 units correctly translated\n";
}

#endif
#endif
62 changes: 30 additions & 32 deletions test/test_udunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TEST(UDUNITS, acceptedAlias)
auto err = doc.LoadFile(TEST_FILE_FOLDER "/UDUNITS2/udunits2-accepted.xml");
ASSERT_FALSE(err) << err << std::endl;
auto cs = doc.FirstChildElement("unit-system")->FirstChildElement("unit");
int failConvert{ 0 };
int failConvert{0};
while (cs != nullptr) {
std::string def = cs->FirstChildElement("def")->FirstChild()->Value();

Expand Down Expand Up @@ -265,7 +265,7 @@ TEST(UDUNITS, commonAlias)
auto err = doc.LoadFile(TEST_FILE_FOLDER "/UDUNITS2/udunits2-common.xml");
ASSERT_FALSE(err) << err << std::endl;
auto cs = doc.FirstChildElement("unit-system")->FirstChildElement("unit");
int failConvert{ 0 };
int failConvert{0};
int mismatchUnit{0};
int mismatchVal{0};
while (cs != nullptr) {
Expand All @@ -290,16 +290,15 @@ TEST(UDUNITS, commonAlias)
} else {
if (convert(unit_cast(nameUnit), unit_cast(definitionUnit)) !=
1.0) {
if (definitionUnit.has_same_base(nameUnit))
{
std::cout << "singular name and unit multiplier do not match " << sname
<< " and " << def << "\n";
if (definitionUnit.has_same_base(nameUnit)) {
std::cout
<< "singular name and unit multiplier do not match "
<< sname << " and " << def << "\n";
++mismatchVal;
}
else
{
std::cout << "singular name and unit do not have the same base units " << sname
<< " and " << def << "\n";
} else {
std::cout
<< "singular name and unit do not have the same base units "
<< sname << " and " << def << "\n";
++mismatchUnit;
}
}
Expand All @@ -316,16 +315,15 @@ TEST(UDUNITS, commonAlias)
if (convert(
unit_cast(nameUnit), unit_cast(definitionUnit)) !=
1.0) {
if (definitionUnit.has_same_base(nameUnit))
{
std::cout << "plural name and unit multiplier do not match " << sname
<< " and " << def << "\n";
if (definitionUnit.has_same_base(nameUnit)) {
std::cout
<< "plural name and unit multiplier do not match "
<< sname << " and " << def << "\n";
++mismatchVal;
}
else
{
std::cout << "plural name and unit do not have the same base units " << sname
<< " and " << def << "\n";
} else {
std::cout
<< "plural name and unit do not have the same base units "
<< sname << " and " << def << "\n";
++mismatchUnit;
}
}
Expand All @@ -345,16 +343,15 @@ TEST(UDUNITS, commonAlias)
} else {
if (convert(unit_cast(symUnit), unit_cast(definitionUnit)) !=
1.0) {
if (definitionUnit.has_same_base(symUnit))
{
std::cout << "symbol and unit multiplier do not mismatch" << symString
<< " and " << def << "\n";
if (definitionUnit.has_same_base(symUnit)) {
std::cout
<< "symbol and unit multiplier do not mismatch"
<< symString << " and " << def << "\n";
++mismatchVal;
}
else
{
std::cout << "symbol and unit do not have the same base units " << symString
<< " and " << def << "\n";
} else {
std::cout
<< "symbol and unit do not have the same base units "
<< symString << " and " << def << "\n";
++mismatchUnit;
}
std::cout << "symbol and unit do not match " << symString
Expand All @@ -368,13 +365,14 @@ TEST(UDUNITS, commonAlias)
cs = cs->NextSiblingElement("unit");
}
if (failConvert > 0) {
std::cout <<failConvert<< " units were unable to convert at all\n";
std::cout << failConvert << " units were unable to convert at all\n";
}
if (mismatchUnit > 0) {
std::cout << mismatchUnit<< " units converted but had different base units\n";
std::cout << mismatchUnit
<< " units converted but had different base units\n";
}
if (mismatchVal > 0) {
std::cout << mismatchVal<< " units had different multipliers\n";
std::cout << mismatchVal << " units had different multipliers\n";
}
// EXPECT_EQ(failConvert, 0);
}
20 changes: 13 additions & 7 deletions test/test_unit_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,20 @@ TEST(stringToUnits, Simple)

TEST(stringToUnits, pressure)
{

EXPECT_EQ(unit_from_string("M[HG]"),unit_from_string("meter of mercury column"));
EXPECT_EQ(unit_from_string("M[HG]",units::case_insensitive),unit_from_string("meter of mercury column"));
EXPECT_EQ(unit_from_string("millimeter_Hg_0C"),precise::pressure::mmHg);
EXPECT_EQ(unit_from_string("MM[HG]",units::case_insensitive),unit_from_string("millimeter of mercury column"));
EXPECT_EQ(
unit_from_string("M[HG]"), unit_from_string("meter of mercury column"));
EXPECT_EQ(
unit_from_string("M[HG]", units::case_insensitive),
unit_from_string("meter of mercury column"));
EXPECT_EQ(unit_from_string("millimeter_Hg_0C"), precise::pressure::mmHg);
EXPECT_EQ(
unit_from_string("MM[HG]", units::case_insensitive),
unit_from_string("millimeter of mercury column"));
}

TEST(stringToUnit, fluid)
{
EXPECT_EQ(unit_from_string("US_fluid_ounce"),precise::us::floz);
EXPECT_EQ(unit_from_string("US_fluid_ounce"), precise::us::floz);
}

TEST(stringToUnits, withSpace)
Expand Down Expand Up @@ -591,7 +595,9 @@ TEST(stringToUnits, specificCombinations)

TEST(stringToUnits, barrels)
{
EXPECT_EQ(precise::kilo*precise::us::barrel/precise::day, unit_from_string("kbbl (US)/d"));
EXPECT_EQ(
precise::kilo * precise::us::barrel / precise::day,
unit_from_string("kbbl (US)/d"));
}
TEST(stringToUnits, gasConstant)
{
Expand Down
13 changes: 6 additions & 7 deletions units/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
# SPDX-License-Identifier: BSD-3-Clause
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
set(units_source_files units.cpp commodities.cpp)
if(UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
set(units_source_files units.cpp commodities.cpp)
else()
set(units_source_files units.cpp commodities.cpp x12_conv.cpp r20_conv.cpp)
endif()
endif()

set(units_header_files
units.hpp
Expand Down Expand Up @@ -66,7 +65,7 @@ if(UNITS_BUILD_SHARED_LIBRARY)
if(UNITS_DISABLE_NON_ENGLISH_UNITS)
target_compile_definitions(units PUBLIC -DUNITS_DISABLE_NON_ENGLISH_UNITS=1)
endif()
if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
if(UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
target_compile_definitions(units PUBLIC -DUNITS_DISABLE_EXTRA_UNIT_STANDARDS=1)
endif()
if(UNITS_DEFAULT_DOMAIN)
Expand Down Expand Up @@ -115,7 +114,7 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY)
if(UNITS_DISABLE_NON_ENGLISH_UNITS)
target_compile_definitions(units PUBLIC -DUNITS_DISABLE_NON_ENGLISH_UNITS=1)
endif()
if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
if(UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
target_compile_definitions(units PUBLIC -DUNITS_DISABLE_EXTRA_UNIT_STANDARDS=1)
endif()
if(${CMAKE_CXX_STANDARD} GREATER 16)
Expand All @@ -142,7 +141,7 @@ elseif(UNITS_BUILD_STATIC_LIBRARY)
if(UNITS_BASE_TYPE)
target_compile_definitions(units PUBLIC -DUNITS_BASE_TYPE=${UNITS_BASE_TYPE})
endif()
if (UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
if(UNITS_DISABLE_EXTRA_UNIT_STANDARDS)
target_compile_definitions(units PUBLIC -DUNITS_DISABLE_EXTRA_UNIT_STANDARDS=1)
endif()
if(UNITS_DEFAULT_DOMAIN)
Expand Down
10 changes: 5 additions & 5 deletions units/r20_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3141,11 +3141,11 @@ precise_unit r20_unit(const std::string& r20_string)

#ifdef ENABLE_UNIT_MAP_ACCESS
namespace detail {
const void* r20rawData(size_t& array_size)
{
array_size = precise::r20_units.size();
return precise::r20_units.data();
}
const void* r20rawData(size_t& array_size)
{
array_size = precise::r20_units.size();
return precise::r20_units.data();
}
} // namespace detail

#endif
Expand Down
Loading

0 comments on commit 78031ed

Please sign in to comment.