Ejemplo n.º 1
0
        public void AlarmSetsOffWhenPressureIsAbnormal()
        {
            var alarm = new Alarm(this.fakeSensor.Object);

            for (int i = 0; i < 10; i++)
            {
                this.fakeSensor.Setup(fs => fs.PopNextPressurePsiValue())
                .Returns(randomizer.Next((int)Alarm.LowPressureThreshold));

                alarm.Check();


                Assert.That(alarm.AlarmOn, Is.EqualTo(true), "Alarm does not go off when pressure is low");
            }

            for (int i = 0; i < 10; i++)
            {
                this.fakeSensor.Setup(fs => fs.PopNextPressurePsiValue())
                .Returns(randomizer.Next((int)Alarm.HighPressureThreshold + 2, int.MaxValue));

                alarm.Check();


                Assert.That(alarm.AlarmOn, Is.EqualTo(true), "Alarm does not go off when pressure is high");
            }
        }
Ejemplo n.º 2
0
        public void should_sensor_with_out_of_range__value_trigger_the_alarm(int sensorValue)
        {
            _sensorMock.PushNextPressurePsiValue(sensorValue);

            _alarm.Check();
            bool resultAlarm = _alarm.AlarmOn;

            Assert.IsTrue(resultAlarm);
        }
        public void a_normal_pressure_value_after_an_out_of_range_pressure_value_should_keep_the_alarm_on()
        {
            StubSensor stubSensor = new StubSensor();
            stubSensor.StubCallToPopNextPressurePsiValues(new double[] { Alarm.LowPressureTreshold, Alarm.LowPressureTreshold - 1, Alarm.LowPressureTreshold });
            Alarm target = new Alarm(stubSensor);

            target.Check();
            target.Check();
            target.Check();

            Assert.AreEqual(true, target.AlarmOn, "alarm on");
        }
        public void CheckTurnsAlarmOffWhenPressureRestoresToNormal()
        {
            var alarm       = new Alarm();
            var lowPressure = alarm.LowPressureThreshold - 1;

            alarm.Check(lowPressure);
            Assert.IsTrue(alarm.AlarmOn);

            var normalPressure = alarm.LowPressureThreshold + 1;

            alarm.Check(normalPressure);
            Assert.IsFalse(alarm.AlarmOn);
        }
Ejemplo n.º 5
0
        public void a_normal_pressure_value_after_an_out_of_range_pressure_value_should_keep_the_alarm_on()
        {
            StubSensor stubSensor = new StubSensor();

            stubSensor.StubCallToPopNextPressurePsiValues(new double[] { Alarm.LowPressureTreshold, Alarm.LowPressureTreshold - 1, Alarm.LowPressureTreshold });
            Alarm target = new Alarm(stubSensor);

            target.Check();
            target.Check();
            target.Check();

            Assert.AreEqual(true, target.AlarmOn, "alarm on");
        }
Ejemplo n.º 6
0
        public void A_normal_pressure_value_after_a_value_outside_the_range_should_stop_the_alarm()
        {
            // Arrange
            StubSensor stubSensor = new StubSensor();
            Alarm      alarm      = new Alarm(stubSensor);

            // Act
            stubSensor.ArrangeNextPressurePsiValue(Alarm.LowPressureThreshold - 1);
            alarm.Check();
            stubSensor.ArrangeNextPressurePsiValue(Alarm.LowPressureThreshold);
            alarm.Check();

            // Assert
            Assert.IsFalse(alarm.AlarmOn);
        }
Ejemplo n.º 7
0
        public static void Main()
        {
            IAlarm alarm = new Alarm();

            alarm.Check();
            Console.WriteLine(alarm.AlarmOn);
        }
        public void TestSystemWithValidValues(double sensorValue)
        {
            var fakeSensor = new Mock <ISensor>();

            fakeSensor
            .Setup(fs => fs.PopNextPressurePsiValue())
            .Returns(sensorValue);

            var fakeSensorObj = fakeSensor.Object;

            var alarm = new Alarm(fakeSensor.Object);

            //Not Sucess as Mock.Object returns proxy type :(
            //typeof(Alarm)
            //    .GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
            //    .First(f => f.FieldType == typeof(Sensor))
            //    .SetValue(alarm, fakeSensorObj);

            var expectedValue = false;

            alarm.Check();
            var actualValue = alarm.AlarmOn;

            Assert.That(actualValue, Is.EqualTo(expectedValue));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Updates the card test for card Presses if state is set to selecting
        /// </summary>
        /// <param name="mouse">current Mouse object</param>
        /// <param name="timer">current Timer Object</param>
        protected override void OnUpdate(GameCore.Input.Keyboard keyboard, GameCore.Input.Mouse mouse, GameCore.Timing.Timer timer)
        {
            if (!Active)
            {
                return;
            }
            almDelay.Update(timer.DeltaTimeMS);

            if (almDelay.Check(Alarm.CheckType.RESET))
            {
                if (objValue != curValue)
                {
                    if (StateMain.singleton.soundsOn)
                    {
                        StateMain.singleton.Sounds.odoTick.Play(false, true);
                    }

                    if (Math.Abs(objValue - curValue) < Math.Abs(step))
                    {
                        curValue = objValue;
                    }
                    else
                    {
                        curValue += step;
                    }
                }

                txtCounter.Text = curValue.ToString(format);
                if (txtCounter.Text == "")
                {
                    txtCounter.Text = "0";
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Updates the card test for card Presses if state is set to selecting
 /// </summary>
 /// <param name="mouse">current Mouse object</param>
 /// <param name="timer">current Timer Object</param>
 protected override void OnUpdate(GameCore.Input.Keyboard keyboard, GameCore.Input.Mouse mouse, GameCore.Timing.Timer timer)
 {
     if (status == iconStatus.Concealed)
     {
         if (Released && (StateMain.singleton.currentState == StateMain.singleton.stPlay || StateMain.singleton.currentState == StateMain.singleton.stCredit))
         {
             //if (StateMain.singleton.soundsOn)
             //{
             //    StateMain.singleton.Sounds.iconReveal.Stop(true);
             //    StateMain.singleton.Sounds.iconReveal.Play(false, true);
             //}
             //Reveal();
             //if(!((StPlay)StateMain.singleton.stPlay).autoReveal)
             //StateMain.singleton.saveRecoveryRecord();   //every icon should be updated...
         }
     }
     else if (status == iconStatus.Revealing)
     {
         almCoverAnim.Update(timer.DeltaTimeMS);
         if (almCoverAnim.Check(Alarm.CheckType.RESET))
         {
             coverAnimFrame++;
             if (coverAnimFrame >= Definitions.CoverAnimationFrames)
             {
                 IconsView.singleton.iconsRevealed++;
                 status = iconStatus.Revealed;
             }
         }
     }
 }
        // A class with the only goal of simulating a dependency on Alart
        // that has impact on the refactoring.

        private void DoSomething()
        {
            Alarm anAlarm = new Alarm();

            anAlarm.Check();
            bool isAlarmOn = anAlarm.AlarmOn;
        }
Ejemplo n.º 12
0
        // A class with the only goal of simulating a dependency on Alert
        // that has impact on the refactoring.

        public AnAlarmClient1()
        {
            Alarm anAlarm = new Alarm();

            anAlarm.Check();
            bool isAlarmOn = anAlarm.AlarmOn;
        }
        public void Psi_Value_Within_Valid_Range_Does_Not_Trigger_The_Alarm()
        {
            Alarm alarm = new Alarm(new Sensor(new RandomNumberGenerator(0.5)));

            alarm.Check();

            alarm.AlarmOn.Should().BeFalse();
        }
Ejemplo n.º 14
0
        public void thinks_in_what_we_need_to_test()
        {
            var alarm = new Alarm();

            alarm.Check();

            Assert.True(false);
        }
        public void Psi_Value_Of_TwentyTwo_Triggers_The_Alarm()
        {
            Alarm alarm = new Alarm(new Sensor(new RandomNumberGenerator(1)));

            alarm.Check();

            alarm.AlarmOn.Should().BeTrue();
        }
Ejemplo n.º 16
0
        public override void OnUpdate(Keyboard keyboard, Mouse mouse, Timer timer)
        {
            if (context.btnRevealAll.Released)
            {
                context.btnRevealAll.Enable = false;
                autoReveal = true;
            }

            if (autoReveal)
            {
                almAutoRevealDelay.Update(timer.DeltaTimeMS);
                if (almAutoRevealDelay.Check(Alarm.CheckType.RESET))
                {
                    if (context.soundsOn)
                    {
                        //context.Sounds.iconReveal.Stop(true);
                        //context.Sounds.iconReveal.Play(false, true);
                    }

                    int iconNo = randomIcon[rCounter];
                    if (context.iconsView.icons[iconNo].status == Icon.iconStatus.Concealed)
                    {
                        context.iconsView.icons[iconNo].Reveal();
                    }
                    rCounter++;
                    if (rCounter >= Definitions.IconsPerTab)
                    {
                        autoReveal = false;
                        rCounter   = 0;
                    }
                }
            }

            if (context.iconsView.iconsRevealed >= Definitions.IconsPerTab)
            {
                //done either win or lose...

                if (winnings > 0 || freeTabsWon > 0)
                {
                    context.changeStateTo(context.stWin);
                }
                else
                {
                    context.changeStateTo(context.stLose);
                }
            }


            //if (keyboard.KeyReleased('S'))
            //{
            //    Bingo.singleton.logError("test log");
            //    context.iconsView.icons[0].iconNo = 10;
            //    context.iconsView.icons[2].iconNo = 10;
            //    context.iconsView.icons[7].iconNo = 10;
            //    freeTabsWon = 4;
            //    autoReveal = true;
            //}
        }
Ejemplo n.º 17
0
        public void TheAlarmShouldAlwaysBeRestToReturnTheValidResult()
        {
            // Arranges
            var mockedSensor = new Mock <ISensor>();

            mockedSensor.SetupSequence(method => method.GetValue())
            .Returns(-22)
            .Returns(0);
            var alarm = new Alarm(mockedSensor.Object);

            // Acts
            alarm.Check();
            Check.That(alarm.Status).IsTrue();
            alarm.Check();

            // Asserts
            Check.That(alarm.Status).IsFalse();
        }
        public void CheckSetsAlarmOnWhenPressureIsTooHigh()
        {
            var alarm        = new Alarm();
            var highPressure = alarm.HighPressureThreshold + 1;

            alarm.Check(highPressure);

            Assert.IsTrue(alarm.AlarmOn);
        }
        public void CheckKeepsAlarmOffWhenPressureIsNormal()
        {
            var alarm          = new Alarm();
            var normalPressure = alarm.LowPressureThreshold + 1;

            alarm.Check(normalPressure);

            Assert.IsFalse(alarm.AlarmOn);
        }
        public void a_pressure_value_out_of_range_should_raise_the_alarm()
        {
            StubSensor stubSensor = new StubSensor();
            stubSensor.StubCallToPopNextPressurePsiValue(Alarm.LowPressureTreshold -1);
            Alarm target = new Alarm(stubSensor);

            target.Check();

            Assert.AreEqual(true, target.AlarmOn, "alarm on");
        }
        public void a_normal_pressure_value_should_not_raise_the_alarm()
        {
            StubSensor stubSensor = new StubSensor();
            stubSensor.StubCallToPopNextPressurePsiValue(Alarm.LowPressureTreshold);
            Alarm target = new Alarm(stubSensor);

            target.Check();

            Assert.AreEqual(false, target.AlarmOn, "alarm on");
        }
Ejemplo n.º 22
0
        public void AlarmOn_CheckOutOfRangeThenInRange_StaysOn()
        {
            Mock <ISensor> sensorMock = new Mock <ISensor>();

            sensorMock.Setup(s => s.PopNextPressurePsiValue()).Returns(25D);

            Alarm alarm = new Alarm(sensorMock.Object);

            alarm.Check();

            sensorMock.Setup(s => s.PopNextPressurePsiValue()).Returns(20D);

            alarm.Check();

            bool expectedResult = true;
            bool actualResult   = alarm.AlarmOn;

            Assert.That(actualResult, Is.EqualTo(expectedResult));
        }
        public bool SensorReadingWithinLimitsShouldNotTriggerAlarmAlarm(double pressureSensorValue)
        {
            Alarm     alarm  = new Alarm();
            FieldInfo sensor = alarm.GetType().GetField("_sensor", BindingFlags.NonPublic | BindingFlags.Instance);

            mockSensor.Setup(s => s.PopNextPressurePsiValue()).Returns(pressureSensorValue);
            sensor.SetValue(alarm, mockSensor.Object);
            alarm.Check();
            return(alarm.AlarmOn);
        }
Ejemplo n.º 24
0
        public void a_pressure_value_out_of_range_should_raise_the_alarm()
        {
            StubSensor stubSensor = new StubSensor();

            stubSensor.StubCallToPopNextPressurePsiValue(Alarm.LowPressureTreshold - 1);
            Alarm target = new Alarm(stubSensor);

            target.Check();

            Assert.AreEqual(true, target.AlarmOn, "alarm on");
        }
        public void CheckSetsAlarmOnWhenPressureIsTooLow()
        {
            // simulate sensor values until we get a value that is less
            // than the lower threshold
            var alarm       = new Alarm();
            var lowPressure = alarm.LowPressureThreshold - 1;

            alarm.Check(lowPressure);

            Assert.IsTrue(alarm.AlarmOn);
        }
Ejemplo n.º 26
0
        public void a_normal_pressure_value_should_not_raise_the_alarm()
        {
            StubSensor stubSensor = new StubSensor();

            stubSensor.StubCallToPopNextPressurePsiValue(Alarm.LowPressureTreshold);
            Alarm target = new Alarm(stubSensor);

            target.Check();

            Assert.AreEqual(false, target.AlarmOn, "alarm on");
        }
Ejemplo n.º 27
0
        public void TestHighPressure()
        {
            var sensor = new Mock <ISensor>();

            sensor.Setup(s => s.PopNextPressurePsiValue()).Returns(25D);

            Alarm alarm = new Alarm();

            alarm.Check();

            Assert.That(alarm.AlarmOn, Is.EqualTo(true));
        }
Ejemplo n.º 28
0
        public override void OnUpdate(Keyboard keyboard, Mouse mouse, Timer timer)
        {
            almGameOver.Update(timer.DeltaTimeMS);
            if (almGameOver.Check(Alarm.CheckType.TURNOFF))
            {
                context.cashOut();
            }

            if (context.btnCashout.Released)
            {
                context.cashOut();
            }
        }
Ejemplo n.º 29
0
    public void AlarmShouldReturnsFalseIfPressureValueBetweenLowPressureThresholdAndHighPressureThreshold(double pressureSample)
    {
        // Arrange
        randomMock.Setup(x => x.NextDouble()).Returns(pressureSample);

        // Act
        Alarm alarm = SetAlarm(randomMock);

        alarm.Check();

        // Assert
        Assert.That(alarm.AlarmOn, Is.EqualTo(false), "Alarm not work correctly!");
    }
Ejemplo n.º 30
0
        public void A_pressure_value_outside_the_range_should_raise_the_alarm()
        {
            // Arrange
            StubSensor stubSensor = new StubSensor();
            Alarm      alarm      = new Alarm(stubSensor);

            // Act
            stubSensor.ArrangeNextPressurePsiValue(Alarm.HighPressureThreshold + 1);
            alarm.Check();

            // Assert
            Assert.IsTrue(alarm.AlarmOn);
        }
        public void TirePressureSystem_AlarmIsOn(double value)
        {
            var            alarm  = new Alarm();
            Mock <ISensor> sensor = new Mock <ISensor>();

            sensor.Setup(x => x.PopNextPressurePsiValue()).Returns(value);

            alarm.Check();
            var actual   = alarm.AlarmOn;
            var expected = true;

            Assert.That(actual, Is.EqualTo(expected));
        }
Ejemplo n.º 32
0
        public void AlarmOn_IsTrue_WhenPsiIs_OutOfRange(double psiOffest)
        {
            var randPsiStub = new Mock <IRandomPsi>();

            randPsiStub.Setup(r => r.ReadPressureSample()).Returns(psiOffest);
            var sensor = new Sensor();

            IAlarm sut = new Alarm();

            sut.Check(sensor, randPsiStub.Object);

            Assert.That(sut.AlarmOn, Is.True);
        }
Ejemplo n.º 33
0
    public void LowPressureTireShouldActivateAlarm(double tirePressure)
    {
        Mock <ISensor> fakeSensor = new Mock <ISensor>();

        fakeSensor.Setup(p => p.PopNextPressurePsiValue())
        .Returns(tirePressure);
        IAlarm alarm = new Alarm(fakeSensor.Object);

        alarm.Check();

        Assert.That(alarm.AlarmOn, Is.EqualTo(true),
                    "Low pressure tire didn't acitvate alarm.");
    }
        public void GIVEN_pressure_psi_value_is_16_WHEN_check_pressure_value_in_alarm_THEN_alarm_is_on()
        {
            // Given
            var sensor = new Mock<ISensor>();
            var alarm = new Alarm(sensor.Object);

            sensor
                .Setup(s => s.PopNextPressurePsiValue())
                .Returns(16.0);

            // When
            alarm.Check();

            // Then
            Assert.IsTrue(alarm.AlarmOn);
            sensor.Verify(s => s.PopNextPressurePsiValue());
        }