Aetheria/tests/Aetheria.Shared.Tests/StationKindDescriptionTests.cs
Nibu dcd27cb3b0 Station-kind descriptions name only goods a recipe makes or takes
Uranium, Hydrogen (and Bacteria, Fungi, Animal Products) were named by mining, volatiles, agriculture, habitat-support and power descriptions with no recipe behind them. Dropped the claims (smaller than authoring a power chain); batch StationKindDescriptions restates the five kinds in the catalog; test pins the rule.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-11 05:59:44 +00:00

66 lines
4 KiB
C#

using System.Linq;
using System.Text.RegularExpressions;
using GameCult.Caching;
using Xunit;
// A station kind's description is what a player and a planner read of what it does; the recipes at the kind are what it does.
public sealed class StationKindDescriptionTests
{
// Every good the shipped catalog extracts at a station kind (a commodity recipe with no inputs; a gear recipe is a design on offer, not raw) is named in that kind's description.
// Kills: a kind that gains an extraction recipe (Diamond at mining, Ammonia at volatiles) while its description still lists the old set.
[Fact]
public void EveryRawGoodAKindExtractsIsNamedInItsDescription()
{
using var db = AetherDb.Open();
var cache = db.Cache;
var unnamed = cache.GetAll<RecipeData>().Where(recipe => recipe.Inputs.Count == 0 && recipe.StationKind.IsSet())
.Select(recipe => (Kind: cache.Get(recipe.StationKind), Output: cache.Get(recipe.Output)))
.Where(pair => pair.Kind != null && (pair.Output is SimpleCommodityData || pair.Output is CompoundCommodityData) && !pair.Kind.Description.Contains(pair.Output.Name))
.Select(pair => $"{pair.Kind.Name} extracts {pair.Output.Name}, which its description omits")
.Distinct().OrderBy(line => line).ToList();
Assert.True(unnamed.Count == 0, string.Join("\n", unnamed));
}
// The two kinds the rule was cut for, by name, so the rule cannot pass by the catalog having lost the recipes.
[Fact]
public void MiningExtractsDiamondAndVolatilesAmmonia()
{
using var db = AetherDb.Open();
var cache = db.Cache;
string Extracted(string kindId) => string.Join(",", cache.GetAll<RecipeData>()
.Where(recipe => recipe.Inputs.Count == 0 && recipe.StationKind.IsSet() && recipe.StationKind.Key.Equals(StationKindData.KeyOf(kindId)))
.Select(recipe => cache.Get(recipe.Output).Name));
Assert.Contains("Diamond", Extracted("mining"));
Assert.Contains("Ammonia", Extracted("volatiles"));
Assert.Contains("Diamond", cache.Get<StationKindData>(StationKindData.KeyOf("mining")).Description);
Assert.Contains("Ammonia", cache.Get<StationKindData>(StationKindData.KeyOf("volatiles")).Description);
}
// Kills: a station-kind description naming a commodity no recipe yields or consumes (Uranium, Hydrogen, Bacteria, Fungi and
// Animal Products were named by the shipped descriptions with no recipe behind them).
[Fact]
public void EveryCommodityAStationKindNamesIsMadeOrTakenByARecipe()
{
using var db = AetherDb.Open();
var c = db.Cache;
var used = c.GetAll<RecipeData>().SelectMany(r => r.Inputs.Select(i => i.Commodity.Key.Value).Append(r.Output.Key.Value)).ToHashSet();
var commodities = c.GetAll<SimpleCommodityData>().ToArray();
Assert.True(commodities.Length >= 20 && used.Count >= 20, $"fixture: the catalog holds its commodities and recipes ({commodities.Length}, {used.Count})");
var kinds = c.GetAll<StationKindData>().ToArray();
Assert.True(kinds.Length >= 17, $"fixture: the catalog holds its station kinds ({kinds.Length})");
var orphans = from kind in kinds
from good in commodities
where Regex.IsMatch(kind.Description ?? "", @"\b" + Regex.Escape(good.Name) + @"\b") && !used.Contains(c.RefOf(good).Key.Value)
select $"{kind.Name} names {good.Name}";
Assert.True(!orphans.Any(), string.Join("\n", orphans));
}
// Kills: the fresh-catalog text and the shipped catalog saying different things about the same kind.
[Fact]
public void TheShippedDescriptionsAreTheAuthoredTable()
{
using var db = AetherDb.Open();
foreach (var id in new[] { "mining", "volatiles", "agriculture", "habitat-support", "power" })
Assert.Equal(StationKindsCatalog.DescriptionOf(id), db.Cache.Get<StationKindData>(StationKindData.KeyOf(id)).Description);
}
}