Exemple #1
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);
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        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();
            }
        }
Exemple #5
0
        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();
            }
        }