diff --git a/tests/Aetheria.Shared.Tests/StationDeckTests.cs b/tests/Aetheria.Shared.Tests/StationDeckTests.cs index 82ceeb34a..2368ebb0a 100644 --- a/tests/Aetheria.Shared.Tests/StationDeckTests.cs +++ b/tests/Aetheria.Shared.Tests/StationDeckTests.cs @@ -34,24 +34,79 @@ public sealed partial class RunStartTests var checkedFactions = 0; foreach (var seed in DeckSeeds) { - var galaxy = DemoGalaxy(seed); - var deal = StationDeck.Deal(galaxy, _cache); - foreach (var region in Enumerable.Range(0, galaxy.Zones.Length).GroupBy(z => galaxy.Zones[z].Province.Region)) - { - var outside = region.Where(z => galaxy.Zones[z] != galaxy.Entrance).ToArray(); - foreach (var faction in outside.Select(z => StationDeck.StructureFaction(galaxy, galaxy.Zones[z])).Distinct()) - { - var dealt = outside.SelectMany(z => Ambient(deal[z], galaxy.Zones[z])).Where(card => card.Faction == faction) - .Select(card => card.Kind.Key.Value).ToHashSet(); - foreach (var kind in StationKinds.PoolOf(_cache, faction)) - Assert.True(dealt.Contains(kind.Key.Value), $"seed {seed}: {faction.Name} fields {kind.Key.Value}, none dealt outside the entrance of region {region.Key}"); - checkedFactions++; - } - } + checkedFactions += AssertEveryKindOutsideTheEntrance(DemoGalaxy(seed), $"seed {seed}"); } Assert.True(checkedFactions >= 40 * 4, $"the sweep covered {checkedFactions} faction regions"); } + private int AssertEveryKindOutsideTheEntrance(Galaxy galaxy, string label) + { + var checkedFactions = 0; + var deal = StationDeck.Deal(galaxy, _cache); + foreach (var region in Enumerable.Range(0, galaxy.Zones.Length).GroupBy(z => galaxy.Zones[z].Province.Region)) + { + var outside = region.Where(z => galaxy.Zones[z] != galaxy.Entrance).ToArray(); + foreach (var faction in outside.Select(z => StationDeck.StructureFaction(galaxy, galaxy.Zones[z])).Distinct()) + { + var dealt = outside.SelectMany(z => Ambient(deal[z], galaxy.Zones[z])).Where(card => card.Faction == faction) + .Select(card => card.Kind.Key.Value).ToHashSet(); + foreach (var kind in StationKinds.PoolOf(_cache, faction)) + Assert.True(dealt.Contains(kind.Key.Value), $"{label}: {faction.Name} fields {kind.Key.Value}, none dealt outside the entrance of region {region.Key}"); + checkedFactions++; + } + } + return checkedFactions; + } + + // The demo's entrance is dealt no card (its presence leaves 0 slots), so the entrance rules need a galaxy that gives it some: the faction + // that holds it gets its home there and an influence of 3 (a small territory, so it holds few slots outside the entrance and the thin-territory rule + // and the entrance slots meet), restored after. + private void WithADealtEntrance(uint seed, Action body) + { + var galaxy = DemoGalaxy(seed); + var holder = StationDeck.StructureFaction(galaxy, galaxy.Entrance); + var home = galaxy.HomeZones[holder]; + var influence = holder.InfluenceDistance; + galaxy.HomeZones[holder] = galaxy.Entrance; + holder.InfluenceDistance = 3; + try { body(galaxy); } + finally { holder.InfluenceDistance = influence; galaxy.HomeZones[holder] = home; } + } + + // With cards dealt to the entrance, the first deck still goes outside it: every kind a faction fields stands outside the entrance. + [Fact] + public void EveryKindStandsOutsideTheEntranceWhenTheEntranceIsDealtCards() + { + var exercised = 0; + foreach (var seed in DeckSeeds) + WithADealtEntrance(seed, galaxy => + { + var cards = Ambient(StationDeck.Deal(galaxy, _cache)[Array.IndexOf(galaxy.Zones, galaxy.Entrance)], galaxy.Entrance); + if (cards.Length == 0) return; + exercised++; + Assert.True(AssertEveryKindOutsideTheEntrance(galaxy, $"seed {seed}") > 0); + }); + Assert.True(exercised >= 10, $"only {exercised} of {DeckSeeds.Length} seeds dealt the entrance a card"); + } + + // Orders replace the dealt entrance cards, they do not join them: a scenario that orders the entrance holds its orders and nothing dealt. + [Fact] + public void AnOrderedEntranceDealtCardsStillHoldsExactlyItsOrders() + { + var orders = new DemoTerminus().EntranceStations; + var exercised = 0; + foreach (var seed in DeckSeeds.Take(20)) + WithADealtEntrance(seed, galaxy => + { + var cards = StationDeck.Deal(galaxy, _cache)[Array.IndexOf(galaxy.Zones, galaxy.Entrance)]; + if (cards.Length == 0) return; + exercised++; + var pack = ZoneGenerator.GenerateZone(_items, _zoneSettings, _planetSettings, galaxy, galaxy.Entrance, orders, ambient: false); + Assert.Equal(orders.Select(order => OrderCard(galaxy, order)).ToArray(), StationCardsOf(pack)); + }); + Assert.True(exercised >= 5, $"only {exercised} of 20 seeds dealt the entrance a card"); + } + [Fact] public void EveryDealtCardIsSeated() {