CI / build-test (push) Successful in 1m13s
- Added a `startDay` parameter to the `Calendar` class to allow for fractional day offsets at clock initialization, enabling more flexible time settings. - Updated `TotalDays` calculation to include the `startDay` offset. - Introduced `StartDayOfYear` in `ClimateSettings` to shift the seasonal phase, allowing worlds to begin at a specific time of year. - Adjusted `YearProgress` and `Year` calculations in the `Climate` class to account for the new `StartDayOfYear`. - Added unit tests to verify the functionality of the new start day features in both `Calendar` and `Climate` classes.
97 lines
2.6 KiB
C#
97 lines
2.6 KiB
C#
using MrGameEng.Core;
|
|
using Xunit;
|
|
|
|
namespace MrGameEng.Core.Tests;
|
|
|
|
public class CalendarTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_NonPositiveSecondsPerDay_Throws()
|
|
{
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => new Calendar(new GameClock(), 0f));
|
|
}
|
|
|
|
[Fact]
|
|
public void TotalDays_TracksScaledClockTime()
|
|
{
|
|
var clock = new GameClock();
|
|
var calendar = new Calendar(clock, secondsPerDay: 10f);
|
|
|
|
clock.Advance(5f); // half a day
|
|
|
|
Assert.Equal(0.5, calendar.TotalDays, 5);
|
|
Assert.Equal(1, calendar.Day);
|
|
Assert.Equal(0.5f, calendar.DayProgress, 5);
|
|
}
|
|
|
|
[Fact]
|
|
public void Day_CountsFromOne_AndRollsOver()
|
|
{
|
|
var clock = new GameClock();
|
|
var calendar = new Calendar(clock, secondsPerDay: 10f);
|
|
|
|
Assert.Equal(1, calendar.Day);
|
|
|
|
clock.Advance(10f); // exactly one day
|
|
Assert.Equal(2, calendar.Day);
|
|
Assert.Equal(0f, calendar.DayProgress, 5);
|
|
|
|
clock.Advance(15f); // total 25s = 2.5 days
|
|
Assert.Equal(3, calendar.Day);
|
|
Assert.Equal(0.5f, calendar.DayProgress, 5);
|
|
}
|
|
|
|
[Fact]
|
|
public void HourAndMinute_DecomposeTimeOfDay()
|
|
{
|
|
var clock = new GameClock();
|
|
var calendar = new Calendar(clock, secondsPerDay: 1440f); // one minute per in-game minute
|
|
|
|
clock.Advance(14 * 60 + 30); // 14:30
|
|
|
|
Assert.Equal(14, calendar.Hour);
|
|
Assert.Equal(30, calendar.Minute);
|
|
Assert.Equal(14 * 60 + 30, calendar.MinuteOfDay);
|
|
}
|
|
|
|
[Fact]
|
|
public void StartDay_OffsetsTheTimeOfDay()
|
|
{
|
|
var clock = new GameClock();
|
|
var calendar = new Calendar(clock, secondsPerDay: 10f, startDay: 7.0 / 24); // begin at 07:00
|
|
|
|
Assert.Equal(1, calendar.Day);
|
|
Assert.Equal(7, calendar.Hour);
|
|
Assert.Equal(0, calendar.Minute);
|
|
|
|
clock.Advance(5f); // half a day later → 19:00
|
|
Assert.Equal(19, calendar.Hour);
|
|
}
|
|
|
|
[Fact]
|
|
public void Pause_DoesNotAdvanceTheCalendar()
|
|
{
|
|
var clock = new GameClock { TimeScale = 0f };
|
|
var calendar = new Calendar(clock, secondsPerDay: 10f);
|
|
|
|
clock.Advance(100f);
|
|
|
|
Assert.Equal(0.0, calendar.TotalDays, 5);
|
|
Assert.Equal(1, calendar.Day);
|
|
}
|
|
|
|
[Fact]
|
|
public void TimeScale_SpeedsUpTheCalendar()
|
|
{
|
|
var slow = new GameClock();
|
|
var fast = new GameClock { TimeScale = 6f };
|
|
var slowCal = new Calendar(slow, secondsPerDay: 10f);
|
|
var fastCal = new Calendar(fast, secondsPerDay: 10f);
|
|
|
|
slow.Advance(10f);
|
|
fast.Advance(10f);
|
|
|
|
Assert.Equal(6.0, fastCal.TotalDays / slowCal.TotalDays, 5);
|
|
}
|
|
}
|