mirror of
https://github.com/SFML/SFML.git
synced 2025-01-18 23:35:11 +08:00
Use approximation when comparing floats in tests
This commit is contained in:
parent
722ab54f84
commit
b56604c940
@ -149,9 +149,9 @@ TEST_CASE("[Graphics] sf::Glsl")
|
|||||||
{
|
{
|
||||||
constexpr sf::Glsl::Vec4 vec = sf::Color(0, 128, 192, 255);
|
constexpr sf::Glsl::Vec4 vec = sf::Color(0, 128, 192, 255);
|
||||||
STATIC_CHECK(vec.x == 0.f);
|
STATIC_CHECK(vec.x == 0.f);
|
||||||
STATIC_CHECK(vec.y == 128 / 255.f);
|
|
||||||
STATIC_CHECK(vec.z == 192 / 255.f);
|
|
||||||
STATIC_CHECK(vec.w == 1.f);
|
STATIC_CHECK(vec.w == 1.f);
|
||||||
|
CHECK(vec.y == Approx(128 / 255.f));
|
||||||
|
CHECK(vec.z == Approx(192 / 255.f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,8 +229,8 @@ TEST_CASE("[System] sf::Angle")
|
|||||||
SECTION("operator/")
|
SECTION("operator/")
|
||||||
{
|
{
|
||||||
STATIC_CHECK(sf::Angle::Zero / 10 == sf::Angle::Zero);
|
STATIC_CHECK(sf::Angle::Zero / 10 == sf::Angle::Zero);
|
||||||
STATIC_CHECK(sf::degrees(10) / 2.5f == sf::degrees(4));
|
|
||||||
STATIC_CHECK(sf::radians(12) / 3 == sf::radians(4));
|
STATIC_CHECK(sf::radians(12) / 3 == sf::radians(4));
|
||||||
|
CHECK(sf::degrees(10) / 2.5f == Approx(sf::degrees(4)));
|
||||||
|
|
||||||
STATIC_CHECK(sf::Angle::Zero / sf::degrees(1) == 0.f);
|
STATIC_CHECK(sf::Angle::Zero / sf::degrees(1) == 0.f);
|
||||||
STATIC_CHECK(sf::degrees(10) / sf::degrees(10) == 1.f);
|
STATIC_CHECK(sf::degrees(10) / sf::degrees(10) == 1.f);
|
||||||
|
@ -50,7 +50,7 @@ TEST_CASE("[System] sf::Time")
|
|||||||
SECTION("Construct from milliseconds")
|
SECTION("Construct from milliseconds")
|
||||||
{
|
{
|
||||||
constexpr sf::Time time = sf::milliseconds(42);
|
constexpr sf::Time time = sf::milliseconds(42);
|
||||||
STATIC_CHECK(time.asSeconds() == 0.042f);
|
CHECK(time.asSeconds() == Approx(0.042f));
|
||||||
STATIC_CHECK(time.asMilliseconds() == 42);
|
STATIC_CHECK(time.asMilliseconds() == 42);
|
||||||
STATIC_CHECK(time.asMicroseconds() == 42'000);
|
STATIC_CHECK(time.asMicroseconds() == 42'000);
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ TEST_CASE("[System] sf::Time")
|
|||||||
SECTION("Construct from microseconds")
|
SECTION("Construct from microseconds")
|
||||||
{
|
{
|
||||||
constexpr sf::Time time = sf::microseconds(987654);
|
constexpr sf::Time time = sf::microseconds(987654);
|
||||||
STATIC_CHECK(time.asSeconds() == 0.987654f);
|
CHECK(time.asSeconds() == Approx(0.987654f));
|
||||||
STATIC_CHECK(time.asMilliseconds() == 987);
|
STATIC_CHECK(time.asMilliseconds() == 987);
|
||||||
STATIC_CHECK(time.asMicroseconds() == 987'654);
|
STATIC_CHECK(time.asMicroseconds() == 987'654);
|
||||||
}
|
}
|
||||||
@ -79,13 +79,13 @@ TEST_CASE("[System] sf::Time")
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr sf::Time time = 10ms;
|
constexpr sf::Time time = 10ms;
|
||||||
STATIC_CHECK(time.asSeconds() == 0.01f);
|
CHECK(time.asSeconds() == Approx(0.01f));
|
||||||
STATIC_CHECK(time.asMilliseconds() == 10);
|
STATIC_CHECK(time.asMilliseconds() == 10);
|
||||||
STATIC_CHECK(time.asMicroseconds() == 10'000);
|
STATIC_CHECK(time.asMicroseconds() == 10'000);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr sf::Time time = 2048us;
|
constexpr sf::Time time = 2048us;
|
||||||
STATIC_CHECK(time.asSeconds() == 0.002048f);
|
CHECK(time.asSeconds() == Approx(0.002048f));
|
||||||
STATIC_CHECK(time.asMilliseconds() == 2);
|
STATIC_CHECK(time.asMilliseconds() == 2);
|
||||||
STATIC_CHECK(time.asMicroseconds() == 2048);
|
STATIC_CHECK(time.asMicroseconds() == 2048);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user