129 lines
4.3 KiB
C#
129 lines
4.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NUnit.Framework;
|
|
using Vanguard.Api.Contracts;
|
|
using Vanguard.UI;
|
|
|
|
namespace Vanguard.Tests
|
|
{
|
|
public sealed class DeckBuilderTests
|
|
{
|
|
private static CardCatalogItemDto Card(
|
|
string printingId,
|
|
string nameId,
|
|
int grade,
|
|
string clan,
|
|
string trigger = "None")
|
|
{
|
|
return new CardCatalogItemDto
|
|
{
|
|
PrintingId = printingId,
|
|
NameId = nameId,
|
|
NameEn = nameId,
|
|
NameRu = nameId,
|
|
Grade = grade,
|
|
Clan = clan,
|
|
Trigger = trigger,
|
|
};
|
|
}
|
|
|
|
private static Dictionary<string, CardCatalogItemDto> Catalog(
|
|
params CardCatalogItemDto[] cards)
|
|
{
|
|
return cards.ToDictionary(card => card.PrintingId);
|
|
}
|
|
|
|
[Test]
|
|
public void Empty_Filter_Matches_Every_Card()
|
|
{
|
|
var filter = new DeckFilter();
|
|
Assert.IsTrue(filter.IsEmpty);
|
|
Assert.IsTrue(filter.Matches(Card("p1", "A", 0, "RoyalPaladin")));
|
|
Assert.IsTrue(filter.Matches(Card("p2", "B", 3, "Kagero", "Heal")));
|
|
}
|
|
|
|
[Test]
|
|
public void Multi_Filter_Combines_Clan_Grade_And_Trigger()
|
|
{
|
|
var filter = new DeckFilter();
|
|
filter.Clans.Add("RoyalPaladin");
|
|
filter.Clans.Add("Kagero");
|
|
filter.Grades.Add(1);
|
|
filter.Grades.Add(2);
|
|
filter.Triggers.Add("Heal");
|
|
|
|
Assert.IsTrue(filter.Matches(Card("p1", "A", 1, "Kagero", "Heal")));
|
|
Assert.IsFalse(filter.Matches(Card("p2", "B", 1, "Kagero", "Draw")));
|
|
Assert.IsFalse(filter.Matches(Card("p3", "C", 0, "Kagero", "Heal")));
|
|
Assert.IsFalse(filter.Matches(Card("p4", "D", 1, "NovaGrappler", "Heal")));
|
|
Assert.IsFalse(filter.IsEmpty);
|
|
}
|
|
|
|
[Test]
|
|
public void GroupDeck_Sums_Printings_And_Sorts_By_Grade_Then_Name()
|
|
{
|
|
Loc.SetLanguage(UiLanguage.Ru);
|
|
var catalog = Catalog(
|
|
Card("p1", "Zeta", 2, "Kagero"),
|
|
Card("p2", "Alpha", 2, "Kagero"),
|
|
Card("p3", "Alpha", 2, "Kagero"),
|
|
Card("p4", "Beta", 0, "Kagero"));
|
|
|
|
var groups = DeckListModel.GroupDeck(
|
|
new[] { "p1", "p2", "p3", "p4" },
|
|
catalog);
|
|
|
|
Assert.AreEqual(3, groups.Count);
|
|
Assert.AreEqual("Beta", groups[0].NameId);
|
|
Assert.AreEqual("Alpha", groups[1].NameId);
|
|
Assert.AreEqual(2, groups[1].Count);
|
|
Assert.AreEqual("Zeta", groups[2].NameId);
|
|
}
|
|
|
|
[Test]
|
|
public void GroupDeck_Keeps_Unknown_Printing_Last()
|
|
{
|
|
var catalog = Catalog(Card("p1", "Alpha", 0, "Kagero"));
|
|
var groups = DeckListModel.GroupDeck(new[] { "missing", "p1" }, catalog);
|
|
|
|
Assert.AreEqual(2, groups.Count);
|
|
Assert.AreEqual("Alpha", groups[0].NameId);
|
|
Assert.AreEqual("missing", groups[1].NameId);
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_Requires_Count_Triggers_And_Copy_Limit()
|
|
{
|
|
var catalog = new Dictionary<string, CardCatalogItemDto>();
|
|
var cards = new List<string>();
|
|
for (var i = 0; i < 50; i++)
|
|
{
|
|
var printingId = "p" + i;
|
|
catalog[printingId] = Card(
|
|
printingId,
|
|
"card" + i,
|
|
i % 4,
|
|
"RoyalPaladin",
|
|
i < 16 ? "Critical" : "None");
|
|
cards.Add(printingId);
|
|
}
|
|
|
|
var valid = DeckListModel.Validate(cards, catalog);
|
|
Assert.AreEqual(50, valid.Count);
|
|
Assert.AreEqual(16, valid.Triggers);
|
|
Assert.IsTrue(valid.IsValid);
|
|
|
|
var shortDeck = DeckListModel.Validate(cards.Take(49), catalog);
|
|
Assert.IsFalse(shortDeck.IsValid);
|
|
|
|
var copyDeck = new List<string>
|
|
{
|
|
"p0", "p0", "p0", "p0", "p0",
|
|
};
|
|
var copyValidation = DeckListModel.Validate(copyDeck, catalog);
|
|
Assert.IsFalse(copyValidation.MaxCopiesOk);
|
|
Assert.IsFalse(copyValidation.IsValid);
|
|
}
|
|
}
|
|
}
|