Пример #1
0
        public void SensorValueReached_Trigger()
        {
            var sensor  = new TestSensor(ActuatorIdFactory.EmptyId, new TestLogger());
            var trigger = new SensorValueReachedTrigger(sensor);

            trigger.Target = 10.2F;
            trigger.Delta  = 3.0F;

            int triggerCount = 0;

            trigger.Attach(() => triggerCount++);

            sensor.SetValue(5);
            triggerCount.ShouldBeEquivalentTo(0);

            sensor.SetValue(10);
            triggerCount.ShouldBeEquivalentTo(0);

            sensor.SetValue(10.2F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.SetValue(9.0F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.SetValue(13.0F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.SetValue(5.0F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.SetValue(10.2F);
            triggerCount.ShouldBeEquivalentTo(2);
        }
Пример #2
0
        public void SensorValueReached_Trigger()
        {
            var sensor  = new TestTemperatureSensor(ComponentIdFactory.EmptyId, new TestNumericValueSensorEndpoint());
            var trigger = new SensorValueReachedTrigger(sensor);

            trigger.Target = 10.2F;
            trigger.Delta  = 3.0F;

            int triggerCount = 0;

            trigger.Attach(() => triggerCount++);

            sensor.Endpoint.UpdateValue(5);
            triggerCount.ShouldBeEquivalentTo(0);

            sensor.Endpoint.UpdateValue(10);
            triggerCount.ShouldBeEquivalentTo(0);

            sensor.Endpoint.UpdateValue(10.2F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.Endpoint.UpdateValue(9.0F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.Endpoint.UpdateValue(13.0F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.Endpoint.UpdateValue(5.0F);
            triggerCount.ShouldBeEquivalentTo(1);

            sensor.Endpoint.UpdateValue(10.2F);
            triggerCount.ShouldBeEquivalentTo(2);
        }