Merge eureka/aetheria-release-product-tiers (head e6a17a5e)
Reports cut-product-tiers h1/h2; Soul verdicts s1, s2 hold. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
d83cacc6a7
16 changed files with 949 additions and 43 deletions
|
|
@ -36,7 +36,7 @@ public sealed class CatalogRoleTests
|
|||
}
|
||||
|
||||
// The whole of CB-R1 over every design in the catalog: each non-flat stat reads exactly one declared role, every
|
||||
// declared role is read, and every seller authors each role once. Weapons, and designs of a kind the tool keeps a role
|
||||
// declared role is read, and every seller authors each role once (a bin authors none: it reads its line's). Weapons, and designs of a kind the tool keeps a role
|
||||
// map for, must also carry a non-flat stat (a design with no stat at all has nothing for quality to vary).
|
||||
[Fact]
|
||||
public void ShippedCatalogRolesAreLive()
|
||||
|
|
@ -59,13 +59,15 @@ public sealed class CatalogRoleTests
|
|||
broken.Add($"{design.Name}: declares [{string.Join(", ", declared)}] but non-flat stats read [{string.Join(", ", read)}]");
|
||||
if (varying.Length == 0 && stats.Length > 0 && (design is WeaponItemData || Program.HasRoleMap(design)))
|
||||
broken.Add($"{design.Name}: every stat is flat");
|
||||
foreach (var product in products.Where(p => p.Design.Key.Equals(cache.RefOf(design).Key)))
|
||||
foreach (var product in products.Where(p => p.Bin == null && p.Design.Key.Equals(cache.RefOf(design).Key)))
|
||||
{
|
||||
var authored = (product.Roles ?? new List<ProductRole>()).Select(r => r.Role).OrderBy(r => r, StringComparer.Ordinal).ToArray();
|
||||
if (!authored.SequenceEqual(declared))
|
||||
broken.Add($"{design.Name}: product \"{product.Name}\" authors [{string.Join(", ", authored)}], not each of [{string.Join(", ", declared)}] once");
|
||||
}
|
||||
}
|
||||
foreach (var bin in products.Where(p => p.Bin != null))
|
||||
if (bin.Roles?.Count > 0 || bin.Assembly != null) broken.Add($"bin \"{bin.Name}\" authors roles or an assembly of its own");
|
||||
Assert.True(broken.Count == 0, string.Join("\n", broken));
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +266,7 @@ public sealed class CatalogRoleTests
|
|||
var profiles = new Dictionary<string, (float Mean, float Dev)>(Program.MakerProfiles) { ["Pirates"] = (.45f, .22f) };
|
||||
foreach (var design in new[] { autocannon, lrm, srm, mine, drive })
|
||||
{
|
||||
var sellers = cache.GetAll<FactionProductData>().Where(p => p.Design.Key.Equals(cache.RefOf(design).Key)).ToArray();
|
||||
var sellers = cache.GetAll<FactionProductData>().Where(p => p.Bin == null && p.Design.Key.Equals(cache.RefOf(design).Key)).ToArray();
|
||||
Assert.NotEmpty(sellers);
|
||||
foreach (var product in sellers)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -622,6 +622,13 @@ public sealed class LoadoutTests : IDisposable
|
|||
var result = items.GetTier((CraftedItemInstance) items.CreateInstance(lot));
|
||||
Assert.Equal(settings.Tiers[0].Name, result.tier.Name);
|
||||
Assert.Equal(2, result.upgrades);
|
||||
|
||||
// The same width from the other side (follow-up tier-upgrade-step-two-sided): two steps less a hair is one upgrade, so a
|
||||
// step narrower than .0499 reads two and a wider one reads none.
|
||||
var under = items.Lots.Add(new Lot { Design = cache.RefOf<ItemData>(lamp), Origin = new Attributed(), Quality = settings.Tiers[0].Quality + 2 * .0499f - .0001f, Roles = new List<RoleFill>() });
|
||||
var below = items.GetTier((CraftedItemInstance) items.CreateInstance(under));
|
||||
Assert.Equal(settings.Tiers[0].Name, below.tier.Name);
|
||||
Assert.Equal(1, below.upgrades);
|
||||
}
|
||||
|
||||
// S7 (docs/stats-and-power-cut.md Cut 1 findings): a Quality term must raise the lot's quality to its own
|
||||
|
|
|
|||
276
tests/Aetheria.Shared.Tests/ProductBinTests.cs
Normal file
276
tests/Aetheria.Shared.Tests/ProductBinTests.cs
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using Xunit;
|
||||
|
||||
// A bin is a product of its maker's line above a floor (aetheria-release, cut product-tiers; ruling maker-design-tiers-allowed):
|
||||
// the mint derives its distributions from the line on every lot, truncated below line mean + Floor deviations, and the lot is
|
||||
// still the bin's. Lots here come from CreateLot(product), the production mint, on the AssemblyFromMakerTests fixture.
|
||||
public sealed class ProductBinTests : IDisposable
|
||||
{
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-bins-" + Guid.NewGuid().ToString("N"));
|
||||
private readonly CultCache _cache;
|
||||
private readonly ItemManager _items;
|
||||
private readonly CultRecordRef<CraftedItemData> _lens;
|
||||
private readonly List<string> _log = new List<string>();
|
||||
|
||||
public ProductBinTests()
|
||||
{
|
||||
Directory.CreateDirectory(_root);
|
||||
_cache = AetheriaStores.Open(Path.Combine(_root, "Aetheria.cc"), catalogWritable: true);
|
||||
var gear = _cache.Upsert(new GearData
|
||||
{
|
||||
Name = "Lensed", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10,
|
||||
Roles = { new ItemRole { Name = "lens" } }
|
||||
});
|
||||
_lens = new CultRecordRef<CraftedItemData>(gear.Key);
|
||||
_items = new ItemManager(_cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), _log.Add) { Random = new CultMath.Random(7u) };
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_cache.Dispose();
|
||||
Directory.Delete(_root, true);
|
||||
}
|
||||
|
||||
private static AssemblyDistribution A(float mean, float deviation) => new AssemblyDistribution { Mean = mean, StandardDeviation = deviation };
|
||||
|
||||
// A maker at assembly .6 +- .1 and a line of the Lensed design at lens .5 +- .1.
|
||||
private FactionProductData Line(string name = "Line", float lensMean = .5f, float lensDeviation = .1f, AssemblyDistribution own = null, float makerMean = .6f)
|
||||
{
|
||||
var maker = _cache.Upsert(new Faction { Name = name + " Maker", Assembly = A(makerMean, .1f) });
|
||||
_cache.Upsert(new FactionProductData
|
||||
{
|
||||
Name = name, Design = _lens, Manufacturer = maker, Assembly = own,
|
||||
Roles = { new ProductRole { Role = "lens", Mean = lensMean, StandardDeviation = lensDeviation } }
|
||||
});
|
||||
return _cache.GetAll<FactionProductData>().Single(p => p.Name == name);
|
||||
}
|
||||
|
||||
private FactionProductData Bin(FactionProductData line, string name, float floor)
|
||||
{
|
||||
_cache.Upsert(new FactionProductData
|
||||
{
|
||||
Name = name, Design = line.Design, Manufacturer = line.Manufacturer,
|
||||
Bin = new ProductBin { Line = _cache.RefOf(line), Floor = floor }
|
||||
});
|
||||
return _cache.GetAll<FactionProductData>().Single(p => p.Name == name);
|
||||
}
|
||||
|
||||
private Lot[] Mint(FactionProductData product, int count) =>
|
||||
Enumerable.Range(0, count).Select(_ => _items.Lots[_items.CreateLot(product)]).ToArray();
|
||||
|
||||
private static float[] Fills(Lot[] lots) => lots.Select(l => l.Roles.Single().Quality).ToArray();
|
||||
|
||||
// Floor 0 is the top half of the line: nothing under the line's mean, in the fills or in the assembly.
|
||||
[Fact]
|
||||
public void BinnedFillsAndAssemblyNeverFallBelowTheFloor()
|
||||
{
|
||||
var lots = Mint(Bin(Line(), "Top Half", 0), 400);
|
||||
Assert.All(lots, lot =>
|
||||
{
|
||||
Assert.True(lot.Roles.Single().Quality >= .5f - 1e-5f, "a fill fell under the line's mean");
|
||||
Assert.True(lot.Quality >= .6f - 1e-5f, "an assembly fell under the maker's mean");
|
||||
});
|
||||
Assert.InRange(Fills(lots).Average(), .55f, .60f);
|
||||
}
|
||||
|
||||
// The floor is in the line's standard deviations: .67 on .5 +- .1 cuts at .567 and the truncated mean is .627.
|
||||
[Fact]
|
||||
public void FloorIsInDeviations()
|
||||
{
|
||||
var fills = Fills(Mint(Bin(Line(), "Top Quarter", .67f), 400));
|
||||
Assert.All(fills, fill => Assert.True(fill >= .567f - 1e-5f, "a fill fell under mean + floor deviations"));
|
||||
Assert.InRange(fills.Average(), .61f, .645f);
|
||||
}
|
||||
|
||||
// A bin keeps no distribution of its own: after it exists, the line and the maker move and the bin follows.
|
||||
[Fact]
|
||||
public void BinDerivesFromItsLineNotACopy()
|
||||
{
|
||||
var line = Line();
|
||||
var bin = Bin(line, "Follower", 0);
|
||||
Assert.Empty(bin.Roles);
|
||||
Assert.Null(bin.Assembly);
|
||||
line.Roles.Single().Mean = .7f;
|
||||
var maker = _cache.Get(line.Manufacturer);
|
||||
maker.Assembly = A(.8f, .1f);
|
||||
_cache.Commit(batch =>
|
||||
{
|
||||
batch.Upsert(typeof(FactionProductData), line, _cache.RefOf(line).Key);
|
||||
batch.Upsert(typeof(Faction), maker, _cache.RefOf(maker).Key);
|
||||
});
|
||||
var lots = Mint(bin, 300);
|
||||
Assert.All(lots, lot =>
|
||||
{
|
||||
Assert.True(lot.Roles.Single().Quality >= .7f - 1e-5f, "the bin read a copy of its line's fill");
|
||||
Assert.True(lot.Quality >= .8f - 1e-5f, "the bin read a copy of its maker's assembly");
|
||||
});
|
||||
}
|
||||
|
||||
// A line's own assembly is the final test a bin of it sits: the maker's is read only when the line sets none.
|
||||
[Fact]
|
||||
public void BinReadsTheLinesOwnAssemblyBeforeTheMakers()
|
||||
{
|
||||
var bin = Bin(Line(own: A(.85f, .05f), makerMean: .4f), "Certified", 0);
|
||||
Assert.All(Mint(bin, 300), lot => Assert.True(lot.Quality >= .85f - 1e-5f, "the bin assembled as its maker, not its line"));
|
||||
}
|
||||
|
||||
// 6 deviations above a .2 +- .01 line is out of reach in 64 draws: the mint returns the cutoff, .26, and does not loop.
|
||||
[Fact]
|
||||
public void UnreachableFloorMintsAtTheCutoff()
|
||||
{
|
||||
var bin = Bin(Line(lensMean: .2f, lensDeviation: .01f, own: A(.2f, .01f)), "Unreachable", 6);
|
||||
Assert.All(Mint(bin, 20), lot =>
|
||||
{
|
||||
Assert.Equal(.26f, lot.Roles.Single().Quality, 5);
|
||||
Assert.Equal(.26f, lot.Quality, 5);
|
||||
});
|
||||
}
|
||||
|
||||
// The search draws at most 64 times, and stops at the first draw that clears the cutoff: the stream after it is what shows how
|
||||
// many draws it took. An unreachable cutoff takes exactly 64, a deviation of 0 (draw equal to the cutoff) takes 1.
|
||||
[Fact]
|
||||
public void TheSearchDrawsAtMostSixtyFourTimesAndStopsAtTheFirstDrawThatClearsTheCutoff()
|
||||
{
|
||||
float AfterDraws(int draws)
|
||||
{
|
||||
var random = new CultMath.Random(11u);
|
||||
for (var i = 0; i < draws; i++) random.NextGaussian(0, 1);
|
||||
return random.NextGaussian(0, 1);
|
||||
}
|
||||
|
||||
var unreachable = new CultMath.Random(11u);
|
||||
Assert.Equal(40f, unreachable.NextGaussianAbove(0, 1, 40f));
|
||||
Assert.Equal(AfterDraws(64), unreachable.NextGaussian(0, 1));
|
||||
|
||||
var immediate = new CultMath.Random(11u);
|
||||
Assert.Equal(.5f, immediate.NextGaussianAbove(.5f, 0, 0));
|
||||
Assert.Equal(AfterDraws(1), immediate.NextGaussian(0, 1));
|
||||
}
|
||||
|
||||
// Snapshot of the first five assemblies and fills at base, before the bin existed (seed 20261018, lens .5 +- .1, maker .6 +- .1).
|
||||
[Fact]
|
||||
public void UnbinnedMintConsumesTheStreamAsBefore()
|
||||
{
|
||||
var line = Line();
|
||||
_items.Random = new CultMath.Random(20261018u);
|
||||
var lots = Mint(line, 5);
|
||||
Assert.Empty(_log);
|
||||
var assemblies = new[] { .59560823f, .68289334f, .57563853f, .5639112f, .59828424f };
|
||||
var fills = new[] { .6311789f, .5835483f, .47641385f, .46416125f, .45124212f };
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
Assert.Equal(assemblies[i], lots[i].Quality, 5);
|
||||
Assert.Equal(fills[i], lots[i].Roles.Single().Quality, 5);
|
||||
}
|
||||
}
|
||||
|
||||
// The lot is the bin's: its product, its title, and the line's maker as its brand.
|
||||
[Fact]
|
||||
public void ABinnedLotIsBrandedAsTheBin()
|
||||
{
|
||||
var line = Line();
|
||||
var bin = Bin(line, "Premiere", 0);
|
||||
var lotId = _items.CreateLot(bin);
|
||||
Assert.Equal(_cache.RefOf(bin), _items.Lots[lotId].Product);
|
||||
var instance = _items.CreateInstance(lotId);
|
||||
Assert.Equal("Premiere", _items.Title(instance));
|
||||
var (maker, product) = _items.Brand(instance);
|
||||
Assert.Equal(_cache.Get(line.Manufacturer).Name, maker.Name);
|
||||
Assert.Equal("Premiere", product.Name);
|
||||
}
|
||||
|
||||
// The line a bin draws from is the one Bin.Line names, not another line of the design: three lines of one design, by three
|
||||
// makers, with the bin on the middle one by name, so a bin that reads the first or the last line of the design is far off.
|
||||
[Fact]
|
||||
public void ABinMintsFromExactlyTheLineItNames()
|
||||
{
|
||||
Line("A line", lensMean: .3f, makerMean: .2f);
|
||||
var middle = Line("M line", lensMean: .6f, makerMean: .5f);
|
||||
Line("Z line", lensMean: .9f, makerMean: .9f);
|
||||
var lots = Mint(Bin(middle, "Middle Premiere", 0), 400);
|
||||
Assert.All(lots, lot =>
|
||||
{
|
||||
Assert.True(lot.Roles.Single().Quality >= .6f - 1e-5f, "a fill came from a line below the named one");
|
||||
Assert.True(lot.Quality >= .5f - 1e-5f, "an assembly came from a maker below the named line's");
|
||||
});
|
||||
Assert.InRange(Fills(lots).Average(), .64f, .72f);
|
||||
Assert.InRange(lots.Average(lot => lot.Quality), .55f, .62f);
|
||||
}
|
||||
|
||||
private const string Canary = "canary-7f3a91";
|
||||
|
||||
private enum Damage { None, LineRemoved, LineIsBin }
|
||||
|
||||
// A catalog on disk holding one line and a bin of it, damaged as asked, for AetheriaStores.Open to read.
|
||||
private string DamagedCatalog(float floor, Damage damage)
|
||||
{
|
||||
var path = Path.Combine(_root, Guid.NewGuid().ToString("N"), "Aetheria.cc");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
using var seed = AetheriaStores.Open(path, catalogWritable: true);
|
||||
seed.Upsert(new VerseGrammar { Revision = 1 });
|
||||
var maker = seed.Upsert(new Faction { Name = Canary + " Maker" });
|
||||
var gear = seed.Upsert(new GearData { Name = "Lensed", Hardpoint = HardpointType.Sensors, Shape = new Shape(), Price = 10, Roles = { new ItemRole { Name = "lens" } } });
|
||||
var design = new CultRecordRef<CraftedItemData>(gear.Key);
|
||||
var line = seed.Upsert(new FactionProductData { Name = Canary + " Line", Design = design, Manufacturer = maker, Roles = { new ProductRole { Role = "lens" } } });
|
||||
var bin = seed.Upsert(new FactionProductData { Name = Canary, Design = design, Manufacturer = maker, Bin = new ProductBin { Line = line, Floor = floor } });
|
||||
if (damage == Damage.LineIsBin)
|
||||
seed.Upsert(new FactionProductData { Name = Canary + " Nested", Design = design, Manufacturer = maker, Bin = new ProductBin { Line = bin, Floor = 0 } });
|
||||
if (damage == Damage.LineRemoved) seed.Remove(line.Key);
|
||||
seed.FlushAsync().Wait();
|
||||
return path;
|
||||
}
|
||||
|
||||
// The runtime does not trust authoring for a bin: a NaN floor would weigh NaN and null every draw of its design.
|
||||
[Theory]
|
||||
[InlineData(float.NaN)]
|
||||
[InlineData(float.PositiveInfinity)]
|
||||
[InlineData(float.NegativeInfinity)]
|
||||
public void ACatalogWhoseBinFloorIsNotFiniteIsRefusedWhereItIsRead(float floor)
|
||||
{
|
||||
var refusal = Assert.Throws<InvalidOperationException>(() => AetheriaStores.Open(DamagedCatalog(floor, Damage.None)));
|
||||
Assert.Contains("Floor", refusal.Message);
|
||||
Assert.DoesNotContain(Canary, refusal.Message);
|
||||
Assert.DoesNotContain(floor.ToString(), refusal.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ACatalogWhoseBinNamesNoLineIsRefusedWhereItIsRead()
|
||||
{
|
||||
var refusal = Assert.Throws<InvalidOperationException>(() => AetheriaStores.Open(DamagedCatalog(.67f, Damage.LineRemoved)));
|
||||
Assert.Contains("Line", refusal.Message);
|
||||
Assert.DoesNotContain(Canary, refusal.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ACatalogWhoseBinNamesAnotherBinIsRefusedWhereItIsRead()
|
||||
{
|
||||
var refusal = Assert.Throws<InvalidOperationException>(() => AetheriaStores.Open(DamagedCatalog(.67f, Damage.LineIsBin)));
|
||||
Assert.Contains("Line", refusal.Message);
|
||||
Assert.DoesNotContain(Canary, refusal.Message);
|
||||
}
|
||||
|
||||
// The refusals are of damage, not of bins: a sound bin on a sound line reads.
|
||||
[Fact]
|
||||
public void ACatalogWithASoundBinIsRead()
|
||||
{
|
||||
using var cache = AetheriaStores.Open(DamagedCatalog(.67f, Damage.None));
|
||||
Assert.Equal(.67f, cache.GetAll<FactionProductData>().Single(product => product.Name == Canary).Bin.Floor);
|
||||
}
|
||||
|
||||
// A bin whose line the catalog does not hold mints as a product with no roles of its own, and says so.
|
||||
[Fact]
|
||||
public void ABinOfALineTheCatalogLacksMintsAtDefaultsAndLogs()
|
||||
{
|
||||
var line = Line();
|
||||
var bin = Bin(line, "Orphan", 0);
|
||||
_cache.Remove(_cache.RefOf(line).Key);
|
||||
var lots = Mint(bin, 5);
|
||||
Assert.Equal(5, lots.Length);
|
||||
Assert.Equal(5, _log.Count);
|
||||
Assert.All(_log, message => Assert.False(string.IsNullOrWhiteSpace(message)));
|
||||
}
|
||||
}
|
||||
|
|
@ -63,7 +63,10 @@ public sealed class ProductChoiceTests : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
private Rig Build(params string[] lampOrder)
|
||||
private Rig Build(params string[] lampOrder) => Build(new float[0], lampOrder);
|
||||
|
||||
// binFloors adds one bin of lamp-a's line per floor, named "lamp-a bin" and "lamp-a bin 2"..., by the same maker.
|
||||
private Rig Build(float[] binFloors, string[] lampOrder)
|
||||
{
|
||||
var root = Path.Combine(_root, "rig" + _catalogs++);
|
||||
Directory.CreateDirectory(root);
|
||||
|
|
@ -97,6 +100,12 @@ public sealed class ProductChoiceTests : IDisposable
|
|||
// lampOrder holds product names; the record key of the i-th inserted is "k" + i, so keys and insertion order
|
||||
// both follow the permutation.
|
||||
for (var i = 0; i < lampOrder.Length; i++) Sell(lampOrder[i], lamp.Key, makers[lampOrder[i]], "k" + i);
|
||||
for (var i = 0; i < binFloors.Length; i++)
|
||||
seed.Commit(batch => batch.Upsert(typeof(FactionProductData), new FactionProductData
|
||||
{
|
||||
Name = i == 0 ? "lamp-a bin" : "lamp-a bin " + (i + 1), Design = new CultRecordRef<CraftedItemData>(lamp.Key), Manufacturer = alpha,
|
||||
Bin = new ProductBin { Line = new CultRecordRef<FactionProductData>(new CultRecordKey("k" + Array.IndexOf(lampOrder, "lamp-a"))), Floor = binFloors[i] }
|
||||
}, new CultRecordKey("bin" + i)));
|
||||
seed.FlushAsync().Wait();
|
||||
}
|
||||
|
||||
|
|
@ -249,6 +258,90 @@ public sealed class ProductChoiceTests : IDisposable
|
|||
Assert.InRange(MakerDraws(rig, rig.OutEven, 1, "lamp-a", 300), 80, 120);
|
||||
}
|
||||
|
||||
// Ruling bin-share-by-floor: a bin of lamp-a's line takes the fraction of lamp-a's stock that would pass its floor, 1 - Phi(Floor),
|
||||
// of lamp-a's preference, and the line keeps the rest, so the maker's presence for the design is what it was without the bin.
|
||||
[Fact]
|
||||
public void ABinTakesItsPassFractionOfItsMakersPreference()
|
||||
{
|
||||
var alone = Build("lamp-z", "lamp-a");
|
||||
var preference = alone.Outfitter(alone.OutEven, 1, 0).ProductWeight(alone.Product("lamp-a"));
|
||||
Assert.True(preference > 0);
|
||||
|
||||
var quarter = Build(new[] { .67f }, new[] { "lamp-z", "lamp-a" });
|
||||
var generator = quarter.Outfitter(quarter.OutEven, 1, 0);
|
||||
Assert.Equal(.2514f * preference, generator.ProductWeight(quarter.Product("lamp-a bin")), 3);
|
||||
Assert.Equal(.7486f * preference, generator.ProductWeight(quarter.Product("lamp-a")), 3);
|
||||
Assert.Equal(preference, generator.ProductWeight(quarter.Product("lamp-a bin")) + generator.ProductWeight(quarter.Product("lamp-a")), 3);
|
||||
// Another maker's product, whose line has no bin, weighs what it did without any bin in the catalog.
|
||||
Assert.Equal(alone.Outfitter(alone.OutEven, 1, 0).ProductWeight(alone.Product("lamp-z")), generator.ProductWeight(quarter.Product("lamp-z")), 3);
|
||||
|
||||
var half = Build(new[] { 0f }, new[] { "lamp-z", "lamp-a" });
|
||||
generator = half.Outfitter(half.OutEven, 1, 0);
|
||||
Assert.Equal(.5f * preference, generator.ProductWeight(half.Product("lamp-a bin")), 3);
|
||||
Assert.Equal(.5f * preference, generator.ProductWeight(half.Product("lamp-a")), 3);
|
||||
|
||||
// The maker keeps its presence: Alpha's line and bin together draw as lamp-a alone did.
|
||||
var lamp = quarter.Cache.GetByName<GearData>("Lamp");
|
||||
var alpha = Enumerable.Range(1, 300).Count(i => quarter.Cache.Get(quarter.Outfitter(quarter.OutEven, Seed(i), 0).ChooseProduct(lamp).Manufacturer).Name == "Alpha");
|
||||
Assert.InRange(alpha, 180, 220);
|
||||
}
|
||||
|
||||
// A line gives up the sum of its bins' pass fractions and no more: two top-half bins leave it nothing, and a third does not
|
||||
// take it below nothing.
|
||||
[Fact]
|
||||
public void ALineKeepsWhatItsBinsLeaveAndNeverLessThanNothing()
|
||||
{
|
||||
var two = Build(new[] { 0f, .67f }, new[] { "lamp-z", "lamp-a" });
|
||||
var alone = Build("lamp-z", "lamp-a");
|
||||
var preference = alone.Outfitter(alone.OutEven, 1, 0).ProductWeight(alone.Product("lamp-a"));
|
||||
Assert.Equal((1 - .5f - .2514f) * preference, two.Outfitter(two.OutEven, 1, 0).ProductWeight(two.Product("lamp-a")), 3);
|
||||
|
||||
var three = Build(new[] { 0f, 0f, 0f }, new[] { "lamp-z", "lamp-a" });
|
||||
Assert.Equal(0f, three.Outfitter(three.OutEven, 1, 0).ProductWeight(three.Product("lamp-a")));
|
||||
}
|
||||
|
||||
// Ruling bin-share-by-floor holds on every draw of a design, not only the preference-weighted one. When every reachable maker
|
||||
// weighs 0 the ChooseProduct draw is by share alone, and Alpha's line and bin together keep the half they held as one product.
|
||||
[Fact]
|
||||
public void ABinLeavesItsMakersShareOfTheAllZeroWeightDrawUnchanged()
|
||||
{
|
||||
int AlphaDraws(Rig rig)
|
||||
{
|
||||
var lamp = rig.Cache.GetByName<GearData>("Lamp");
|
||||
var zero = rig.Cache.GetByName<Faction>("OutZero");
|
||||
return Enumerable.Range(1, 1000).Count(i => rig.Cache.Get(rig.Outfitter(zero, Seed(i), 0).ChooseProduct(lamp).Manufacturer).Name == "Alpha");
|
||||
}
|
||||
|
||||
Assert.InRange(AlphaDraws(Build("lamp-z", "lamp-a")), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { .67f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { 0f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
}
|
||||
|
||||
// The same for a required item that has fallen back to any manufacturer (OutNone is allied to nobody, so no product is on offer
|
||||
// and the fallback weighs every product alike, but for the bins' shares).
|
||||
[Fact]
|
||||
public void ABinLeavesItsMakersShareOfTheRequiredFallbackDrawUnchanged()
|
||||
{
|
||||
int AlphaDraws(Rig rig)
|
||||
{
|
||||
var log = new List<string>();
|
||||
var items = new ItemManager(rig.Cache, new ProvenanceLedger(), RunSaveTests.TestSettings(), log.Add);
|
||||
var lamp = rig.Cache.GetByName<GearData>("Lamp");
|
||||
var alpha = Enumerable.Range(1, 1000).Count(i =>
|
||||
{
|
||||
var random = new Random(Seed(i));
|
||||
var generator = new LoadoutGenerator(ref random, items, rig.Galaxy, null, rig.OutNone, .5f);
|
||||
return rig.Cache.Get(generator.RandomProduct<EquippableItemData>(0, design => design == lamp, required: true).product.Manufacturer).Name == "Alpha";
|
||||
});
|
||||
Assert.NotEmpty(log);
|
||||
return alpha;
|
||||
}
|
||||
|
||||
Assert.InRange(AlphaDraws(Build("lamp-z", "lamp-a")), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { .67f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
Assert.InRange(AlphaDraws(Build(new[] { 0f }, new[] { "lamp-z", "lamp-a" })), 440, 560);
|
||||
}
|
||||
|
||||
// A weight that read the allegiance alone would give 1 : .25 here, an 80% draw; the zone and allegiance together
|
||||
// give 1 : .125 for alpha at its own zone, 89%.
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Caching.MessagePack;
|
||||
using MessagePack;
|
||||
using Xunit;
|
||||
|
||||
// The weapon product lines the shipped catalog holds (campaign aetheria-release, cut product-lines-weapons; rulings
|
||||
|
|
@ -99,4 +101,61 @@ public sealed class ProductLinesCatalogTests
|
|||
}
|
||||
}
|
||||
}
|
||||
// Cut product-tiers: the six bins of the command's tier table are in the catalog, each a single product that names its line.
|
||||
[Fact]
|
||||
public void TierRowsAreShipped()
|
||||
{
|
||||
using var cache = RestoredHullsTests.OpenCatalog();
|
||||
var table = ProductLinesCommand.TierTable();
|
||||
Assert.Equal(6, table.Count);
|
||||
foreach (var row in table)
|
||||
{
|
||||
var bin = Assert.Single(cache.GetAll<FactionProductData>(), p => p.Name == row.Name);
|
||||
var line = Assert.Single(cache.GetAll<FactionProductData>(), p => p.Name == row.Line);
|
||||
Assert.Equal(cache.RefOf(line).Key, bin.Bin.Line.Key);
|
||||
Assert.Equal(line.Design.Key, bin.Design.Key);
|
||||
Assert.Equal(line.Manufacturer.Key, bin.Manufacturer.Key);
|
||||
Assert.Equal(row.Floor, bin.Bin.Floor);
|
||||
Assert.Equal(row.Description, bin.Description);
|
||||
Assert.Empty(bin.Roles);
|
||||
Assert.Null(bin.Assembly);
|
||||
}
|
||||
}
|
||||
|
||||
// A bin bins an unbinned line of its own design and maker, and the catalog holds no bin the table does not author.
|
||||
[Fact]
|
||||
public void BinsBinAnUnbinnedLineOfTheirOwnDesignAndMaker()
|
||||
{
|
||||
using var cache = RestoredHullsTests.OpenCatalog();
|
||||
var bins = cache.GetAll<FactionProductData>().Where(p => p.Bin != null).ToArray();
|
||||
Assert.Equal(ProductLinesCommand.TierTable().Select(r => r.Name).OrderBy(n => n, StringComparer.Ordinal), bins.Select(b => b.Name).OrderBy(n => n, StringComparer.Ordinal));
|
||||
foreach (var bin in bins)
|
||||
{
|
||||
var line = cache.Get(bin.Bin.Line);
|
||||
Assert.NotNull(line);
|
||||
Assert.Null(line.Bin);
|
||||
Assert.Equal(line.Design.Key, bin.Design.Key);
|
||||
Assert.Equal(line.Manufacturer.Key, bin.Manufacturer.Key);
|
||||
Assert.True(bin.Bin.Floor >= 0 && float.IsFinite(bin.Bin.Floor));
|
||||
}
|
||||
}
|
||||
|
||||
// FactionProductData slot 7 is additive under the same schema id: a bin round-trips, and a record written before the slot
|
||||
// existed (an array one element shorter) reads no bin.
|
||||
[Fact]
|
||||
public void BinIsSlotSevenAndACatalogWithoutItReadsNoBin()
|
||||
{
|
||||
var options = CultDocumentMessagePackSerialization.OptionsFor(typeof(FactionProductData).Assembly);
|
||||
var binned = MessagePackSerializer.Deserialize<FactionProductData>(
|
||||
MessagePackSerializer.Serialize(new FactionProductData { Name = "Binned", Bin = new ProductBin { Floor = .67f } }, options), options);
|
||||
Assert.Equal(.67f, binned.Bin.Floor);
|
||||
|
||||
var bytes = MessagePackSerializer.Serialize(new FactionProductData { Name = "Old", Description = "d" }, options);
|
||||
Assert.Equal(0x98, bytes[0]);
|
||||
Assert.Equal(0xC0, bytes[^1]);
|
||||
var before = new byte[] { 0x97 }.Concat(bytes.Skip(1).Take(bytes.Length - 2)).ToArray();
|
||||
var old = MessagePackSerializer.Deserialize<FactionProductData>(before, options);
|
||||
Assert.Equal("Old", old.Name);
|
||||
Assert.Null(old.Bin);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,9 @@ public abstract class ProductLinesCommandTests : IDisposable
|
|||
Assert.Equal(Names.Length, products.Length);
|
||||
_shipped = products.Select(p => Describe(cache, p)).OrderBy(x => x, StringComparer.Ordinal).ToArray();
|
||||
_shippedKeys = products.Select(p => cache.RefOf(p).Key.Value).OrderBy(x => x, StringComparer.Ordinal).ToArray();
|
||||
foreach (var product in products) Assert.True(cache.Remove(cache.RefOf(product).Key));
|
||||
// A bin cannot outlive its line (the catalog read refuses it), so the bins of the removed lines go with them.
|
||||
var binned = cache.GetAll<FactionProductData>().Where(p => p.Bin != null && products.Any(line => cache.RefOf(line).Key.Equals(p.Bin.Line.Key))).ToArray();
|
||||
foreach (var product in products.Concat(binned)) Assert.True(cache.Remove(cache.RefOf(product).Key));
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
|
||||
|
|
|
|||
184
tests/Aetheria.Shared.Tests/ProductTiersCommandTests.cs
Normal file
184
tests/Aetheria.Shared.Tests/ProductTiersCommandTests.cs
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Caching.MessagePack;
|
||||
using Xunit;
|
||||
|
||||
// AetherDb's product-lines tiers command (cut product-tiers; rulings maker-design-tiers-allowed, bin-share-by-floor), run on a
|
||||
// scratch copy of the shipped catalog with the table's bins removed from it. A standalone class: a tier row is not a Row.
|
||||
public sealed class ProductTiersCommandTests : IDisposable
|
||||
{
|
||||
private static readonly string[] Apply = { "tiers", "apply" };
|
||||
private static readonly string[] DryRun = { "tiers" };
|
||||
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), "product-tiers-command-" + Guid.NewGuid().ToString("N"));
|
||||
private string CatalogPath => Path.Combine(_root, "GameData", "Aetheria.cc");
|
||||
private readonly string[] _names = ProductLinesCommand.TierTable().Select(r => r.Name).ToArray();
|
||||
|
||||
public ProductTiersCommandTests()
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(_root, "GameData"));
|
||||
Directory.CreateDirectory(Path.Combine(_root, "Assets", "Resources"));
|
||||
var shipped = AetherDb.FindRoot();
|
||||
File.Copy(Path.Combine(shipped, "GameData", "Aetheria.cc"), CatalogPath);
|
||||
File.Copy(Path.Combine(shipped, "Assets", "Resources", "Settings.asset"), Path.Combine(_root, "Assets", "Resources", "Settings.asset"));
|
||||
using var cache = Open();
|
||||
foreach (var bin in cache.GetAll<FactionProductData>().Where(p => _names.Contains(p.Name)).ToArray()) Assert.True(cache.Remove(cache.RefOf(bin).Key));
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
|
||||
public void Dispose() => Directory.Delete(_root, true);
|
||||
|
||||
private CultCache Open()
|
||||
{
|
||||
var cache = new CultCache(TestCatalog.Registry());
|
||||
cache.AddBackingStore(new SingleFileMessagePackBackingStore(CatalogPath), AetheriaStores.CatalogTypes);
|
||||
return cache;
|
||||
}
|
||||
|
||||
private Dictionary<string, CultPersistedRecord> Records() =>
|
||||
CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(CatalogPath)).Records.ToDictionary(r => r.Key, StringComparer.Ordinal);
|
||||
|
||||
private FactionProductData[] Bins()
|
||||
{
|
||||
using var cache = Open();
|
||||
return cache.GetAll<FactionProductData>().Where(p => _names.Contains(p.Name)).ToArray();
|
||||
}
|
||||
|
||||
// Edits the scratch catalog before a refusal case; the bins the table authors stay out of it.
|
||||
private void Edit(Action<CultCache> edit)
|
||||
{
|
||||
using var cache = Open();
|
||||
edit(cache);
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
|
||||
// The command refuses the row with a message naming the rule, and the catalog's bytes are as they were.
|
||||
private void Refused(ProductLinesCommand.TierRow row, string phrase)
|
||||
{
|
||||
var before = File.ReadAllBytes(CatalogPath);
|
||||
var error = Assert.Throws<InvalidOperationException>(() => ProductLinesCommand.RunTiers(new[] { row }, true, _root));
|
||||
Assert.Contains(phrase, error.Message);
|
||||
Assert.Equal(before, File.ReadAllBytes(CatalogPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_dry_run_writes_nothing_and_apply_lands_the_table_once_and_replays_as_a_no_op()
|
||||
{
|
||||
var before = File.ReadAllBytes(CatalogPath);
|
||||
Assert.Empty(Bins());
|
||||
|
||||
Assert.Equal(0, ProductLinesCommand.Run(DryRun, _root));
|
||||
Assert.Equal(before, File.ReadAllBytes(CatalogPath));
|
||||
|
||||
Assert.Equal(0, ProductLinesCommand.Run(Apply, _root));
|
||||
var landed = File.ReadAllBytes(CatalogPath);
|
||||
Assert.NotEqual(before, landed);
|
||||
Assert.Equal(6, Bins().Length);
|
||||
|
||||
Assert.Equal(0, ProductLinesCommand.Run(Apply, _root));
|
||||
Assert.Equal(landed, File.ReadAllBytes(CatalogPath));
|
||||
Assert.Equal(0, ProductLinesCommand.Run(DryRun, _root));
|
||||
Assert.Equal(landed, File.ReadAllBytes(CatalogPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Each_bin_is_its_lines_design_and_maker_at_its_floor_with_nothing_of_its_own()
|
||||
{
|
||||
Assert.Equal(0, ProductLinesCommand.Run(Apply, _root));
|
||||
using var cache = Open();
|
||||
foreach (var row in ProductLinesCommand.TierTable())
|
||||
{
|
||||
var bin = Assert.Single(cache.GetAll<FactionProductData>(), p => p.Name == row.Name);
|
||||
var line = Assert.Single(cache.GetAll<FactionProductData>(), p => p.Name == row.Line);
|
||||
Assert.Equal(cache.RefOf(line).Key, bin.Bin.Line.Key);
|
||||
Assert.Equal(line.Design.Key, bin.Design.Key);
|
||||
Assert.Equal(line.Manufacturer.Key, bin.Manufacturer.Key);
|
||||
Assert.Equal(row.Floor, bin.Bin.Floor);
|
||||
Assert.Equal(row.Description, bin.Description);
|
||||
Assert.Empty(bin.Roles);
|
||||
Assert.Null(bin.Assembly);
|
||||
Assert.Null(line.Bin);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Apply_writes_only_the_records_it_authors()
|
||||
{
|
||||
var before = Records();
|
||||
Assert.Equal(0, ProductLinesCommand.Run(Apply, _root));
|
||||
var after = Records();
|
||||
Assert.Equal(before.Count + 6, after.Count);
|
||||
foreach (var (key, record) in before)
|
||||
{
|
||||
Assert.True(after.TryGetValue(key, out var kept), "a record the command did not author is gone");
|
||||
Assert.Equal(record.StoredAt, kept.StoredAt);
|
||||
Assert.True(record.Payload.AsSpan().SequenceEqual(kept.Payload), "a record the command did not author has changed bytes");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_bin_already_authored_at_another_floor_is_refused()
|
||||
{
|
||||
Assert.Equal(0, ProductLinesCommand.Run(Apply, _root));
|
||||
Refused(new ProductLinesCommand.TierRow("Sparrow", "Goldcrest", .5f, "x"), "already belongs");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_bin_already_authored_on_another_line_is_refused()
|
||||
{
|
||||
Assert.Equal(0, ProductLinesCommand.Run(Apply, _root));
|
||||
Refused(new ProductLinesCommand.TierRow("Spotlight", "Goldcrest", .67f, "x"), "already belongs");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_line_the_catalog_does_not_hold_is_refused()
|
||||
{
|
||||
Refused(new ProductLinesCommand.TierRow("No Such Line", "Fresh Bin", 0f, "x"), "found 0");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_ambiguous_line_is_refused()
|
||||
{
|
||||
Edit(cache =>
|
||||
{
|
||||
var sparrow = cache.GetAll<FactionProductData>().Single(p => p.Name == "Sparrow");
|
||||
cache.Upsert(new FactionProductData { Name = "Sparrow", Design = sparrow.Design, Manufacturer = sparrow.Manufacturer });
|
||||
});
|
||||
Refused(new ProductLinesCommand.TierRow("Sparrow", "Fresh Bin", 0f, "x"), "found 2");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_line_that_is_itself_a_bin_is_refused()
|
||||
{
|
||||
Assert.Equal(0, ProductLinesCommand.Run(Apply, _root));
|
||||
Refused(new ProductLinesCommand.TierRow("Goldcrest", "Fresh Bin", 0f, "x"), "itself a bin");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-.1f)]
|
||||
[InlineData(float.NaN)]
|
||||
[InlineData(float.PositiveInfinity)]
|
||||
public void A_floor_that_is_negative_or_not_finite_is_refused(float floor)
|
||||
{
|
||||
Refused(new ProductLinesCommand.TierRow("Sparrow", "Fresh Bin", floor, "x"), "finite number");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Spotlight")]
|
||||
[InlineData("SPOTLIGHT")]
|
||||
public void A_bin_name_held_by_another_product_is_refused_ignoring_case(string name)
|
||||
{
|
||||
Refused(new ProductLinesCommand.TierRow("Sparrow", name, 0f, "x"), "already belongs");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_bin_name_that_is_a_designs_is_refused()
|
||||
{
|
||||
string design;
|
||||
using (var cache = Open()) design = cache.GetAll<CraftedItemData>().First().Name;
|
||||
Refused(new ProductLinesCommand.TierRow("Sparrow", design.ToUpperInvariant(), 0f, "x"), "name of a design");
|
||||
}
|
||||
}
|
||||
|
|
@ -207,6 +207,110 @@ public sealed class RolesBackfillCommandTests : IDisposable
|
|||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
||||
// A bin authors no roles (ProductBin): the backfill that restores its line's missing roles leaves the bin's list empty.
|
||||
[Fact]
|
||||
public void A_binned_seller_gains_no_roles()
|
||||
{
|
||||
Reset(flattened: false, unnamed: false);
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key) && p.Roles.Count == 2);
|
||||
var sellerName = seller.Name;
|
||||
seller.Roles = new List<ProductRole> { seller.Roles.OrderBy(r => r.Role, StringComparer.Ordinal).First() };
|
||||
var bin = new FactionProductData
|
||||
{
|
||||
Name = "Binned " + sellerName, Design = seller.Design, Manufacturer = seller.Manufacturer,
|
||||
Bin = new ProductBin { Line = db.Cache.RefOf(seller), Floor = 0f }
|
||||
};
|
||||
db.Cache.Commit(batch =>
|
||||
{
|
||||
batch.Upsert(typeof(FactionProductData), seller, db.Cache.RefOf(seller).Key);
|
||||
batch.Upsert(typeof(FactionProductData), bin);
|
||||
});
|
||||
db.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.RolesBackfill(apply: true, root: _root));
|
||||
db = AetherDb.Open(root: _root);
|
||||
try
|
||||
{
|
||||
Assert.Equal(2, db.Cache.GetAll<FactionProductData>().Single(p => p.Name == sellerName).Roles.Count);
|
||||
Assert.Empty(db.Cache.GetAll<FactionProductData>().Single(p => p.Name == "Binned " + sellerName).Roles);
|
||||
}
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
||||
// The census reports a seller that authors no spread for a role of its design as a gap, and never a bin: a bin reads its line's.
|
||||
[Fact]
|
||||
public void The_census_reports_a_roleless_seller_and_never_a_bin()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key));
|
||||
var sellerName = seller.Name;
|
||||
seller.Roles = new List<ProductRole>();
|
||||
db.Cache.Commit(batch =>
|
||||
{
|
||||
batch.Upsert(typeof(FactionProductData), seller, db.Cache.RefOf(seller).Key);
|
||||
batch.Upsert(typeof(FactionProductData), new FactionProductData
|
||||
{
|
||||
Name = "Binned " + sellerName, Design = seller.Design, Manufacturer = seller.Manufacturer,
|
||||
Bin = new ProductBin { Line = db.Cache.RefOf(seller), Floor = 0f }
|
||||
});
|
||||
});
|
||||
db.Cache.Dispose();
|
||||
|
||||
db = AetherDb.Open(root: _root);
|
||||
try
|
||||
{
|
||||
var gaps = Program.RoleGaps(db.Cache, db.Cache.GetAll<EquippableItemData>().ToArray(), db.Cache.GetAll<FactionProductData>().ToArray()).ToArray();
|
||||
Assert.Contains(gaps, gap => gap.Product.Name == sellerName && gap.Missing.Length == 2);
|
||||
Assert.DoesNotContain(gaps, gap => gap.Product.Name == "Binned " + sellerName);
|
||||
}
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
||||
// roles-migrate authors a role on every product that sells a design lacking one; a bin sells none of its own.
|
||||
[Fact]
|
||||
public void A_binned_seller_gains_no_roles_from_roles_migrate()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var autocannon = db.Cache.GetAll<WeaponItemData>().Single(weapon => weapon.Name == "Autocannon");
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Design.Key.Equals(db.Cache.RefOf(autocannon).Key));
|
||||
var bin = new FactionProductData
|
||||
{
|
||||
Name = "Binned " + seller.Name, Design = seller.Design, Manufacturer = seller.Manufacturer,
|
||||
Bin = new ProductBin { Line = db.Cache.RefOf(seller), Floor = 0f }
|
||||
};
|
||||
db.Cache.Commit(batch => batch.Upsert(typeof(FactionProductData), bin));
|
||||
db.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.RolesMigrate(apply: true, root: _root));
|
||||
db = AetherDb.Open(root: _root);
|
||||
try { Assert.Empty(db.Cache.GetAll<FactionProductData>().Single(p => p.Name == "Binned " + seller.Name).Roles); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
||||
// sensor-stat-set authors an emission-discipline role on every product of a sensor design; a bin of one authors none.
|
||||
[Fact]
|
||||
public void A_binned_seller_gains_no_roles_from_sensor_stat_set()
|
||||
{
|
||||
var db = AetherDb.Open(catalogWritable: true, root: _root);
|
||||
var sensor = db.Cache.GetAll<EquippableItemData>().Where(d => d.Behaviors != null && d.Behaviors.OfType<SensorData>().Any()).OrderBy(d => d.Name, StringComparer.Ordinal).First();
|
||||
var seller = db.Cache.GetAll<FactionProductData>().OrderBy(p => p.Name, StringComparer.Ordinal).First(p => p.Bin == null && p.Design.Key.Equals(db.Cache.RefOf(sensor).Key));
|
||||
var bin = new FactionProductData
|
||||
{
|
||||
Name = "Binned " + seller.Name, Design = seller.Design, Manufacturer = seller.Manufacturer,
|
||||
Bin = new ProductBin { Line = db.Cache.RefOf(seller), Floor = 0f }
|
||||
};
|
||||
db.Cache.Commit(batch => batch.Upsert(typeof(FactionProductData), bin));
|
||||
db.Cache.Dispose();
|
||||
|
||||
Assert.Equal(0, Program.SensorStatSet(apply: true, root: _root));
|
||||
db = AetherDb.Open(root: _root);
|
||||
try { Assert.Empty(db.Cache.GetAll<FactionProductData>().Single(p => p.Name == "Binned " + seller.Name).Roles); }
|
||||
finally { db.Cache.Dispose(); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_design_the_catalog_does_not_hold_refuses_and_lands_nothing()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue