test(engine-ambient): TestBattleScope + HeadlessFixture split for multi-instance
Step 6 of multi-instancing migration. HeadlessEngineEnv.EnsureInitialized is split into EnsureProcessGlobals (idempotent, process-once) + SeedCharaIdsOnCurrentAmbient (per-test). New TestBattleScope IDisposable sets up a fresh BattleAmbientContext per test. NonParallelizable removed from converted classes; assembly-level Parallelizable(Fixtures) enabled. SVSim.BattleEngine.Tests fully green under parallel test execution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,11 @@ namespace SVSim.BattleEngine.Tests
|
||||
[TestFixture]
|
||||
public class RngSeamTests
|
||||
{
|
||||
private TestBattleScope _scope;
|
||||
|
||||
[SetUp] public void SetUpScope() { _scope = new TestBattleScope(); }
|
||||
[TearDown] public void TearDownScope() { _scope?.Dispose(); _scope = null; }
|
||||
|
||||
// RandomSourceBridge.Range must mirror the engine's exact roll arithmetic:
|
||||
// BattleManagerBase.StableRandom does `(int)Math.Floor((double)val * unit)`.
|
||||
[Test]
|
||||
@@ -60,7 +65,6 @@ namespace SVSim.BattleEngine.Tests
|
||||
[Test]
|
||||
public void Override_rolls_real_values_under_IsForecast()
|
||||
{
|
||||
HeadlessEngineEnv.EnsureInitialized();
|
||||
BattleManagerBase.IsForecast = true; // would zero the un-overridden engine RNG
|
||||
|
||||
// 3 units; with RandomSourceBridge.Range(val, unit) = floor(val*unit):
|
||||
@@ -69,6 +73,7 @@ namespace SVSim.BattleEngine.Tests
|
||||
// StableRandomOnlySelf(10) -> scripted self pick 4
|
||||
var src = new ScriptedRandomSource(new[] { 0.5, 0.25 }, new[] { 4 });
|
||||
var mgr = new HeadlessBattleMgr(new HeadlessContentsCreator(), src);
|
||||
_scope.Ctx.Mgr = mgr;
|
||||
|
||||
Assert.That(mgr.StableRandom(7), Is.EqualTo(3), "StableRandom did not use the injected source");
|
||||
Assert.That(mgr.randomResult, Is.EqualTo(0.5), "StableRandom must set randomResult to the rolled unit");
|
||||
@@ -84,10 +89,10 @@ namespace SVSim.BattleEngine.Tests
|
||||
[Test]
|
||||
public void Default_source_matches_engine_generator_and_formula()
|
||||
{
|
||||
HeadlessEngineEnv.EnsureInitialized();
|
||||
BattleManagerBase.IsForecast = true;
|
||||
|
||||
var mgr = new HeadlessBattleMgr(new HeadlessContentsCreator()); // default SeededRandomSource(12345)
|
||||
_scope.Ctx.Mgr = mgr;
|
||||
var reference = new System.Random(12345);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
|
||||
Reference in New Issue
Block a user