StationDeckTests: a fixture that deals the entrance cards beside its orders

The demo entrance is dealt no card, so the entrance rules were vacuous. The holder of the entrance gets its home there and an influence of 3: every kind a faction fields still stands outside the entrance (dies under the first deck dealt to entrance slots first, seed 19), and an ordered entrance holds exactly its orders (dies under dealt extras seated after the orders).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-29 04:30:40 +01:00
commit c27eeff3b8

View file

@ -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<Galaxy> 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()
{