public void SimpleFlowArrives() { var supply = new WaterSupply(); var pump = new Pump(); var drain = new Drain(); var combinator = new DialyzingFluidFlowCombinator(); pump.PumpSpeed = 7; combinator.ConnectOutWithIn(supply.MainFlow, pump.MainFlow); combinator.ConnectOutWithIn(pump.MainFlow, drain.MainFlow); combinator.CommitFlow(); var model = new DialyzingFluidFlowModel { FlowElements = new IComponent[] { supply, pump, drain, combinator } }; var simulator = new SafetySharpSimulator(model); //Important: Call after all objects have been created simulator.SimulateStep(); var modelAfterStep = (DialyzingFluidFlowModel)simulator.Model; var supplyAfterStep = (WaterSupply)modelAfterStep.Components[0]; var pumpAfterStep = (Pump)modelAfterStep.Components[1]; var drainAfterStep = (Drain)modelAfterStep.Components[2]; pumpAfterStep.MainFlow.Incoming.Backward.CustomSuctionValue.Should().Be(7); supplyAfterStep.MainFlow.Outgoing.Forward.Quantity.Should().Be(7); drainAfterStep.MainFlow.Incoming.Forward.Quantity.Should().Be(7); }
public void TwoStepFlowArrives() { var testModel = new IntFlowModel(); var source = new IntFlowSource(); var direct1 = new IntFlowInToOut(); var direct2 = new IntFlowInToOut(); var sink = new IntFlowSink(); testModel.Components = new IntFlowComponentCollection(source, direct1, direct2, sink); source.SendForward = testModel.CreateForward; source.ReceivedBackward = testModel.PrintReceivedBackward; sink.SendBackward = testModel.CreateBackward; sink.ReceivedForward = testModel.PrintReceivedForward; testModel.Combinator.ConnectOutWithIn(source, direct1); testModel.Combinator.ConnectOutWithIn(direct1, direct2); testModel.Combinator.ConnectOutWithIn(direct2, sink); testModel.Combinator.CommitFlow(); var simulator = new SafetySharpSimulator(testModel); //Important: Call after all objects have been created simulator.SimulateStep(); var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0]; var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components; var sourceAfterStep = (IntFlowSource)flowComponentsAfterStep[0]; var sinkAfterStep = (IntFlowSink)flowComponentsAfterStep[3]; sinkAfterStep.Incoming.Forward.Should().Be(7); sourceAfterStep.Outgoing.Backward.Should().Be(1); }
protected override void Check() { var m = new M(); var simulator = new SafetySharpSimulator(m, m.F); m = (M)simulator.Model; var f = simulator.RuntimeModel.Compile(m.F); var g = simulator.RuntimeModel.Compile(m.G); m.C.X.ShouldBe(0); simulator.RuntimeModel.Evaluate(m.F).ShouldBe(true); simulator.RuntimeModel.Evaluate(m.G).ShouldBe(true); f().ShouldBe(true); g().ShouldBe(true); simulator.SimulateStep(); m.C.X.ShouldBe(1); simulator.RuntimeModel.Evaluate(m.F).ShouldBe(false); simulator.RuntimeModel.Evaluate(m.G).ShouldBe(false); f().ShouldBe(false); g().ShouldBe(false); }
public void Simulate_10_Step_HeaterAndPumpToBalanceChamberDefect() { var testModel = new Model(); var simulator = new SafetySharpSimulator(testModel); //Important: Call after all objects have been created var patient = simulator.Model.Roots.OfType <Patient>().First(); var hdMachine = simulator.Model.Roots.OfType <HdMachine>().First(); hdMachine.DialyzingFluidDeliverySystem.WaterPreparation.WaterHeaterDefect.Activation = Activation.Forced; hdMachine.DialyzingFluidDeliverySystem.PumpToBalanceChamber.PumpDefect.Activation = Activation.Forced; simulator.SimulateStep(); var patient2 = simulator.Model.Roots.OfType <Patient>().First(); simulator.SimulateStep(); var patient3 = simulator.Model.Roots.OfType <Patient>().First(); simulator.SimulateStep(); var patient4 = simulator.Model.Roots.OfType <Patient>().First(); var hdMachine4 = simulator.Model.Roots.OfType <HdMachine>().First(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); }
private void OnCounterExample(object sender, RoutedEventArgs e) { var counterExampleSerialization = new SafetySharpCounterExampleSerialization(); var dialog = new OpenFileDialog { AddExtension = true, CheckFileExists = true, CheckPathExists = true, DefaultExt = ".ltsmin", Filter = $"S# Counter Examples (*{counterExampleSerialization.FileExtension})|*{counterExampleSerialization.FileExtension}", Title = "Open S# Counter Example", Multiselect = false }; if (dialog.ShowDialog() != true) { return; } try { var simulator = new SafetySharpSimulator(counterExampleSerialization.Load(dialog.FileName)); SetSimulator(simulator); CloseCounterExampleButton.Visibility = Visibility.Visible; } catch (Exception ex) { var message = "An incompatible change has been made to the model since the counter example has been generated: " + ex.Message; MessageBox.Show(message, "Failed to Load Counter Example", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void DialyzerWorks_Simulation() { var specification = new DialyzerTestEnvironment(); var simulator = new SafetySharpSimulator(specification); //Important: Call after all objects have been created var dialyzerAfterStep0 = (Dialyzer)simulator.Model.Roots.OfType <Dialyzer>().First(); var patientAfterStep0 = (DialyzerTestEnvironmentPatient) simulator.Model.Roots.OfType <DialyzerTestEnvironmentPatient>().First(); Console.Out.WriteLine("Initial"); patientAfterStep0.ArteryFlow.Outgoing.Forward.PrintBloodValues("outgoing Blood"); patientAfterStep0.VeinFlow.Incoming.Forward.PrintBloodValues("incoming Blood"); patientAfterStep0.PrintBloodValues(""); Console.Out.WriteLine("Step 1"); simulator.SimulateStep(); var dialyzerAfterStep1 = (Dialyzer)simulator.Model.Roots.OfType <Dialyzer>().First(); var patientAfterStep1 = (DialyzerTestEnvironmentPatient) simulator.Model.Roots.OfType <DialyzerTestEnvironmentPatient>().First(); patientAfterStep1.ArteryFlow.Outgoing.Forward.PrintBloodValues("outgoing Blood"); patientAfterStep1.VeinFlow.Incoming.Forward.PrintBloodValues("incoming Blood"); patientAfterStep1.PrintBloodValues(""); Console.Out.WriteLine("Step 2"); simulator.SimulateStep(); var dialyzerAfterStep2 = (Dialyzer)simulator.Model.Roots.OfType <Dialyzer>().First(); var patientAfterStep2 = (DialyzerTestEnvironmentPatient) simulator.Model.Roots.OfType <DialyzerTestEnvironmentPatient>().First(); patientAfterStep2.ArteryFlow.Outgoing.Forward.PrintBloodValues("outgoing Blood"); patientAfterStep2.VeinFlow.Incoming.Forward.PrintBloodValues("incoming Blood"); patientAfterStep2.PrintBloodValues(""); Console.Out.WriteLine("Step 3"); simulator.SimulateStep(); var dialyzerAfterStep3 = (Dialyzer)simulator.Model.Roots.OfType <Dialyzer>().First(); var patientAfterStep3 = (DialyzerTestEnvironmentPatient) simulator.Model.Roots.OfType <DialyzerTestEnvironmentPatient>().First(); patientAfterStep3.ArteryFlow.Outgoing.Forward.PrintBloodValues("outgoing Blood"); patientAfterStep3.VeinFlow.Incoming.Forward.PrintBloodValues("incoming Blood"); patientAfterStep3.PrintBloodValues(""); Console.Out.WriteLine("Step 4"); simulator.SimulateStep(); var dialyzerAfterStep4 = (Dialyzer)simulator.Model.Roots.OfType <Dialyzer>().First(); var patientAfterStep4 = (DialyzerTestEnvironmentPatient) simulator.Model.Roots.OfType <DialyzerTestEnvironmentPatient>().First(); patientAfterStep4.ArteryFlow.Outgoing.Forward.PrintBloodValues("outgoing Blood"); patientAfterStep4.VeinFlow.Incoming.Forward.PrintBloodValues("incoming Blood"); patientAfterStep4.PrintBloodValues(""); //dialyzerAfterStep1.Should().Be(1); patientAfterStep4.BigWasteProducts.Should().Be(0); patientAfterStep4.SmallWasteProducts.Should().Be(2); }
protected override void Check() { var simulator = new SafetySharpSimulator(TestModel.InitializeModel(new C <D>())); var c = (C <D>)simulator.Model.Roots[0]; c.Y.X.ShouldBe(0); simulator.SimulateStep(); c.Y.X.ShouldBe(1); }
public void Simulate_1Step() { var testModel = new Model(); var simulator = new SafetySharpSimulator(testModel); //Important: Call after all objects have been created simulator.SimulateStep(); var flowCombinatorAfterStep = (DialyzingFluidFlowCombinator)simulator.Model.Roots[0]; }
protected override void Check() { var simulator = new SafetySharpSimulator(TestModel.InitializeModel(new C { X = 44 })); var c = (C)simulator.Model.Roots[0]; c.F.Activation = Activation.Suppressed; c.X.ShouldBe(44); for (var i = 0; i < 10; ++i) { simulator.FastForward(10); c.X.ShouldBe(44 + (i + 1) * 10); } for (var i = 0; i < 12; ++i) { simulator.Rewind(10); if (i < 10) { c.X.ShouldBe(44 + (10 - i - 1) * 10); } else { c.X.ShouldBe(44); } } for (var i = 0; i < 12; ++i) { simulator.FastForward(10); c.X.ShouldBe(44 + (i + 1) * 10); } simulator.Rewind(61); c.X.ShouldBe(103); c.F.Activation = Activation.Forced; simulator.SimulateStep(); c.X.ShouldBe(105); simulator.Rewind(2); c.X.ShouldBe(102); c.F.Activation = Activation.Suppressed; simulator.Prune(); c.X.ShouldBe(102); simulator.SimulateStep(); c.X.ShouldBe(103); simulator.FastForward(10); c.X.ShouldBe(113); }
protected override void Check() { var simulator = new SafetySharpSimulator(TestModel.InitializeModel(new C())); var c = (C)simulator.Model.Roots[0]; c.D.X.ShouldBe(44); c.E.X.ShouldBe(44); simulator.SimulateStep(); c.D.X.ShouldBe(45); c.E.X.ShouldBe(46); }
public void Simulate() { var model = new Model(); model.InitializeDefaultInstance(); model.CreateObserverController <FastObserverController>(); model.Faults.SuppressActivations(); var simulator = new SafetySharpSimulator(model); PrintTrace(simulator, steps: 120); }
protected override void Check() { var m1 = new M(); var s = new SafetySharpSimulator(m1); var m2 = (M)s.Model; m2.F.I.ShouldBe(m1.F.I); m2.E.C.I.ShouldBe(m1.E.C.I); m2.Roots.ShouldBe(new IComponent[] { m2.F, m2.E }, ignoreOrder: true); m2.Components.ShouldBe(new IComponent[] { m2.F, m2.E }, ignoreOrder: true); m2.Faults.ShouldBeEmpty(); }
public void TankDoesNotRuptureWhenNoFaultsOccur() { var model = new Model(); model.Faults.SuppressActivations(); var simulator = new SafetySharpSimulator(model); model = (Model)simulator.Model; simulator.FastForward(steps: 120); model.Tank.IsRuptured.Should().BeFalse(); }
private void SetSimulator(SafetySharpSimulator simulator) { if (Simulator != null) { Simulator.ModelStateChanged -= OnModelStateChanged; Simulator.Pause(); } Simulator = new RealTimeSafetySharpSimulator(simulator, (int)Math.Round(1000 / _speed)); Simulator.ModelStateChanged += OnModelStateChanged; UpdateSimulationButtonVisibilities(); OnReset(null, null); }
protected override void Check() { var c = new C(); var d = new D(); Component.Bind(nameof(c.Y), nameof(d.Z)); var simulator = new SafetySharpSimulator(TestModel.InitializeModel(c, d)); c = (C)simulator.Model.Roots[0]; simulator.SimulateStep(); c.X.ShouldBe(7); }
public void TankDoesNotRuptureWhenSensorDoesNotReportTankFull() { var model = new Model(); model.Faults.SuppressActivations(); model.Sensor.SuppressIsFull.ForceActivation(); var simulator = new SafetySharpSimulator(model); model = (Model)simulator.Model; simulator.FastForward(steps: 120); model.Tank.IsRuptured.Should().BeFalse(); }
protected override void Check() { var simulator = new SafetySharpSimulator(TestModel.InitializeModel(new C())); var c = (C)simulator.Model.Roots[0]; c.F.Activation = Activation.Forced; simulator.SimulateStep(); c.X.ShouldBe(1); c.F.Activation = Activation.Suppressed; simulator.SimulateStep(); c.X.ShouldBe(1); simulator.Model.Faults.ShouldBeEmpty(); }
public void NoCollisionsWhenNoFaultsOccur() { var model = Model.CreateOriginal(); model.Faults.SuppressActivations(); var simulator = new SafetySharpSimulator(model); simulator.FastForward(steps: 20); foreach (var vehicle in ((Model)simulator.Model).Vehicles) { vehicle.IsCollided.Should().BeFalse(); } }
protected override void Check() { var m1 = new M <C>(); var s = new SafetySharpSimulator(m1); var m2 = (M <C>)s.Model; m2.A.I.ShouldBe(m1.A.I); ((C)m2.B).I.ShouldBe(((C)m1.B).I); ((C)m2.C).I.ShouldBe(((C)m1.C).I); m2.D().I.ShouldBe(m1.D().I); m2.Roots.ShouldBe(new[] { m2.A, m2.B, m2.C, m2.D() }, ignoreOrder: true); m2.Components.ShouldBe(new[] { m2.A, m2.B, m2.C, m2.D() }, ignoreOrder: true); m2.Faults.ShouldBeEmpty(); }
protected override void Check() { var simulator = new SafetySharpSimulator(TestModel.InitializeModel(new C { X = 44 })); var c = (C)simulator.Model.Roots[0]; c.X.ShouldBe(44); for (var i = 0; i < 100; ++i) { simulator.SimulateStep(); c.X.ShouldBe(44 + i + 1); } }
public static void PrintTrace(SafetySharpSimulator simulator, int steps) { var model = (Model)simulator.Model; for (var i = 0; i < steps; ++i) { WriteLine($"================= Step: {i} ====================================="); if (model.ObserverController.ReconfigurationState == ReconfStates.Failed) { WriteLine("Reconfiguration failed."); } else { foreach (var robot in model.RobotAgents) { WriteLine(robot); } foreach (var cart in model.CartAgents) { WriteLine(cart); } foreach (var workpiece in model.Workpieces) { WriteLine(workpiece); } foreach (var robot in model.Robots) { WriteLine(robot); } foreach (var cart in model.Carts) { WriteLine(cart); } } simulator.SimulateStep(); } }
public void CompositeFlowArrives() { var testModel = new IntFlowModel(); var source = new IntFlowSource(); var composite = new IntFlowComposite(); var firstInComposite = new IntFlowInToOut(); var secondInComposite = new IntFlowInToOut(); var sink = new IntFlowSink(); testModel.Components = new IntFlowComponentCollection(source, composite, firstInComposite, secondInComposite, sink); source.SendForward = testModel.CreateForward; source.ReceivedBackward = testModel.PrintReceivedBackward; sink.SendBackward = testModel.CreateBackward; sink.ReceivedForward = testModel.PrintReceivedForward; testModel.Combinator.ConnectOutWithIn(source, composite); testModel.Combinator.ConnectInWithIn(composite, firstInComposite); testModel.Combinator.ConnectOutWithIn(firstInComposite, secondInComposite); testModel.Combinator.ConnectOutWithOut(secondInComposite, composite); testModel.Combinator.ConnectOutWithIn(composite, sink); testModel.Combinator.CommitFlow(); var simulator = new SafetySharpSimulator(testModel); //Important: Call after all objects have been created simulator.SimulateStep(); var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0]; var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components; var sourceAfterStep = (IntFlowSource)flowComponentsAfterStep[0]; var compositeAfterStep = (IntFlowComposite)flowComponentsAfterStep[1]; var firstInCompositeAfterStep = (IntFlowInToOut)flowComponentsAfterStep[2]; var sinkAfterStep = (IntFlowSink)flowComponentsAfterStep[4]; sourceAfterStep.Outgoing.Forward.Should().Be((Int)7); compositeAfterStep.Incoming.Forward.Should().Be((Int)7); compositeAfterStep.FlowIn.Outgoing.Forward.Should().Be((Int)7); firstInCompositeAfterStep.Incoming.Forward.Should().Be((Int)7); compositeAfterStep.FlowOut.Outgoing.Forward.Should().Be((Int)7); compositeAfterStep.Outgoing.Forward.Should().Be((Int)7); sinkAfterStep.Incoming.Forward.Should().Be((Int)7); sourceAfterStep.Outgoing.Backward.Should().Be(1); }
protected override void Check() { var m1 = new M(); var s = new SafetySharpSimulator(m1); var m2 = (M)s.Model; var c1 = m1.GetRoots().OfType <C>().ToArray(); var c2 = m2.GetRoots().OfType <C>().ToArray(); for (var i = 0; i < c1.Length; ++i) { c2[i].I.ShouldBe(c1[i].I); } m2.E.C.I.ShouldBe(m1.E.C.I); m2.Roots.ShouldBe(m2.GetRoots(), ignoreOrder: true); m2.Components.ShouldBe(m2.GetRoots().Concat(new[] { m2.E.C }), ignoreOrder: true); m2.Faults.ShouldBe(new[] { m2.E.F }); }
public void DialyzingFluidDeliverySystemWorks_Simulation() { var specification = new DialyzingFluidDeliverySystemTestEnvironment(); var simulator = new SafetySharpSimulator(specification); //Important: Call after all objects have been created var dialyzerAfterStep0 = simulator.Model.Roots.OfType <DialyzingFluidDeliverySystemTestEnvironmentDialyzer>().First(); var dialyzingFluidDeliverySystemAfterStep0 = simulator.Model.Roots.OfType <DialyzingFluidDeliverySystem>().First(); Console.Out.WriteLine("Initial"); //dialyzingFluidDeliverySystemAfterStep0.ArteryFlow.Outgoing.ForwardToSuccessor.PrintBloodValues("outgoing Blood"); //patientAfterStep0.VeinFlow.Incoming.ForwardFromPredecessor.PrintBloodValues("incoming Blood"); //patientAfterStep0.PrintBloodValues(""); Console.Out.WriteLine("Step 1"); simulator.SimulateStep(); /* * //dialyzerAfterStep1.Should().Be(1); * patientAfterStep4.BigWasteProducts.Should().Be(0); * patientAfterStep4.SmallWasteProducts.Should().Be(2);*/ }
public void ExtracorporealBloodCircuitWorks_Simulation() { var specification = new ExtracorporealBloodCircuitTestEnvironment(); var simulator = new SafetySharpSimulator(specification); //Important: Call after all objects have been created var extracorporealBloodCircuitAfterStep0 = simulator.Model.Roots.OfType <ExtracorporealBloodCircuit>().First(); var patientAfterStep0 = simulator.Model.Roots.OfType <Patient>().First(); Console.Out.WriteLine("Initial"); patientAfterStep0.ArteryFlow.Outgoing.Forward.PrintBloodValues("outgoing Blood"); patientAfterStep0.VeinFlow.Incoming.Forward.PrintBloodValues("incoming Blood"); patientAfterStep0.PrintBloodValues(""); Console.Out.WriteLine("Step 1"); simulator.SimulateStep(); /* * //dialyzerAfterStep1.Should().Be(1); * patientAfterStep4.BigWasteProducts.Should().Be(0); * patientAfterStep4.SmallWasteProducts.Should().Be(2); */ }
public void MergeFlowWorksWithComposite() { var testModel = new IntFlowModel(); var sourceOutside = new IntFlowSource(); var sourceInside = new IntFlowSource(); var composite = new IntFlowComposite(); var way1Direct = new IntFlowInToOut(); var way2Direct = new IntFlowInToOut(); var sink = new IntFlowSink(); testModel.Components = new IntFlowComponentCollection(sourceOutside, sourceInside, composite, way1Direct, way2Direct, sink); sourceOutside.SendForward = testModel.CreateForward; sourceOutside.ReceivedBackward = testModel.PrintReceivedBackward; sourceInside.SendForward = testModel.CreateForward; sourceInside.ReceivedBackward = testModel.PrintReceivedBackward; sink.SendBackward = testModel.CreateBackward; sink.ReceivedForward = testModel.PrintReceivedForward; testModel.Combinator.ConnectOutWithIn(sourceOutside, composite); testModel.Combinator.ConnectInWithIn(composite, way1Direct); testModel.Combinator.ConnectOutWithIn(sourceInside, way2Direct); testModel.Combinator.ConnectOutsWithOut(new IFlowComponentUniqueOutgoing <Int, Int>[] { way1Direct, way2Direct }, composite); testModel.Combinator.ConnectOutWithIn(composite, sink); testModel.Combinator.CommitFlow(); var simulator = new SafetySharpSimulator(testModel); //Important: Call after all objects have been created simulator.SimulateStep(); var flowCombinatorAfterStep = (IntFlowCombinator)simulator.Model.Roots[0]; var flowComponentsAfterStep = ((IntFlowComponentCollection)simulator.Model.Roots[1]).Components; var sourceInsideAfterStep = (IntFlowSource)flowComponentsAfterStep[1]; var sourceOutsideAfterStep = (IntFlowSource)flowComponentsAfterStep[0]; var sinkAfterStep = (IntFlowSink)flowComponentsAfterStep[5]; sinkAfterStep.Incoming.Forward.Should().Be(7); sourceOutsideAfterStep.Outgoing.Backward.Should().Be(1); sourceInsideAfterStep.Outgoing.Backward.Should().Be(1); }
protected override void Check() { var m1 = new M(); var s = new SafetySharpSimulator(m1, m1.Formula); var m2 = (M)s.Model; m1.A.I.ShouldBe(m2.A.I); m1.B.I.ShouldBe(m2.B.I); m1.C.I.ShouldBe(m2.C.I); m1.D().I.ShouldBe(m2.D().I); m1.E.I.ShouldBe(m2.E.I); m1.F.I.ShouldBe(m2.F.I); m1.G.I.ShouldBe(m2.G.I); m1.H().I.ShouldBe(m2.H().I); s.RuntimeModel.Evaluate(m2.Formula).ShouldBe(false); m2.Roots.ShouldBe(new IComponent[] { m2.A, m2.B, m2.C, m2.D() }, ignoreOrder: true); m2.Components.ShouldBe(new IComponent[] { m2.A, m2.B, m2.C, m2.D() }, ignoreOrder: true); m2.Faults.ShouldBeEmpty(); }
protected override void Check() { var simulator = new SafetySharpSimulator(TestModel.InitializeModel(new C())); var c = (C)simulator.Model.Roots[0]; c.X.ShouldBe(0); c.Y.ShouldBe(0); c.Z.ShouldBe(0); simulator.SimulateStep(); c.X.ShouldBe(1); c.Y.ShouldBe(1); c.Z.ShouldBe(1); simulator.SimulateStep(); c.X.ShouldBe(2); c.Y.ShouldBe(0); c.Z.ShouldBe(2); simulator.SimulateStep(); c.X.ShouldBe(2); c.Y.ShouldBe(1); c.Z.ShouldBe(3); var exception = Should.Throw <RangeViolationException>(() => simulator.SimulateStep()); exception.Field.ShouldBe(typeof(C).GetField("Z")); exception.Object.ShouldBe(c); exception.FieldValue.ShouldBe(4); exception.Range.LowerBound.ShouldBe(0); exception.Range.UpperBound.ShouldBe(3); exception.Range.OverflowBehavior.ShouldBe(OverflowBehavior.Error); simulator.Reset(); c.X.ShouldBe(0); c.Y.ShouldBe(0); c.Z.ShouldBe(0); }
public void Simulate_10_Step_DialyzerRuptured() { var testModel = new Model(); var simulator = new SafetySharpSimulator(testModel); //Important: Call after all objects have been created var patient = simulator.Model.Roots.OfType <Patient>().First(); var hdMachine = simulator.Model.Roots.OfType <HdMachine>().First(); hdMachine.Dialyzer.DialyzerMembraneRupturesFault.Activation = Activation.Forced; simulator.SimulateStep(); patient = simulator.Model.Roots.OfType <Patient>().First(); simulator.SimulateStep(); patient = simulator.Model.Roots.OfType <Patient>().First(); simulator.SimulateStep(); patient = simulator.Model.Roots.OfType <Patient>().First(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); simulator.SimulateStep(); }
public void TankRupturesWhenSensorDoesNotReportTankFullAndTimerDoesNotTimeout() { var model = new Model(); model.Faults.SuppressActivations(); model.Sensor.SuppressIsFull.ForceActivation(); model.Timer.SuppressTimeout.ForceActivation(); // Check that the tank is ruptured after 62 steps var simulator = new SafetySharpSimulator(model); model = (Model)simulator.Model; simulator.FastForward(steps: 62); model.Tank.IsRuptured.Should().BeTrue(); // Check that the tank does not rupture in the first 61 steps simulator.Reset(); for (var i = 0; i < 61; ++i) { simulator.SimulateStep(); model.Tank.IsRuptured.Should().BeFalse(); } }