public void SimpleEntityFaultTest() { var ctx = new SimulationContext(true); EntityPool pool = new EntityPool(EntityPoolTests.CreateEntities(ctx.LocalSpace, 100, new RandomLogic(new Type[] { typeof(ConsistentLogic), typeof(FaultLogic) }).Instantiate), ctx); InconsistencyCoverage ic = InconsistencyCoverage.NewCommon(); int any = -1; for (int i = 0; i < 8; i++) { EntityChangeSet set = new EntityChangeSet(); ctx.SetGeneration(i); var errors = pool.TestEvolve(set, ic, i, TimeSpan.FromSeconds(1)); if (errors != null) { Assert.IsTrue(ic.OneCount > 0); if (any == -1) { any = i; } } ic = ic.Grow(true); Assert.IsTrue(ic.Size == InconsistencyCoverage.CommonResolution); } if (any == 0) { Assert.AreEqual(ic.OneCount, ic.Size.Product); } }
public void ExtensiveEntityFaultTest() { int mismatched = 0; var ctx = new SimulationContext(true); for (int k = 0; k < 20; k++) { InconsistencyCoverage ic = InconsistencyCoverage.NewCommon(), nextIC = ic; EntityPool pool = new EntityPool(EntityPoolTests.CreateEntities(ctx.LocalSpace, 100, i => i > 0 ? new ConsistentLogic() : (EntityLogic)(new FaultLogic())), ctx); int faultyCount = 0; Entity faulty = new Entity(); foreach (var e in pool.ToArray()) { if (Helper.Deserialize(e.SerialLogicState) is FaultLogic) { faultyCount++; faulty = e; } } Assert.AreEqual(faultyCount, 1); bool doGrow = k % 2 != 0; ConsistentLogic.GrowingIC = doGrow; for (int i = 0; i < InconsistencyCoverage.CommonResolution; i++) //no point going further than current resolution { EntityChangeSet set = new EntityChangeSet(); ctx.SetGeneration(i); var errors = pool.TestEvolve(set, ic, i, TimeSpan.FromSeconds(1)); Assert.AreEqual(1, errors.Count, Helper.Concat(",", errors)); Assert.AreEqual(0, set.Execute(pool, ic, ctx)); //Assert.AreEqual(ic.OneCount, 1); if (doGrow) { ic = ic.Grow(true); } if (!doGrow) { Assert.AreEqual(ic.OneCount, 1); } Entity[] entities = pool.ToArray(); bool hasFaulty = false; foreach (var e in entities) { bool isFaultOrigin = (Helper.Deserialize(e.SerialLogicState) is FaultLogic); if (isFaultOrigin) { faulty = e; Assert.IsFalse(hasFaulty); hasFaulty = true; } } Assert.IsTrue(hasFaulty); foreach (var e in entities) { bool isFaultOrigin = (Helper.Deserialize(e.SerialLogicState) is FaultLogic); #if STATE_ADV if (!isFaultOrigin) { if (ctx.GetDistance(e.ID.Position, faulty.ID.Position) <= Simulation.SensorRange) { Assert.IsTrue(e.HasContact(faulty.ID.Guid)); Assert.IsTrue(e.HasContact(faulty.ID)); } var adv = set.FindAdvertisementFor(e.ID); Assert.IsNotNull(e.Appearances); } bool consistent = ConsistentLogic.IsConsistent(e.Appearances); #else ConsistentLogic c = e.MyLogic as ConsistentLogic; bool consistent = c != null && c.isConsistent; #endif bool icIsInc = ic.IsInconsistentR(Simulation.MySpace.Relativate(e.ID.Position)); if (!consistent && !icIsInc) { if (doGrow) { Assert.Fail("Inconsistent entity located outside IC area: " + e + ", " + e.MyLogic); } else { mismatched++; break; } } } //Assert.AreEqual(ic.OneCount, 1); } } Assert.AreNotEqual(mismatched, 0); }