- PlayActionsHandler doc: drop the phantom 'with a debug log' (handlers are stateless singletons with no logger); say token plays degrade silently. - KnownListBuilder.ExtractMoveTo doc: note first-match-wins semantics and the send-side==recv-side 'to' assumption pending recv-capture confirmation. - KnownListBuilderTests: add multi-move first-match coverage and the in-deck-but-no-matching-move null branch for BuildPlayedCard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
115 lines
4.1 KiB
C#
115 lines
4.1 KiB
C#
using NUnit.Framework;
|
|
using SVSim.BattleNode.Sessions.Dispatch;
|
|
|
|
namespace SVSim.UnitTests.BattleNode.Sessions;
|
|
|
|
[TestFixture]
|
|
public class KnownListBuilderTests
|
|
{
|
|
// orderList as it arrives in a RawBody: a list of single-key op dicts.
|
|
private static List<object?> OrderListMove(int idx, int from, int to) => new()
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
["move"] = new Dictionary<string, object?>
|
|
{
|
|
["idx"] = new List<object?> { (long)idx },
|
|
["isSelf"] = 1L, ["from"] = (long)from, ["to"] = (long)to,
|
|
}
|
|
}
|
|
};
|
|
|
|
[Test]
|
|
public void ExtractMoveTo_returns_to_for_matching_idx()
|
|
{
|
|
var to = KnownListBuilder.ExtractMoveTo(OrderListMove(3, 10, 20), playIdx: 3);
|
|
Assert.That(to, Is.EqualTo(20));
|
|
}
|
|
|
|
[Test]
|
|
public void ExtractMoveTo_returns_null_when_no_move_op_matches()
|
|
{
|
|
Assert.That(KnownListBuilder.ExtractMoveTo(OrderListMove(3, 10, 20), playIdx: 99), Is.Null);
|
|
Assert.That(KnownListBuilder.ExtractMoveTo(null, playIdx: 3), Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void ExtractMoveTo_returns_first_matching_move_op()
|
|
{
|
|
// A real PlayActions can carry several move ops; the played card's move comes first,
|
|
// later ops (token add/alter) target other idxs. Confirm first-match-wins, not last.
|
|
var orderList = new List<object?>
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
["move"] = new Dictionary<string, object?>
|
|
{
|
|
["idx"] = new List<object?> { 3L }, ["isSelf"] = 1L, ["from"] = 10L, ["to"] = 30L,
|
|
}
|
|
},
|
|
new Dictionary<string, object?>
|
|
{
|
|
["move"] = new Dictionary<string, object?>
|
|
{
|
|
["idx"] = new List<object?> { 31L, 32L }, ["isSelf"] = 1L, ["from"] = 0L, ["to"] = 40L,
|
|
}
|
|
},
|
|
};
|
|
Assert.That(KnownListBuilder.ExtractMoveTo(orderList, playIdx: 3), Is.EqualTo(30));
|
|
Assert.That(KnownListBuilder.ExtractMoveTo(orderList, playIdx: 31), Is.EqualTo(40));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildPlayedCard_returns_null_for_deck_card_with_no_matching_move_op()
|
|
{
|
|
// idx is in the deck, but the orderList has no move op for it → can't synthesize.
|
|
var deckMap = new Dictionary<int, long> { [3] = 128821011L };
|
|
var entry = KnownListBuilder.BuildPlayedCard(deckMap, playIdx: 3, orderList: OrderListMove(7, 10, 20));
|
|
Assert.That(entry, Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void BuildPlayedCard_synthesizes_entry_for_deck_card()
|
|
{
|
|
var deckMap = new Dictionary<int, long> { [3] = 128821011L };
|
|
var entry = KnownListBuilder.BuildPlayedCard(deckMap, playIdx: 3, orderList: OrderListMove(3, 10, 20));
|
|
|
|
Assert.That(entry, Is.Not.Null);
|
|
Assert.That(entry!.Idx, Is.EqualTo(3));
|
|
Assert.That(entry.CardId, Is.EqualTo(128821011L));
|
|
Assert.That(entry.To, Is.EqualTo(20));
|
|
Assert.That(entry.Spellboost, Is.EqualTo(0));
|
|
Assert.That(entry.AttachTarget, Is.EqualTo(""));
|
|
}
|
|
|
|
[Test]
|
|
public void BuildPlayedCard_returns_null_for_token_idx_not_in_deck()
|
|
{
|
|
var deckMap = new Dictionary<int, long> { [3] = 128821011L };
|
|
var entry = KnownListBuilder.BuildPlayedCard(deckMap, playIdx: 31, orderList: OrderListMove(31, 10, 20));
|
|
Assert.That(entry, Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void RenameTargets_passes_isSelf_through_verbatim()
|
|
{
|
|
var targetList = new List<object?>
|
|
{
|
|
new Dictionary<string, object?> { ["targetIdx"] = 8L, ["isSelf"] = 0L },
|
|
};
|
|
var renamed = KnownListBuilder.RenameTargets(targetList);
|
|
|
|
Assert.That(renamed, Is.Not.Null);
|
|
Assert.That(renamed!.Count, Is.EqualTo(1));
|
|
Assert.That(renamed[0].TargetIdx, Is.EqualTo(8));
|
|
Assert.That(renamed[0].IsSelf, Is.EqualTo(0));
|
|
}
|
|
|
|
[Test]
|
|
public void RenameTargets_returns_null_for_missing_or_empty()
|
|
{
|
|
Assert.That(KnownListBuilder.RenameTargets(null), Is.Null);
|
|
Assert.That(KnownListBuilder.RenameTargets(new List<object?>()), Is.Null);
|
|
}
|
|
}
|