Files
zfxaction26_1/tests/SideScrollerGame.Sim.Tests/SimulationStateTests.cs

69 lines
2.4 KiB
C#

using System.Collections.Immutable;
using SideScrollerGame.Sim.Input;
using SideScrollerGame.Sim.Runtime;
namespace SideScrollerGame.Sim.Tests;
public sealed class SimulationStateTests
{
[Fact]
public void PlayerState_CloneAndButtonReleasePreserveIndependentState()
{
PlayerState player = new(new(1), new(3, 4), 1, 2, 5, 6, 7, 0, 9);
player.SetButton(InputButton.Dash, true);
player.ApplyDamage(4);
var clone = player.Clone();
player.SetButton(InputButton.Dash, false);
player.SetPosition(new(8, 9));
Assert.NotEqual(player.ButtonMask, clone.ButtonMask);
Assert.Equal(7, clone.SelectedWeaponSlot);
Assert.Equal(3, clone.Position.m_X.ToIntRound());
Assert.Equal(4, clone.Position.m_Y.ToIntRound());
Assert.Equal(5, clone.Health);
}
[Fact]
public void SimulationState_CloneCreatesDeepCopy()
{
SimulationState original = new(4, 9, 123UL, 456UL, ImmutableArray.Create(new PlayerState(new(1), new(1, 2), 3, 4, 5, 6, 7, 8, 9)), ImmutableHashSet<string>.Empty.Add("checkpoint_a"));
var clone = original.Clone();
original.GetRequiredPlayer(new(1)).SetMoveAxis(9, 9);
original.ActivateTrigger("checkpoint_b");
Assert.Equal(4, clone.Tick);
Assert.Equal(9, clone.Seed);
Assert.Equal((ulong)123, clone.RandomState);
Assert.Equal((ulong)456, clone.LastRandomValue);
Assert.Equal(3, clone.GetRequiredPlayer(new(1)).MoveAxisX);
Assert.DoesNotContain("checkpoint_b", clone.ActivatedTriggerIds);
}
[Fact]
public void SimulationState_AcceptsDefaultPlayerArray()
{
SimulationState state = new(0, 1, 1UL, 0UL, default, ImmutableHashSet<string>.Empty);
Assert.Empty(state.Players);
Assert.Empty(state.ActivatedTriggerIds);
}
[Fact]
public void SimulationState_AcceptsDefaultTriggerSet()
{
SimulationState state = new(0, 1, 1UL, 0UL, ImmutableArray<PlayerState>.Empty, default!);
Assert.Empty(state.ActivatedTriggerIds);
}
[Fact]
public void ActivateTrigger_ReturnsFalseWhenRepeated()
{
SimulationState state = new(0, 1, 1UL, 0UL, ImmutableArray<PlayerState>.Empty, ImmutableHashSet<string>.Empty);
Assert.True(state.ActivateTrigger("checkpoint_a"));
Assert.False(state.ActivateTrigger("checkpoint_a"));
}
}