Station kinds tests: a bad package kind is excluded not fatal, same seed gives the same station and belt kinds, the stand-in check can fail (red)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ea3e983aa2
commit
d55ac30905
3 changed files with 126 additions and 3 deletions
|
|
@ -833,6 +833,49 @@ public sealed partial class MiningCut3Tests : IDisposable
|
|||
Assert.True(belts > 0, "no seed generated a belt; the generation path went unexercised");
|
||||
}
|
||||
|
||||
// The kind of a belt is a function of the zone's seed, not of the key the cache mints for it: the same seed generated
|
||||
// again, through the real key minting, gives the same belts the same kinds.
|
||||
[Fact]
|
||||
public void SameSeedGivesTheSameBeltKinds()
|
||||
{
|
||||
string[] Generate(uint seed, int run)
|
||||
{
|
||||
var dir = Path.Combine(_root, $"same{seed}-{run}");
|
||||
Directory.CreateDirectory(dir);
|
||||
var catalog = Path.Combine(dir, "Aetheria.cc");
|
||||
File.Copy(TestCatalog.Repo, catalog);
|
||||
using var cache = OpenShippedCatalogCopy(catalog, Path.Combine(dir, "run.cc"));
|
||||
foreach (var existing in cache.GetAll<FieldKindData>().ToArray())
|
||||
{
|
||||
existing.GenerationWeight = 0f;
|
||||
cache.Upsert(existing);
|
||||
}
|
||||
cache.Upsert(Kind("Gen A", 1f, 1f));
|
||||
cache.Upsert(Kind("Gen B", 1f, 2f));
|
||||
cache.Upsert(Kind("Gen C", 1f, 4f));
|
||||
Galaxy galaxy;
|
||||
try
|
||||
{
|
||||
galaxy = new Galaxy(RestoredHullsTests.TutorialGalaxySettings(), RestoredHullsTests.TutorialBackgroundSettings(),
|
||||
cache, new PlayerSettings(), new DirectoryInfo(dir), _ => { }, null, seed);
|
||||
}
|
||||
catch (Exception) { return null; }
|
||||
var items = new ItemManager(1u, cache, new ProvenanceLedger(), GameSettings(), _ => { });
|
||||
return galaxy.Zones.Take(6).SelectMany(zone =>
|
||||
ZoneGenerator.GenerateZone(items, RestoredHullsTests.TutorialZoneSettings(), RestoredHullsTests.AuthoredPlanetSettings(), galaxy, zone, isTutorial: zone == galaxy.Entrance)
|
||||
.Planets.Select(body => cache.Get(body)).OfType<AsteroidBeltData>().Select(belt => belt.Kind.Key.Value))
|
||||
.ToArray();
|
||||
}
|
||||
for (uint seed = 1; seed <= 25; seed++)
|
||||
{
|
||||
var first = Generate(seed, 0);
|
||||
if (first == null || first.Length < 4) continue;
|
||||
for (var run = 1; run < 4; run++) Assert.Equal(first, Generate(seed, run));
|
||||
return;
|
||||
}
|
||||
Assert.Fail("no seed generated enough belts; the generation path went unexercised");
|
||||
}
|
||||
|
||||
// ==== Mining Cut 3 fix batch (Soul's findings) ====
|
||||
|
||||
// Q12 A ("launchers cannot mine") in the reach rule: reach counts only weapons that can mine (Weapon.CanMine).
|
||||
|
|
|
|||
|
|
@ -49,6 +49,36 @@ public sealed class ShipModCatalogTests : IDisposable
|
|||
AssertOnlyTheDerivedFile();
|
||||
}
|
||||
|
||||
// A package's station kind is checked per package: a bad one is left out, named with its reason, and the derived catalog
|
||||
// still opens. The shipped catalog's own check is unchanged.
|
||||
[Fact]
|
||||
public void ComposeExcludesPackagesWithBadStationKinds()
|
||||
{
|
||||
using (var cache = AetheriaStores.Open(Shipped, catalogWritable: true))
|
||||
{
|
||||
cache.Upsert(new StationKindData { Name = "Hub" });
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
string kindKey;
|
||||
using (var cache = AetheriaStores.Open(Shipped)) kindKey = cache.RefOf(cache.GetAll<StationKindData>().Single()).Key.Value;
|
||||
var held = new CultRecordRef<StationKindData>(new CultRecordKey(kindKey));
|
||||
WritePackage("mod.kindless", "Kindless", tweak: p => p.Hull.HullType = HullType.Station);
|
||||
WritePackage("mod.unknown", "Unknown", tweak: p => { p.Hull.HullType = HullType.Station; p.Hull.Kind = new CultRecordRef<StationKindData>(new CultRecordKey("station-kind:nowhere")); });
|
||||
WritePackage("mod.shipkind", "ShipKind", tweak: p => p.Hull.Kind = held);
|
||||
WritePackage("mod.good", "GoodStation", tweak: p => { p.Hull.HullType = HullType.Station; p.Hull.Kind = held; });
|
||||
|
||||
var composition = ShipModCatalog.Compose(Shipped, Derived, Mods);
|
||||
|
||||
Assert.Equal(new[] { "mod.good" }, composition.Included);
|
||||
Assert.Equal(new[] { "mod.kindless", "mod.shipkind", "mod.unknown" }, composition.Excluded.Select(e => e.Package).OrderBy(n => n, StringComparer.Ordinal));
|
||||
Assert.Contains("no Kind", composition.Excluded.Single(e => e.Package == "mod.kindless").Reason);
|
||||
Assert.Contains("names no station kind", composition.Excluded.Single(e => e.Package == "mod.unknown").Reason);
|
||||
Assert.Contains("only a station hull has one", composition.Excluded.Single(e => e.Package == "mod.shipkind").Reason);
|
||||
using var derived = AetheriaStores.Open(Derived);
|
||||
Assert.Contains("GoodStation", derived.GetAll<HullData>().Select(hull => hull.Name));
|
||||
Assert.DoesNotContain("Kindless", derived.GetAll<HullData>().Select(hull => hull.Name));
|
||||
}
|
||||
|
||||
// Correction 2 of the S0 map: the derived catalog held each mod hull twice, once as a HullData and once inside the
|
||||
// ship's authoring record. The hull is now one record, and the visual holds no hull.
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -329,6 +329,29 @@ public sealed class StationKindTests : IDisposable
|
|||
Assert.Equal(one, several);
|
||||
}
|
||||
|
||||
// A station's kind is a function of the zone's seed and the orbit's place in generation, not of a key the cache mints:
|
||||
// the same zone generated again, through the real key minting, gives the same stations the same kinds in the same order.
|
||||
[Fact]
|
||||
public void SameSeedGivesTheSameStationKinds()
|
||||
{
|
||||
string[] Kinds()
|
||||
{
|
||||
var w = World.Make(this, zenithOffered: true);
|
||||
foreach (var faction in new[] { w.Au, w.Zh, w.Lucent })
|
||||
foreach (var kind in new[] { "mining", "shipyard", "depot", "power" }) w.Sell(faction, kind);
|
||||
var authored = AuthoredSettings.Load(RunStartTests.FindRepoRoot());
|
||||
var galaxy = new Galaxy(authored.Read<TutorialGenerationSettings>("TutorialGenerationSettings"),
|
||||
authored.Read<SectorBackgroundSettings>("TutorialBackgroundSettings"), w.Cache, new PlayerSettings(),
|
||||
Directory.CreateDirectory(Path.Combine(_root, "galaxy" + _worlds++, "Narrative")), _ => { }, null, 3);
|
||||
var pack = ZoneGenerator.GenerateZone(w.Items, authored.Read<ZoneGenerationSettings>("ZoneSettings"),
|
||||
authored.Read<PlanetSettings>("PlanetSettings"), galaxy, galaxy.Entrance, galaxy.IsPrelude, true);
|
||||
return pack.Entities.OfType<OrbitalEntityPack>().Where(e => e.Kind.IsSet()).Select(e => e.Kind.Key.Value).ToArray();
|
||||
}
|
||||
var first = Kinds();
|
||||
Assert.True(first.Length >= 3, "the sample placed stations");
|
||||
for (var run = 1; run < 6; run++) Assert.Equal(first, Kinds());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GeneratedZonesPlaceStationsByKind()
|
||||
{
|
||||
|
|
@ -389,10 +412,8 @@ public sealed class StationKindTests : IDisposable
|
|||
Assert.Equal(StationKindData.KeyOf("trade-hub").Value, cache.GetAll<HullData>().Single(h => h.Name == "Zenith").Kind.Key.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShippedStandInsAreLive()
|
||||
private static void AssertStandInsLive(CultCache cache)
|
||||
{
|
||||
using var cache = AetheriaStores.Open(TestCatalog.Repo);
|
||||
foreach (var kind in cache.GetAll<StationKindData>())
|
||||
foreach (var standIn in kind.StandIns)
|
||||
{
|
||||
|
|
@ -405,4 +426,33 @@ public sealed class StationKindTests : IDisposable
|
|||
Assert.NotEmpty(models);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ShippedStandInsAreLive()
|
||||
{
|
||||
using var cache = AetheriaStores.Open(TestCatalog.Repo);
|
||||
AssertStandInsLive(cache);
|
||||
}
|
||||
|
||||
// The retirement check is not vacuous: given a stand-in it passes when the faction offers the kind it stands in with and
|
||||
// not the owning kind, and fails when the faction has gained its own model of the owning kind or has no model to use.
|
||||
[Fact]
|
||||
public void StandInRetirementCheckCanFail()
|
||||
{
|
||||
var live = World.Make(this, zenithOffered: false);
|
||||
live.Sell(live.Au, "mining");
|
||||
live.StandIn("shipyard", live.Au, "mining");
|
||||
Assert.Single(live.Cache.GetAll<StationKindData>().SelectMany(kind => kind.StandIns));
|
||||
AssertStandInsLive(live.Cache);
|
||||
|
||||
var retired = World.Make(this, zenithOffered: false);
|
||||
retired.Sell(retired.Au, "mining");
|
||||
retired.Sell(retired.Au, "shipyard");
|
||||
retired.StandIn("shipyard", retired.Au, "mining");
|
||||
Assert.ThrowsAny<Exception>(() => AssertStandInsLive(retired.Cache));
|
||||
|
||||
var hollow = World.Make(this, zenithOffered: false);
|
||||
hollow.StandIn("shipyard", hollow.Au, "mining");
|
||||
Assert.ThrowsAny<Exception>(() => AssertStandInsLive(hollow.Cache));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue