public bool CheckIndividualValue(Sensor sensor, DateTime timeStamp)
 {
     if (sensor.CurrentState.Values.ContainsKey(timeStamp))
         return false;
     var value = sensor.CurrentState.Values[timeStamp];
     return Math.Abs(value - sensor.CurrentState.Values[sensor.CurrentState.FindPrevValue(timeStamp)]) > sensor.MaxRateOfChange;
 }
        public void TestMissingValues()
        {
            var contact = new Contact("Jim", "Does", "*****@*****.**", "Lollipops", "837773");
            var dataSet = new Dataset(new Site(4, "New Site", "Tim Jones", contact, contact, new GPSCoords(0, 0, "argis")));

            var sensor = new Sensor("Dummy Sensor", "Does stuff", 10, 0, "C", 5, dataSet);

            sensor.AddState(new SensorState(sensor, DateTime.Now));
            sensor.CurrentState.Values.Add(new DateTime(1990, 5, 1, 4, 0, 0), 15);
            sensor.CurrentState.Values.Add(new DateTime(1990, 5, 1, 5, 0, 0), 15);
            sensor.CurrentState.Values.Add(new DateTime(1991, 8, 2, 0, 0, 0), 15);

            dataSet.AddSensor(sensor);

            dataSet.DataInterval = 60;

            dataSet.HighestYearLoaded = 1;

            Assert.AreEqual(60, dataSet.DataInterval);

            var missingValues = missingValuesDetector.GetDetectedValues(sensor);

            for (var i = new DateTime(1990, 5, 1, 6, 0, 0); i < new DateTime(1991, 8, 2, 0, 0, 0); i = i.AddHours(1))
            {
                Assert.Contains(new ErroneousValue(i, missingValuesDetector, sensor), missingValues);
            }
        }
示例#3
0
        public ListedSensor(Sensor s, Dataset d)
        {
            if(s == null)
                throw new ArgumentNullException("The specified sensor cannot be null.");

            if (d == null)
                throw new ArgumentNullException("The specified dataset cannot be null.");

            _sensor = s;
            _ds = d;
        }
示例#4
0
        public ErroneousValue(DateTime timeStamp, Sensor owner)
        {
            Owner = owner;

            TimeStamp = timeStamp;

            Detectors = new List<IDetectionMethod>();

            _hasValue = false;

            _command = new GraphCenteringCommand(this);
        }
示例#5
0
        //[Test] Limit no longer applied as we don't save the undo/redo stack
        public void AddStateMaximumFiveEntries()
        {
            var s = new Sensor("Temperature", "C");
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));

            Assert.AreEqual(5, s.UndoStates.Count);
        }
示例#6
0
        public void SetUp()
        {
            _tempFile = Path.GetTempFileName();
            _baseTime = DateTime.Now;
            _ds = new Dataset(new Site(1, "Super Site", "Jimmy Jones", new Contact("Jimmy", "Jones", "*****@*****.**", "Jones Industries", "5551234"), null, new GPSCoords(1, 1,"jayqon")));

            var sensor = new Sensor("Super Sensor", null, _ds);

            sensor.RawData.Values[_baseTime] = 0;
            sensor.RawData.Values[_baseTime.AddHours(1)] = 1;
            sensor.RawData.Values[_baseTime.AddHours(2)] = 2;
            sensor.RawData.Values[_baseTime.AddHours(3)] = 3;
            sensor.RawData.Values[_baseTime.AddHours(4)] = 4;
            sensor.RawData.Values[_baseTime.AddHours(6)] = 6;
            sensor.RawData.Values[_baseTime.AddHours(7)] = 7;
            sensor.RawData.Values[_baseTime.AddHours(8)] = 8;
            sensor.RawData.Values[_baseTime.AddHours(9)] = 9;
            sensor.RawData.Values[_baseTime.AddHours(14)] = 14;
            sensor.RawData.Values[_baseTime.AddHours(15)] = 15;

            _ds.Sensors = new List<Sensor> { sensor };
        }
示例#7
0
        public void ExportAsCSVCorrectValueCount()
        {
            var dateTime = new DateTime(2011, 8, 4, 0, 0, 0);
            var givenDataSet = new Dataset(new Site(1, "Steven", "Kerry", Contact, Contact, new GPSCoords(0, 0, "arcGis")));
            var sampleData = new Dictionary<DateTime, float> { { dateTime.AddMinutes(15), 100 }, { dateTime.AddMinutes(30), 100 }, { dateTime.AddMinutes(45), 100 }, { dateTime.AddMinutes(60), 100 } };
            var s = new Sensor("Awesome Sensor", "Awesome");
            var ss = new SensorState(s, DateTime.Now, sampleData, null);
            s.AddState(ss);
            givenDataSet.AddSensor(s);

            Assert.AreEqual(4, givenDataSet.ExpectedDataPointCount);

            dateTime = new DateTime(2011, 8, 4, 0, 0, 0);
            givenDataSet = new Dataset(new Site(1, "Steven", "Kerry", Contact, Contact, new GPSCoords(0, 0, "arcGis")));

            sampleData = new Dictionary<DateTime, float> { { dateTime.AddMinutes(60), 100 }, { dateTime.AddMinutes(75), 100 }, { dateTime.AddMinutes(90), 100 }, { dateTime.AddMinutes(105), 100 } };
            s = new Sensor("Awesome Sensor", "Awesome");
            ss = new SensorState(s, DateTime.Now, sampleData, null);
            s.AddState(ss);
            givenDataSet.AddSensor(s);

            Assert.AreEqual(4, givenDataSet.ExpectedDataPointCount);
        }
示例#8
0
        public void MovesSensorsCorrectly()
        {
            var A = new Sensor("Temperature at 10m", "A");
            var B = new Sensor("Temperature at 50m", "B");
            var C = new Sensor("Temperature at 100m", "C");
            var D = new Sensor("Temperature at 200m", "D");
            var E = new Sensor("Temperature at 500m", "E");

            _ds1.Sensors.AddRange(new Sensor[] { A, B, C, D, E });

            _ds1.MoveSensorTo(A, C);

            Assert.AreEqual(0, _ds1.Sensors.IndexOf(B));
            Assert.AreEqual(1, _ds1.Sensors.IndexOf(C));
            Assert.AreEqual(2, _ds1.Sensors.IndexOf(A));
            Assert.AreEqual(3, _ds1.Sensors.IndexOf(D));
            Assert.AreEqual(4, _ds1.Sensors.IndexOf(E));

            _ds1.MoveSensorTo(E, C);

            Assert.AreEqual(0, _ds1.Sensors.IndexOf(B));
            Assert.AreEqual(1, _ds1.Sensors.IndexOf(E));
            Assert.AreEqual(2, _ds1.Sensors.IndexOf(C));
            Assert.AreEqual(3, _ds1.Sensors.IndexOf(A));
            Assert.AreEqual(4, _ds1.Sensors.IndexOf(D));
        }
示例#9
0
        public void ProvidesDefaultValuesWhenMatches()
        {
            var testSensor = new Sensor("Temperature", "C", 150, 50, "F", 8.3f, null);
            var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp");

            s.ProvideDefaultValues(testSensor);

            Assert.AreEqual(testSensor.Unit, s.Unit);
            Assert.AreEqual(testSensor.UpperLimit, s.UpperLimit);
            Assert.AreEqual(testSensor.LowerLimit, s.LowerLimit);
            Assert.AreEqual(testSensor.MaxRateOfChange, s.MaximumRateOfChange);
        }
示例#10
0
 public void ConstructWithZeroErrorThreshold()
 {
     var sensor = new Sensor(_testName, _testDescription, _testUpperLimit, _testLowerLimit, _testUnit,
                              _testMaxRateOfChange, _testUndoStates, _testUndoStates,
                              new List<Calibration>(), 0, _ds);
 }
示例#11
0
 public void SensorListTest()
 {
     var s1 = new Sensor("temp", "deg");
     var s2 = new Sensor("DO", "%");
     var sensors = new List<Sensor> { s1, s2 };
     _ds1.AddSensor(s1);
     _ds1.AddSensor(s2);
     Assert.AreEqual(sensors, _ds1.Sensors);
 }
示例#12
0
 public void SetCalibrationDatesListToNull()
 {
     var testSensor = new Sensor(_testName, _testDescription, _testUpperLimit, _testLowerLimit, _testUnit, _testMaxRateOfChange, _testUndoStates, _blankStack, _blankCalibrationDates, _ds);
     testSensor.Calibrations = null;
 }
示例#13
0
 public void RawNeverNull()
 {
     var s = new Sensor("Temperature", "C");
     Assert.IsNotNull(s.RawData);
 }
示例#14
0
        public void UndoToParticularState()
        {
            var s = new Sensor("Temperature", "C");
            var baseDate = new DateTime(2011, 7, 7, 12, 15, 0);

            s.AddState(new SensorState(s, baseDate));
            s.AddState(new SensorState(s, baseDate.AddMinutes(15)));
            s.AddState(new SensorState(s, baseDate.AddMinutes(30)));
            s.AddState(new SensorState(s, baseDate.AddMinutes(45)));
            s.AddState(new SensorState(s, baseDate.AddMinutes(60)));
            s.AddState(new SensorState(s, baseDate.AddMinutes(75)));
            s.AddState(new SensorState(s, baseDate.AddMinutes(90)));
            s.AddState(new SensorState(s, baseDate.AddMinutes(105)));

            s.Undo(baseDate.AddMinutes(75));

            Assert.AreEqual(2, s.RedoStates.Count);
            Assert.AreEqual(baseDate.AddMinutes(90), s.RedoStates[0].EditTimestamp);
            Assert.AreEqual(baseDate.AddMinutes(105), s.RedoStates[1].EditTimestamp);
        }
        public List<ErroneousValue> GetDetectedValues(Sensor sensorToCheck)
        {
            if (sensorToCheck != _currentSensor)
                GenerateUpperAndLowerLines(sensorToCheck);

            var items = (from value in sensorToCheck.CurrentState.Values
                         where (_upperLine.ContainsKey(value.Key) && value.Value > _upperLine[value.Key]) || (_lowerLine.ContainsKey(value.Key) && value.Value < _lowerLine[value.Key])
                         select new ErroneousValue(value.Key, this, sensorToCheck)).ToList();
            return items;
        }
示例#16
0
        //[Test] Limit no longer applied as we don't save the undo/redo stack
        public void UndoRedoStackMaximumFiveEntries()
        {
            var s = new Sensor("Temperature", "C");

            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));
            s.AddState(new SensorState(s, DateTime.Now));

            Assert.AreEqual(5, s.UndoStates.Count);
            Assert.AreEqual(0, s.RedoStates.Count);

            s.Undo();
            s.Undo();
            s.Undo();
            s.Undo();

            // Since the top of the undo stack is the current state, we must have at least one item left on the undo stack...
            Assert.AreEqual(1, s.UndoStates.Count); // This is the real test
            Assert.AreEqual(4, s.RedoStates.Count);

            s.Redo();
            s.Redo();
            s.Redo();
            s.Redo();

            Assert.AreEqual(5, s.UndoStates.Count); // This is the real test
            Assert.AreEqual(0, s.RedoStates.Count);
        }
示例#17
0
        //[Test] Limit no longer applied as we don't save the undo/redo stack
        public void UndoStackPushesCorrectEntriesAndMaxFive()
        {
            var s = new Sensor("Temperature", "C");
            var baseDate = new DateTime(2011, 7, 7, 12, 15, 0);

            s.AddState(new SensorState(s, baseDate));
            Assert.AreEqual(baseDate, s.UndoStates[0].EditTimestamp);

            s.AddState(new SensorState(s, baseDate.AddMinutes(15)));
            Assert.AreEqual(baseDate.AddMinutes(15), s.UndoStates[0].EditTimestamp);

            s.AddState(new SensorState(s, baseDate.AddMinutes(30)));
            Assert.AreEqual(baseDate.AddMinutes(30), s.UndoStates[0].EditTimestamp);

            s.AddState(new SensorState(s, baseDate.AddMinutes(45)));
            Assert.AreEqual(baseDate.AddMinutes(45), s.UndoStates[0].EditTimestamp);

            s.AddState(new SensorState(s, baseDate.AddMinutes(60)));
            Assert.AreEqual(baseDate.AddMinutes(60), s.UndoStates[0].EditTimestamp);

            // Now, for the real test of the method...
            s.AddState(new SensorState(s, baseDate.AddMinutes(75)));
            Assert.AreEqual(baseDate.AddMinutes(75), s.UndoStates[0].EditTimestamp);
            Assert.AreEqual(baseDate.AddMinutes(15), s.UndoStates[4].EditTimestamp);

            s.AddState(new SensorState(s, baseDate.AddMinutes(90)));
            Assert.AreEqual(baseDate.AddMinutes(90), s.UndoStates[0].EditTimestamp);
            Assert.AreEqual(baseDate.AddMinutes(30), s.UndoStates[4].EditTimestamp);
        }
示例#18
0
        public void Setup()
        {
            _testUndoStates = new Stack<SensorState>();

            var testState = new SensorState(null, new DateTime(2010, 5, 7, 18, 42, 0));
            var secondaryTestState = new SensorState(null, new DateTime(2010, 12, 18, 5, 22, 0));

            _testUndoStates.Push(testState);
            _testUndoStates.Push(secondaryTestState);

            _secondUndoStates = new Stack<SensorState>();
            _secondUndoStates.Push(new SensorState(null, new DateTime(2005, 4, 3, 2, 1, 0)));
            _secondUndoStates.Push(new SensorState(null, new DateTime(2005, 4, 4, 2, 1, 0)));

            _tempSensor = new Sensor("Temperature", "C");

            // Initialise sensors for undo testing
            _undoSensor = new Sensor("Temperature", "C");
            _undoSensor.AddState(new SensorState(_undoSensor, new DateTime(2011, 8, 11),
                                                       new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));
            _undoSensor.AddState(new SensorState(_undoSensor, new DateTime(2011, 8, 12),
                                            new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));

            _secondUndoSensor = new Sensor("Temperature", "C");
            _secondUndoSensor.AddState(new SensorState(_secondUndoSensor, new DateTime(2011, 3, 11),
                                                       new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));
            _secondUndoSensor.AddState(new SensorState(_secondUndoSensor, new DateTime(2011, 3, 12),
                                            new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));

            _sensorEmpty = new Sensor("Temperature", "C");
            _ds = new Dataset(new Site(10, "Lake", "Bob Smith", contact, contact, new GPSCoords(50, 50, "argis")));
            _ds2 = new Dataset(new Site(10, "Lake Awesome", "Andy Smith", contact, contact, new GPSCoords(70, 30, "argis")));

            _sensor1 = new Sensor("Temperature", "Temperature at 10m", 100, 20, "°C", 0.003f, _ds);
            _sensor2 = new Sensor("DO", "Dissolved Oxygen in the water", 50, 0, "%", 5.6f, _ds2);
        }
示例#19
0
        public void SetUndoStates()
        {
            var testSensor = new Sensor(_testName, _testDescription, _testUpperLimit, _testLowerLimit, _testUnit, _testMaxRateOfChange, new Stack<SensorState>(), _blankStack, _blankCalibrationDates, _ds);

            var secondStates = _secondUndoStates.Reverse();

            foreach (SensorState s in secondStates)
                testSensor.AddState(s);

            Assert.AreEqual(_secondUndoStates.SkipWhile((x, index) => index == 0).ToList(), testSensor.UndoStates);

            // Reset
            testSensor = new Sensor(_testName, _testDescription, _testUpperLimit, _testLowerLimit, _testUnit, _testMaxRateOfChange, _testUndoStates, _blankStack, _blankCalibrationDates, _ds);

            var testUndo = _testUndoStates.Reverse();

            foreach (SensorState s in testUndo)
                testSensor.AddState(s);

            Assert.AreEqual(_testUndoStates, testSensor.UndoStates);
        }
示例#20
0
        public void SetRawData()
        {
            var s = new Sensor("Temperature", "C");
            var baseDate = new DateTime(2011, 5, 5, 12, 15, 0);
            var original = new SensorState(s, new Dictionary<DateTime, float>() { { baseDate.AddMinutes(15), 20 }, { baseDate.AddMinutes(30), 40 }, { baseDate.AddMinutes(45), 60 }, { baseDate.AddMinutes(60), 80 } }, null);

            foreach (KeyValuePair<DateTime, float> kv in original.Values)
                s.RawData.Values.Add(kv.Key, kv.Value);

            Assert.AreEqual(s.RawData, original);
        }
示例#21
0
        public void SensorNameMatchedCorrectly()
        {
            var testSensor = new Sensor("Temperature", "C");
            var testSensorTwo = new Sensor("Dissolved Oxygen", "Q");

            var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp");
            Assert.IsTrue(s.Matches(testSensor));
            Assert.IsFalse(s.Matches(testSensorTwo));

            s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.StartsWith, "Temp");
            Assert.IsTrue(s.Matches(testSensor));
            Assert.IsFalse(s.Matches(testSensorTwo));

            s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.EndsWith, "Temp");
            Assert.IsFalse(s.Matches(testSensor));

            s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.EndsWith, "n");
            Assert.IsTrue(s.Matches(testSensorTwo));
        }
        private void GenerateUpperAndLowerLines(Sensor sensor)
        {
            //Set Current Sensor
            _currentSensor = sensor;

            if (_currentSensor == null)
                return;

            Debug.WriteLine("Generating Lines");
            //Reset lines
            _upperLine = new Dictionary<DateTime, float>();
            _lowerLine = new Dictionary<DateTime, float>();

            var timeGap = _currentSensor.Owner.DataInterval;

            foreach (var value in _currentSensor.CurrentState.Values)
            {
                var meanValues = new List<float>();
                for (var i = value.Key.AddMinutes(-(timeGap * (_smoothingPeriod / 2 / timeGap))); i < value.Key.AddMinutes((timeGap * (_smoothingPeriod / 2 / timeGap))); i = i.AddMinutes(timeGap))
                {
                    if (_currentSensor.CurrentState.Values.ContainsKey(i))
                        meanValues.Add(_currentSensor.CurrentState.Values[i]);
                }

                meanValues.Add(value.Value);

                var average = meanValues.Sum() / meanValues.Count;
                var sumOfSquares = meanValues.Sum(x => Math.Pow(x - average, 2));
                var standardDeviation = Math.Sqrt(sumOfSquares / (meanValues.Count - 1));

                if (double.IsNaN(standardDeviation))
                    standardDeviation = 0;

                _upperLine[value.Key] = (float)(average + (_numberOfStandardDeviations * standardDeviation));
                _lowerLine[value.Key] = (float)(average - (_numberOfStandardDeviations * standardDeviation));

                //Debug.Print("numberOfValues: {0} average: {1} sumOfSquare: {2} stdDev: {3} upper: {4} lower: {5}", meanValues.Count, average, sumOfSquares, standardDeviation, _upperLine[value.Key], _lowerLine[value.Key]);
            }
        }
        public bool CheckIndividualValue(Sensor sensor, DateTime timeStamp)
        {
            if (sensor != _currentSensor)
                GenerateUpperAndLowerLines(sensor);

            if (!HasGraphableSeries || !_upperLine.ContainsKey(timeStamp) || !_lowerLine.ContainsKey(timeStamp) ||
                !sensor.CurrentState.Values.ContainsKey(timeStamp))
                return false;
            return sensor.CurrentState.Values[timeStamp] < _upperLine[timeStamp] &&
                   sensor.CurrentState.Values[timeStamp] > _lowerLine[timeStamp];
        }
示例#24
0
 public ErroneousValue(DateTime timeStamp, IDetectionMethod detector, Sensor owner)
     : this(timeStamp, owner)
 {
     Detectors.Add(detector);
 }
        public List<LineSeries> GraphableSeries(Sensor sensorToBaseOn, DateTime startDate, DateTime endDate)
        {
            if (!HasGraphableSeries)
                return new List<LineSeries>();

            var upperLine = new LineSeries
                                {
                                    DataSeries =
                                        new DataSeries<DateTime, float>("Upper Deviation",
                                        (from point in _upperLine
                                         where point.Key >= startDate && point.Key <= endDate
                                         select new DataPoint<DateTime, float>(point.Key, point.Value)).OrderBy(x => x.X)),
                                    LineStroke = Brushes.OrangeRed
                                };
            var lowerLine = new LineSeries
                                {
                                    DataSeries =
                                        new DataSeries<DateTime, float>("Lower Deviation",
                                        (from point in _lowerLine
                                         where point.Key >= startDate && point.Key <= endDate
                                         select new DataPoint<DateTime, float>(point.Key, point.Value)).OrderBy(x => x.X)),
                                    LineStroke = Brushes.OrangeRed
                                };
            return new List<LineSeries> { upperLine, lowerLine };
        }
示例#26
0
        public void SetCalibrationDates()
        {
            var calibrationDatesTest = new List<Calibration>
                                           {
                                               new Calibration(new DateTime(2011, 7, 4, 21, 15, 0), 10, 0, 0, 15, 2, 0),
                                               new Calibration(new DateTime(2011, 7, 4, 21, 30, 0), 10, 0, 0, 15, 2, 0),
                                               new Calibration(new DateTime(2011, 7, 4, 21, 45, 0), 10, 0, 0, 15, 2, 0),
                                               new Calibration(new DateTime(2011, 7, 4, 22, 15, 0), 10, 0, 0, 15, 2, 0)
                                           };

            Sensor testSensor = new Sensor(_testName, _testDescription, _testUpperLimit, _testLowerLimit, _testUnit, _testMaxRateOfChange, _testUndoStates, _secondUndoStates, calibrationDatesTest, _ds);

            var secondCalibrationTest = new List<Calibration>
                                           {
                                               new Calibration(new DateTime(2011, 7, 3, 21, 15, 0), 10, 0, 0, 15, 2, 0),
                                               new Calibration(new DateTime(2011, 7, 3, 21, 30, 0), 10, 0, 0, 15, 2, 0),
                                               new Calibration(new DateTime(2011, 7, 3, 21, 45, 0), 10, 0, 0, 15, 2, 0),
                                               new Calibration(new DateTime(2011, 7, 3, 22, 15, 0), 10, 0, 0, 15, 2, 0)
                                           };

            testSensor.Calibrations = secondCalibrationTest;

            Assert.AreEqual(secondCalibrationTest, testSensor.Calibrations);
        }
示例#27
0
 public ErroneousValue(DateTime timeStamp, float value, Sensor owner)
     : this(timeStamp, owner)
 {
     Value = value;
     _hasValue = true;
 }
示例#28
0
        public void ValidUndoStatesAfterMultilevelRedo()
        {
            _undoSensor = new Sensor("Temperature", "C");

            var correctStack = new Stack<SensorState>();
            correctStack.Push(new SensorState(_undoSensor, new DateTime(2011, 8, 12),
                                                       new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));
            correctStack.Push(new SensorState(_undoSensor, new DateTime(2011, 8, 11),
                                            new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));
            correctStack.Push(new SensorState(_undoSensor, new DateTime(2011, 8, 12),
                                new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 64.77f } }, null));

            _undoSensor.AddState(new SensorState(_undoSensor, new DateTime(2011, 8, 11),
                                                       new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));
            _undoSensor.AddState(new SensorState(_undoSensor, new DateTime(2011, 8, 12),
                                            new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 66.77f } }, null));
            _undoSensor.AddState(new SensorState(_undoSensor, new DateTime(2011, 8, 12),
                                new Dictionary<DateTime, float> { { new DateTime(2011, 8, 12), 64.77f } }, null));

            _undoSensor.Undo();
            _undoSensor.Undo();

            Assert.AreEqual(2, _undoSensor.RedoStates.Count);
            Assert.AreEqual(0, _undoSensor.UndoStates.Count);

            _undoSensor.Redo();
            _undoSensor.Redo();

            Assert.AreEqual(0, _undoSensor.RedoStates.Count);
            Assert.AreEqual(2, _undoSensor.UndoStates.Count);
        }
示例#29
0
 public void UpperLimitLessThanLowerLimit()
 {
     var s = new Sensor("Awesome Sensor", "An awesome sensor", 10, 100, "A", 2, _ds);
 }
示例#30
0
        public void ValidUndoStatesAfterRedo()
        {
            var redoSensor = new Sensor("Temperature", "C");

            var correctStackItem = new SensorState(redoSensor, new DateTime(2011, 7, 5, 22, 47, 0), new Dictionary<DateTime, float> { { new DateTime(2010, 5, 5, 22, 00, 0), 22.5f }, { new DateTime(2010, 5, 5, 22, 15, 0), 21.4f }, { new DateTime(2010, 5, 5, 22, 30, 0), 22.0f } }, null);
            var correctStackItemTwo = new SensorState(redoSensor, new DateTime(2011, 7, 9, 22, 47, 0), new Dictionary<DateTime, float> { { new DateTime(2010, 5, 5, 22, 00, 0), 22.5f }, { new DateTime(2010, 5, 5, 22, 15, 0), 21.4f }, { new DateTime(2010, 5, 5, 22, 30, 0), 22.0f } }, null);

            redoSensor.AddState(correctStackItem);
            redoSensor.AddState(correctStackItemTwo);

            redoSensor.Undo();

            Assert.AreEqual(correctStackItem, redoSensor.CurrentState);

            redoSensor.Redo();

            Assert.AreEqual(1, redoSensor.UndoStates.Count);
        }