Skip to content

Commit

Permalink
Add scaleLinear unit test with mixed unsigned types
Browse files Browse the repository at this point in the history
The integer promotion rules that apply to this case can trigger overflow issues with the previous `scaleLinear` code, though are correctly handled by the new update.
  • Loading branch information
DanRStevens committed Mar 5, 2025
1 parent 7acdda4 commit 40d4f21
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/Math/MathUtils.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ TEST(MathUtils, scaleLinearForwardUint32toUint8) {
EXPECT_EQ(uint8_t{255}, NAS2D::scaleLinear(uint32_t{10000}, uint32_t{0}, uint32_t{10000}, uint8_t{0}, uint8_t{255}));
}

TEST(MathUtils, scaleLinearReverseUint32toUint8) {
EXPECT_EQ(uint8_t{255}, NAS2D::scaleLinear(uint32_t{0}, uint32_t{0}, uint32_t{10000}, uint8_t{255}, uint8_t{0}));
EXPECT_EQ(uint8_t{191}, NAS2D::scaleLinear(uint32_t{2500}, uint32_t{0}, uint32_t{10000}, uint8_t{255}, uint8_t{0}));
EXPECT_EQ(uint8_t{127}, NAS2D::scaleLinear(uint32_t{5000}, uint32_t{0}, uint32_t{10000}, uint8_t{255}, uint8_t{0}));
EXPECT_EQ(uint8_t{63}, NAS2D::scaleLinear(uint32_t{7500}, uint32_t{0}, uint32_t{10000}, uint8_t{255}, uint8_t{0}));
EXPECT_EQ(uint8_t{0}, NAS2D::scaleLinear(uint32_t{10000}, uint32_t{0}, uint32_t{10000}, uint8_t{255}, uint8_t{0}));
}

TEST(MathUtils, scaleLinearFloatFahrenheitToCelsius) {
// Fahrenheit to Celsius
EXPECT_NEAR(-18.33333f, NAS2D::scaleLinear(-1.0f, 32.0f, 212.0f, 0.0f, 100.0f), 0.0001f);
Expand Down

0 comments on commit 40d4f21

Please sign in to comment.