1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-03 17:37:18 +00:00
OpenMW/apps/openmw_tests/mwworld/testduration.cpp
elsid 7d1cd11ba9
Split openmw_test_suite into openmw and components tests
To avoid duplicated compilation for openmw translation units. Link openmw-lib to
openmw-tests instead.
2024-06-10 23:12:14 +02:00

64 lines
2.3 KiB
C++

#include <gtest/gtest.h>
#include <cmath>
#include "apps/openmw/mwworld/duration.hpp"
namespace MWWorld
{
namespace
{
TEST(MWWorldDurationTest, fromHoursShouldProduceZeroDaysAndHoursFor0)
{
const Duration duration = Duration::fromHours(0);
EXPECT_EQ(duration.getDays(), 0);
EXPECT_EQ(duration.getHours(), 0);
}
TEST(MWWorldDurationTest, fromHoursShouldProduceOneDayAndZeroHoursFor24)
{
const Duration duration = Duration::fromHours(24);
EXPECT_EQ(duration.getDays(), 1);
EXPECT_EQ(duration.getHours(), 0);
}
TEST(MWWorldDurationTest, fromHoursShouldProduceOneDayAndRemainderHoursFor42)
{
const Duration duration = Duration::fromHours(42);
EXPECT_EQ(duration.getDays(), 1);
EXPECT_EQ(duration.getHours(), 18);
}
TEST(MWWorldDurationTest, fromHoursShouldProduceZeroDaysAndZeroHoursForMinDouble)
{
const Duration duration = Duration::fromHours(std::numeric_limits<double>::min());
EXPECT_EQ(duration.getDays(), 0);
EXPECT_EQ(duration.getHours(), 0);
}
TEST(MWWorldDurationTest, fromHoursShouldProduceZeroDaysAndSomeHoursForMinFloat)
{
const Duration duration = Duration::fromHours(std::numeric_limits<float>::min());
EXPECT_EQ(duration.getDays(), 0);
EXPECT_GT(duration.getHours(), 0);
EXPECT_FLOAT_EQ(duration.getHours(), std::numeric_limits<float>::min());
}
TEST(MWWorldDurationTest, fromHoursShouldProduceZeroDaysAndRemainderHoursForValueJustBelow24InDoublePrecision)
{
const Duration duration = Duration::fromHours(std::nextafter(24.0, 0.0));
EXPECT_EQ(duration.getDays(), 0);
EXPECT_LT(duration.getHours(), 24);
EXPECT_FLOAT_EQ(duration.getHours(), 24);
}
TEST(MWWorldDurationTest, fromHoursShouldProduceZeroDaysAndRemainderHoursForValueJustBelow24InFloatPrecision)
{
const Duration duration = Duration::fromHours(std::nextafter(24.0f, 0.0f));
EXPECT_EQ(duration.getDays(), 0);
EXPECT_LT(duration.getHours(), 24);
EXPECT_FLOAT_EQ(duration.getHours(), 24);
}
}
}