Tests: a loadout may reference products; the unavailable-product test fails one design; distribution tests spread their seeds
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
94ab2d3f50
commit
00956ce329
2 changed files with 9 additions and 4 deletions
|
|
@ -252,7 +252,8 @@ public sealed class LoadoutTests : IDisposable
|
|||
Assert.DoesNotContain(forbidden, bad => bad.IsAssignableFrom(type));
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(CultRecordRef<>))
|
||||
{
|
||||
Assert.True(typeof(EquippableItemData).IsAssignableFrom(type.GetGenericArguments()[0]), $"{type} names a non-design record");
|
||||
var named = type.GetGenericArguments()[0];
|
||||
Assert.True(typeof(EquippableItemData).IsAssignableFrom(named) || named == typeof(FactionProductData), $"{type} names a record that is neither a design nor a product");
|
||||
continue;
|
||||
}
|
||||
if (type.IsArray) pending.Enqueue(type.GetElementType());
|
||||
|
|
@ -336,7 +337,8 @@ public sealed class LoadoutTests : IDisposable
|
|||
using var cache = Open();
|
||||
var items = new ItemManager(cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _ => { });
|
||||
var failures = new List<string>();
|
||||
Assert.Null(Loadouts.Materialize(items, null, HandBuilt(cache), _ => null, failures));
|
||||
var soleProduct = SoleProduct(cache);
|
||||
Assert.Null(Loadouts.Materialize(items, null, HandBuilt(cache), design => design.Name == "Lamp" ? null : soleProduct(design), failures));
|
||||
Assert.Equal("slot 0,0: no available product of Lamp", Assert.Single(failures));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,9 @@ public sealed class ProductChoiceTests : IDisposable
|
|||
};
|
||||
}
|
||||
|
||||
// Small seeds give correlated first draws, so the seeds a distribution test runs over are spread across the range.
|
||||
private static uint Seed(int i) => unchecked((uint) (i * 2654435761L));
|
||||
|
||||
private static Entity Materialize(Rig rig, Loadout loadout, Func<CraftedItemData, FactionProductData> choose, List<string> failures) =>
|
||||
Loadouts.Materialize(rig.Items, null, loadout, choose, failures);
|
||||
|
||||
|
|
@ -142,7 +145,7 @@ public sealed class ProductChoiceTests : IDisposable
|
|||
{
|
||||
var rig = Build("lamp-z", "lamp-a");
|
||||
var lamp = rig.Cache.GetByName<GearData>("Lamp");
|
||||
var drawn = Enumerable.Range(1, 200).Select(seed => rig.Outfitter(rig.OutBoth, (uint) seed).ChooseProduct(lamp).Name).ToArray();
|
||||
var drawn = Enumerable.Range(1, 200).Select(i => rig.Outfitter(rig.OutBoth, Seed(i)).ChooseProduct(lamp).Name).ToArray();
|
||||
var alpha = drawn.Count(name => name == "lamp-a");
|
||||
Assert.InRange(alpha, 160, 199);
|
||||
Assert.Contains("lamp-z", drawn);
|
||||
|
|
@ -154,7 +157,7 @@ public sealed class ProductChoiceTests : IDisposable
|
|||
var rig = Build("lamp-z", "lamp-a");
|
||||
var lamp = rig.Cache.GetByName<GearData>("Lamp");
|
||||
Assert.Equal(rig.Outfitter(null, 7).ChooseProduct(lamp).Name, rig.Outfitter(null, 7).ChooseProduct(lamp).Name);
|
||||
var seen = Enumerable.Range(1, 64).Select(seed => rig.Outfitter(null, (uint) seed).ChooseProduct(lamp).Name).Distinct().OrderBy(name => name).ToArray();
|
||||
var seen = Enumerable.Range(1, 64).Select(i => rig.Outfitter(null, Seed(i)).ChooseProduct(lamp).Name).Distinct().OrderBy(name => name).ToArray();
|
||||
Assert.Equal(new[] { "lamp-a", "lamp-z" }, seen);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue