Tests follow the quarters' row: the census counts it, the reach exemption is station plant only, the drawn gate and an unset row are pinned, fixtures carry a row
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5a4698b2cd
commit
c5178d9b0c
5 changed files with 54 additions and 12 deletions
|
|
@ -71,6 +71,8 @@ public sealed class ConsumableSupplyTests : IDisposable
|
|||
return shape;
|
||||
}
|
||||
|
||||
private static HardpointData CrewRow() => new HardpointData { Type = HardpointType.Facility, Position = new CultMath.int2(1, 1), Shape = Solid(2, 2), Transform = "Fa.1" };
|
||||
|
||||
private Rig Build(Offer offer, Holds holds = Holds.Pinned)
|
||||
{
|
||||
var root = Path.Combine(_root, "rig" + _rigs++);
|
||||
|
|
@ -87,7 +89,7 @@ public sealed class ConsumableSupplyTests : IDisposable
|
|||
// Interior for the crate, the capacitor and the tractor beam every generated ship carries.
|
||||
var hub = new CultRecordRef<StationKindData>(seed.Upsert(new StationKindData { Name = "Hub" }).Key);
|
||||
var skiff = seed.Upsert(new HullData { Name = "Skiff", HullType = HullType.Ship, Shape = Solid(5, 3), Price = 100 });
|
||||
var platform = seed.Upsert(new HullData { Name = "Platform", HullType = HullType.Station, Kind = hub, Shape = Solid(5, 5), Price = 100 });
|
||||
var platform = seed.Upsert(new HullData { Name = "Platform", HullType = HullType.Station, Kind = hub, Shape = Solid(5, 5), Price = 100, Hardpoints = { CrewRow() } });
|
||||
// A hold with no cell cannot take a consumable.
|
||||
var crate = seed.Upsert(new CargoBayData
|
||||
{
|
||||
|
|
@ -102,8 +104,9 @@ public sealed class ConsumableSupplyTests : IDisposable
|
|||
Name = "Heater", Hardpoint = HardpointType.Tool, Shape = new Shape(), Price = 1,
|
||||
Behaviors = { new ThermotoggleData { HighPass = false }, new HeatData() }
|
||||
});
|
||||
// Every station carries Crew Quarters, installed through a not-offered product (one interior cell: the Outpost is a cell wider for it).
|
||||
var quarters = seed.Upsert(new GearData { Name = "Quarters", Hardpoint = HardpointType.Tool, Shape = new Shape(), Price = 1, Behaviors = { new HabitationData { Capacity = 1 } } });
|
||||
// Every station carries Crew Quarters on a Facility row, installed through a not-offered product (the Outpost is two cells wider
|
||||
// for its row: it keeps its four interior gear cells).
|
||||
var quarters = seed.Upsert(new GearData { Name = "Quarters", Hardpoint = HardpointType.Facility, Shape = Solid(2, 2), Price = 1, Behaviors = { new HabitationData { Capacity = 1 } } });
|
||||
seed.Upsert(new FactionProductData { Name = "Quarters by Maker", Design = new CultRecordRef<CraftedItemData>(quarters.Key), Manufacturer = maker, NotOffered = true });
|
||||
// Hardpoint gear no hull in this catalog has a hardpoint for: it has no home.
|
||||
var orphan = seed.Upsert(new GearData { Name = "Orphan", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 1 });
|
||||
|
|
@ -112,7 +115,7 @@ public sealed class ConsumableSupplyTests : IDisposable
|
|||
if (holds != Holds.Pinned)
|
||||
{
|
||||
sold.Add(("Cutter", seed.Upsert(new HullData { Name = "Cutter", HullType = HullType.Ship, Shape = Solid(5, 3), Price = 100 }).Key));
|
||||
sold.Add(("Outpost", seed.Upsert(new HullData { Name = "Outpost", HullType = HullType.Station, Kind = hub, Shape = Solid(5, 4), Price = 100 }).Key));
|
||||
sold.Add(("Outpost", seed.Upsert(new HullData { Name = "Outpost", HullType = HullType.Station, Kind = hub, Shape = Solid(6, 4), Price = 100, Hardpoints = { CrewRow() } }).Key));
|
||||
sold.Add(("Plate", seed.Upsert(new GearData { Name = "Plate", Hardpoint = HardpointType.Tool, Shape = Solid(2, 2), Price = 1 }).Key));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,6 +148,36 @@ public sealed class HabitationTests : IDisposable
|
|||
Assert.Equal(0, partial.Held(_water));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AnUnsetRowOwesNothing()
|
||||
{
|
||||
// A row that names no commodity consumes nothing and keeps nothing owed, however long it steps: Owed stays a fraction below one.
|
||||
var data = Table();
|
||||
data.Table.Add(new HabitationRow { PerOccupantHour = 1000, Basic = true });
|
||||
var hold = Stocked(1000, 1000);
|
||||
Habitants state = null;
|
||||
for (var span = 0; span < 50; span++) (state, _) = Upkeep.Advance(data, state, 3600, hold);
|
||||
Assert.Equal(3, state.Owed.Length);
|
||||
Assert.Equal(0, state.Owed[2]);
|
||||
Assert.All(state.Owed, owed => Assert.InRange(owed, 0, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADisabledOrDestroyedHabitationUnitBuysNothing()
|
||||
{
|
||||
// StationWants.Drawn reads the unit's table only while it runs: a unit switched off or shot out is no crew.
|
||||
var world = Build();
|
||||
var eaten = new[] { _water, _air };
|
||||
Assert.All(eaten, good => Assert.Contains(good, StationWants.Of(world.Station)));
|
||||
var unit = world.Station.Equipment.Single(equipped => equipped.Behaviors.OfType<Habitation>().Any());
|
||||
unit.Enabled.Value = false;
|
||||
Assert.All(eaten, good => Assert.DoesNotContain(good, StationWants.Of(world.Station)));
|
||||
unit.Enabled.Value = true;
|
||||
Assert.All(eaten, good => Assert.Contains(good, StationWants.Of(world.Station)));
|
||||
unit.EquippableItem.Durability = 0;
|
||||
Assert.All(eaten, good => Assert.DoesNotContain(good, StationWants.Of(world.Station)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStateIsFullCapacity()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -151,11 +151,15 @@ public sealed partial class RunStartTests : IDisposable
|
|||
.Concat(station.CargoBays.SelectMany(bay => bay.Cargo.Keys).OfType<CraftedItemInstance>())
|
||||
.Select(item => (_items.GetData(item).Name, _items.Brand(item).Product));
|
||||
|
||||
// Station plant: a not-offered product whose design mounts on a Facility row. The one exemption from the reach rule.
|
||||
private bool IsInstalledPlant(FactionProductData product) =>
|
||||
product.NotOffered && _cache.Get(product.Design) is EquippableItemData design && design.HardpointType == HardpointType.Facility;
|
||||
|
||||
private string Maker(FactionProductData product) => product == null ? "nobody" : _cache.Get(product.Manufacturer)?.Name ?? "nobody";
|
||||
|
||||
// Every faction's stations, in a main-sector galaxy, carry a heater and a reactor, and nothing, equipped or
|
||||
// stocked, from a manufacturer that faction cannot reach (LoadoutGenerator.IsAvailable, the one reach rule). Installed plant, which a
|
||||
// not-offered product makes (the Crew Quarters, as a facility), is no one's draw and so outside the rule.
|
||||
// stocked, from a manufacturer that faction cannot reach (LoadoutGenerator.IsAvailable, the one reach rule). Only station plant, a
|
||||
// not-offered product of Facility gear on a Facility row (the kind's facilities and the Crew Quarters), is no one's draw and so outside it.
|
||||
[Fact]
|
||||
public void EveryFactionsStationsCarryOnlyGearItCanReachIncludingAHeaterAndAReactor()
|
||||
{
|
||||
|
|
@ -170,7 +174,7 @@ public sealed partial class RunStartTests : IDisposable
|
|||
var station = EntitySerializer.Unpack(_items, zone, generator.GenerateStationLoadout(TestStationKinds.TradeHub));
|
||||
Assert.True(station.Equipment.Count(IsHeater) == 1, $"{faction.Name} station {i}: no heater");
|
||||
Assert.True(station.Equipment.Any(item => item.Behaviors.OfType<Reactor>().Any()), $"{faction.Name} station {i}: no reactor");
|
||||
var unreachable = Made(station).Where(made => made.product == null || (LoadoutGenerator.IsOffered(_cache, made.product) && !generator.IsAvailable(made.product))).ToList();
|
||||
var unreachable = Made(station).Where(made => made.product == null || (!IsInstalledPlant(made.product) && !generator.IsAvailable(made.product))).ToList();
|
||||
Assert.True(unreachable.Count == 0,
|
||||
$"{faction.Name} station {i} carries {string.Join(", ", unreachable.Select(u => u.item + " by " + Maker(u.product)))}");
|
||||
}
|
||||
|
|
@ -220,7 +224,7 @@ public sealed partial class RunStartTests : IDisposable
|
|||
{
|
||||
station = EntitySerializer.Unpack(_items, zone, generator.GenerateStationLoadout(TestStationKinds.TradeHub));
|
||||
Assert.True(station.Equipment.Any(item => item.Behaviors.OfType<Reactor>().Any()), $"station {i}: no reactor");
|
||||
var foreign = Made(station).Where(made => made.product == null || (LoadoutGenerator.IsOffered(_cache, made.product) && !generator.IsAvailable(made.product)) ||
|
||||
var foreign = Made(station).Where(made => made.product == null || (!IsInstalledPlant(made.product) && !generator.IsAvailable(made.product)) ||
|
||||
made.product.Manufacturer.Key.Equals(_cache.RefOf(zhestokost).Key)).ToList();
|
||||
Assert.True(foreign.Count == 0, $"station {i} carries {string.Join(", ", foreign.Select(u => u.item + " by " + Maker(u.product)))}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ public sealed class StationFacilityFitTests
|
|||
foreach (var (maker, kind, seed) in cases)
|
||||
{
|
||||
var (items, station) = Generate(cache, maker, kind, seed);
|
||||
var wanted = cache.Get(kind).Facilities.Select(facility => cache.Get(facility).Name).OrderBy(name => name, StringComparer.Ordinal).ToArray();
|
||||
// The kind's facilities and the one Crew Quarters every station carries (StationKinds.InstalledDesigns).
|
||||
var wanted = StationKinds.InstalledDesigns(cache, cache.Get(kind)).Select(design => design.Name).OrderBy(name => name, StringComparer.Ordinal).ToArray();
|
||||
Assert.Equal(wanted, FacilityKeys(station));
|
||||
Assert.All(station.Equipment.Concat<EquippedItem>(station.CargoBays).Where(item => item.Data.HardpointType == HardpointType.Facility),
|
||||
item => Assert.Equal(HardpointType.Facility, item.Hardpoint.Type));
|
||||
|
|
@ -70,7 +71,9 @@ public sealed class StationFacilityFitTests
|
|||
using var cache = RestoredHullsTests.OpenCatalog();
|
||||
var mining = cache.Get(Kind("mining"));
|
||||
var extra = cache.Get(Kind("processing")).Facilities.First();
|
||||
// Twice, so the kind needs three rows whichever hull of the kind is drawn: no hull has more than two.
|
||||
// Three times, so the kind needs five rows whichever hull of the kind is drawn: no hull has more than three (two for its facilities
|
||||
// and the Crew Quarters' row).
|
||||
mining.Facilities.Add(extra);
|
||||
mining.Facilities.Add(extra);
|
||||
mining.Facilities.Add(extra);
|
||||
var maker = cache.GetAll<Faction>().First(faction => StationKinds.FieldableKindsOf(cache, faction).Any(kind => kind.Key.Equals(Kind("mining").Key)));
|
||||
|
|
|
|||
|
|
@ -203,12 +203,14 @@ public sealed class StationKindTests : IDisposable
|
|||
public void AStationGeneratesWithItsFacilityRowUnfilledAndUnlogged()
|
||||
{
|
||||
var world = World.Make(this, zenithOffered: true);
|
||||
Assert.Single(world.Zenith.Hardpoints, row => row.Type == HardpointType.Facility);
|
||||
Assert.Equal(2, world.Zenith.Hardpoints.Count(row => row.Type == HardpointType.Facility)); // its kind's silo row and the Crew Quarters' row
|
||||
for (uint seed = 1; seed <= 8; seed++)
|
||||
{
|
||||
var pack = world.Generator(world.Au, seed).GenerateStationLoadout(Kind("trade-hub"));
|
||||
Assert.Equal("Zenith", world.HullName(pack));
|
||||
Assert.DoesNotContain(pack.Equipment, entry => entry.item != null && ((EquippableItemData) world.Items.GetData(entry.item)).HardpointType == HardpointType.Facility);
|
||||
// Only the Crew Quarters sits on a Facility row of Zenith's pack (the trade hub's silo is a bay): nothing else decides a row.
|
||||
Assert.All(pack.Equipment.Where(entry => entry.item != null && ((EquippableItemData) world.Items.GetData(entry.item)).HardpointType == HardpointType.Facility),
|
||||
entry => Assert.True(StationKinds.IsCrewQuarters(world.Items.GetData(entry.item))));
|
||||
}
|
||||
Assert.DoesNotContain(world.Log, line => line.Contains("Facility hardpoint"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue