SFML/test/TestUtilities/SystemUtil.cpp

50 lines
1.2 KiB
C++
Raw Normal View History

#include <SFML/System/Angle.hpp>
#include <SFML/System/String.hpp>
#include <SFML/System/Time.hpp>
2022-07-18 06:18:40 +08:00
#include <doctest/doctest.h>
2022-07-05 00:20:58 +08:00
#include <SystemUtil.hpp>
2021-12-24 21:31:27 +08:00
namespace sf
{
2022-07-05 13:46:34 +08:00
std::ostream& operator<<(std::ostream& os, const Angle& angle)
2022-07-05 00:20:58 +08:00
{
os << std::fixed << std::setprecision(std::numeric_limits<float>::max_digits10);
os << angle.asDegrees() << " deg";
return os;
}
2022-07-05 13:46:34 +08:00
std::ostream& operator<<(std::ostream& os, const String& string)
2022-07-05 00:20:58 +08:00
{
os << string.toAnsiString();
return os;
}
2022-07-05 13:46:34 +08:00
std::ostream& operator<<(std::ostream& os, Time time)
2022-07-05 00:20:58 +08:00
{
os << time.asMicroseconds() << "us";
return os;
}
2022-07-05 00:20:58 +08:00
} // namespace sf
bool operator==(const float& lhs, const Approx<float>& rhs)
{
return static_cast<double>(lhs) == doctest::Approx(static_cast<double>(rhs.value));
}
bool operator==(const sf::Vector2f& lhs, const Approx<sf::Vector2f>& rhs)
{
return (lhs - rhs.value).length() == Approx(0.f);
}
bool operator==(const sf::Vector3f& lhs, const Approx<sf::Vector3f>& rhs)
{
return (lhs - rhs.value).length() == Approx(0.f);
}
bool operator==(const sf::Angle& lhs, const Approx<sf::Angle>& rhs)
{
return lhs.asDegrees() == Approx(rhs.value.asDegrees());
}