Implement live game clock and simulation controls; enhance API with clock update functionality and improve world summary with clock data; update UI to display simulation controls and integrate clock features into the game experience.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using TheLivingWorld.Core.Simulation;
|
||||
|
||||
namespace TheLivingWorld.Tests;
|
||||
|
||||
public sealed class GameTimeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Advance_at_x1_adds_five_game_minutes_per_real_second()
|
||||
{
|
||||
var start = GameTime.DefaultStart;
|
||||
var next = GameTime.Advance(start, TimeSpan.FromSeconds(1), timeScale: 1, paused: false);
|
||||
|
||||
Assert.Equal(start.AddMinutes(5), next);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Advance_scales_with_time_scale()
|
||||
{
|
||||
var start = GameTime.DefaultStart;
|
||||
|
||||
Assert.Equal(start.AddMinutes(10), GameTime.Advance(start, TimeSpan.FromSeconds(1), 2, false));
|
||||
Assert.Equal(start.AddMinutes(20), GameTime.Advance(start, TimeSpan.FromSeconds(1), 4, false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Advance_does_nothing_when_paused_or_non_positive()
|
||||
{
|
||||
var start = GameTime.DefaultStart;
|
||||
|
||||
Assert.Equal(start, GameTime.Advance(start, TimeSpan.FromSeconds(10), 4, paused: true));
|
||||
Assert.Equal(start, GameTime.Advance(start, TimeSpan.Zero, 1, paused: false));
|
||||
Assert.Equal(start, GameTime.Advance(start, TimeSpan.FromSeconds(-1), 1, paused: false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Advance_handles_a_large_wall_clock_gap()
|
||||
{
|
||||
var start = GameTime.DefaultStart;
|
||||
// One real hour at x1 → 5 * 3600 = 18_000 game minutes = 12.5 game days.
|
||||
var next = GameTime.Advance(start, TimeSpan.FromHours(1), timeScale: 1, paused: false);
|
||||
|
||||
Assert.Equal(start.AddMinutes(5 * 3600), next);
|
||||
Assert.Equal(new DateTime(2012, 4, 24, 18, 0, 0, DateTimeKind.Unspecified), next);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultStart_is_morning_of_12_April_2012()
|
||||
{
|
||||
Assert.Equal(new DateTime(2012, 4, 12, 6, 0, 0, DateTimeKind.Unspecified), GameTime.DefaultStart);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, true)]
|
||||
[InlineData(4, true)]
|
||||
[InlineData(0, false)]
|
||||
[InlineData(5, false)]
|
||||
public void IsValidTimeScale_accepts_1_through_4(int scale, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, GameTime.IsValidTimeScale(scale));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user