102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using NUnit.Framework;
|
|
using SVSim.BattleNode.Lifecycle;
|
|
using SVSim.BattleNode.Protocol;
|
|
using SVSim.BattleNode.Protocol.Bodies;
|
|
|
|
namespace SVSim.UnitTests.BattleNode.Lifecycle;
|
|
|
|
[TestFixture]
|
|
public class ScriptedLifecycleTests
|
|
{
|
|
[Test]
|
|
public void BuildMatched_PutsOppoIdInSelfInfoEqualToTheRealOpponentVid()
|
|
{
|
|
var env = ScriptedLifecycle.BuildMatched(playerViewerId: 906243102, opponentViewerId: 847666884, battleId: "b");
|
|
|
|
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.Matched));
|
|
var body = (MatchedBody)env.Body;
|
|
Assert.That(body.SelfInfo.OppoId, Is.EqualTo(847666884L));
|
|
Assert.That(body.OppoInfo.OppoId, Is.EqualTo(906243102L));
|
|
|
|
// Bid travels in the envelope, not the Body — protect against the reserved-keys regression.
|
|
Assert.That(env.Bid, Is.EqualTo("b"));
|
|
// Typed bodies can't carry an envelope-level "bid" key by construction (no such property).
|
|
}
|
|
|
|
[Test]
|
|
public void BuildMatched_ContainsThirtyCardSelfDeck()
|
|
{
|
|
var env = ScriptedLifecycle.BuildMatched(1, 2, "b");
|
|
var body = (MatchedBody)env.Body;
|
|
Assert.That(body.SelfDeck.Count, Is.EqualTo(30));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildBattleStart_HasTurnStateZeroAndBattleTypeEleven()
|
|
{
|
|
var env = ScriptedLifecycle.BuildBattleStart(playerViewerId: 1);
|
|
var body = (BattleStartBody)env.Body;
|
|
Assert.That(body.TurnState, Is.EqualTo(0));
|
|
Assert.That(body.BattleType, Is.EqualTo(11));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildDeal_HasThreeSelfAndThreeOppoEntries()
|
|
{
|
|
var env = ScriptedLifecycle.BuildDeal();
|
|
var body = (DealBody)env.Body;
|
|
Assert.That(body.Self.Count, Is.EqualTo(3));
|
|
Assert.That(body.Oppo.Count, Is.EqualTo(3));
|
|
}
|
|
|
|
[Test]
|
|
public void ComputeHandAfterSwap_NoSwap_ReturnsInitialHand()
|
|
{
|
|
var hand = ScriptedLifecycle.ComputeHandAfterSwap(Array.Empty<long>());
|
|
Assert.That(hand, Is.EqualTo(new long[] { 1, 2, 3 }));
|
|
}
|
|
|
|
[Test]
|
|
public void ComputeHandAfterSwap_SwapMiddleCard_ReplacesWithFreshDeckIdx()
|
|
{
|
|
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 2 });
|
|
// pos 0 keeps idx 1; pos 1 (was idx 2) gets next deck idx (4); pos 2 keeps idx 3.
|
|
Assert.That(hand, Is.EqualTo(new long[] { 1, 4, 3 }));
|
|
}
|
|
|
|
[Test]
|
|
public void ComputeHandAfterSwap_SwapAll_ReplacesAllWithFreshDeckIdxs()
|
|
{
|
|
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 1, 2, 3 });
|
|
Assert.That(hand, Is.EqualTo(new long[] { 4, 5, 6 }));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildSwapResponse_RendersGivenHandAsPositions()
|
|
{
|
|
var env = ScriptedLifecycle.BuildSwapResponse(new long[] { 1, 4, 3 });
|
|
var body = (SwapResponseBody)env.Body;
|
|
Assert.That(body.Self.Count, Is.EqualTo(3));
|
|
Assert.That(body.Self[1].Idx, Is.EqualTo(4));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildReady_IncludesIdxChangeSeedAndSpin_AndUsesGivenHand()
|
|
{
|
|
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 });
|
|
var body = (ReadyBody)env.Body;
|
|
Assert.That(body.IdxChangeSeed, Is.EqualTo(771_335_280));
|
|
Assert.That(body.Spin, Is.EqualTo(243));
|
|
Assert.That(body.Self[1].Idx, Is.EqualTo(4));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildOpponentTurnStart_HasUriTurnStartAndSpin()
|
|
{
|
|
var env = ScriptedLifecycle.BuildOpponentTurnStart();
|
|
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.TurnStart));
|
|
var body = (OpponentTurnStartBody)env.Body;
|
|
Assert.That(body.Spin, Is.EqualTo(100));
|
|
}
|
|
}
|