Skip to content

Commit

Permalink
Clean up uint16_t test a little more
Browse files Browse the repository at this point in the history
  • Loading branch information
chiphogg committed Dec 11, 2023
1 parent bf30789 commit 7778d09
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions au/quantity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,10 @@ TEST(WillConversionTruncate, UsesModForIntegerTypes) {
TEST(IsConversionLossy, CorrectlyDiscriminatesBetweenLossyAndLosslessConversions) {
// We will check literally every representable value in the type, and make sure that the result
// of `is_conversion_lossy()` matches perfectly with the inability to recover the initial value.
auto test_round_trip_for_every_uint8_value = [](auto source_units, auto target_units) {
for (int i = 0; i <= 65535; ++i) {
auto test_round_trip_for_every_uint16_value = [](auto source_units, auto target_units) {
for (int i = std::numeric_limits<uint16_t>::lowest();
i <= std::numeric_limits<uint16_t>::max();
++i) {
const auto original = source_units(static_cast<uint16_t>(i));
const auto converted = original.coerce_as(target_units);
const auto round_trip = converted.coerce_as(source_units);
Expand All @@ -753,10 +755,10 @@ TEST(IsConversionLossy, CorrectlyDiscriminatesBetweenLossyAndLosslessConversions
};

// Inches-to-feet tests truncation.
test_round_trip_for_every_uint8_value(inches, feet);
test_round_trip_for_every_uint16_value(inches, feet);

// Feet-to-inches tests overflow.
test_round_trip_for_every_uint8_value(feet, inches);
test_round_trip_for_every_uint16_value(feet, inches);
}

TEST(AreQuantityTypesEquivalent, RequiresSameRepAndEquivalentUnits) {
Expand Down

0 comments on commit 7778d09

Please sign in to comment.