public void ShouldPickUpSame()
            {
                var date = new DateTime(2012, 06, 06);

                var cache = new MonitorRecordComparison<double> { TimeStamp = date };

                Assert.Equal(0, cache.CompareTo(new MonitorRecord<double>(date, 1)));
            }
            public void ShouldReturnNotNullInstances()
            {
                var cache = new MonitorRecordComparison<double>(10);

                Assert.Equal(1, cache.Number);
                Assert.Equal(DateTime.Now.Date, cache.TimeStamp.Date);
                Assert.Equal(10, cache.Value);
            }
        private void ProcessResult(long reduceResolution, DateTime lastPredictionTime, IList<MonitorRecord<double>> reducedOrdered, IDictionary<long, MonitorRecordComparison<double>> expectedValues)
        {
            var halfResolution = TimeSpan.FromMilliseconds((long)(reduceResolution / 2));

            //If we have some data to be reduced, reduece it down
            if (reducedOrdered.Count > 0)
            {
                //Loop through and index each to-be-reduced item
                var updates = new Dictionary<long, MonitorRecord<double>>(reducedOrdered.Count);
                foreach (var update in reducedOrdered)
                    updates.Add(update.TimeStamp.Ticks - halfResolution.Ticks, update);

                //Going between the first date we have and the last date plus 7 days we loop around.
                //The loop increments on what ever the resolution we have for the ReductionLevel provided.
                //Then for each value in the loop we go backwards in time a week at a time for 4 weeks.
                //For each of these weeks we look to see if there is a week in the list passed in that
                //matches. This results in us coming up with the dates in the future that the data for a
                //given input date should be used for.

                //This is a seems like a really inefficient way of doing this... as in really really bad.
                //There has to be a better way of doing this. Don't want to change at the moment until the
                //test coverage gets up and I know we aren't breaking anything
                var startTime = lastPredictionTime == Constant.MinDbDateTime ? Support.RoundToResolution(reducedOrdered.Last().TimeStamp, reduceResolution) : lastPredictionTime;
                var endTime = reducedOrdered.Last().TimeStamp.AddDays(7);
                for (var currentTime = startTime; currentTime.Ticks < endTime.Ticks; currentTime = currentTime.AddTicks(reduceResolution * Constant.TicksInMillisecond))
                {
                    var samples = new List<MonitorRecord<double>>();

                    //Starts going backwards in time a week at a time for the number of weeks described
                    for (var i = 0; i < WeeksHistory; ++i)
                    {
                        var timeIndex = currentTime.AddTicks(-(i + 1)*TimeSpan.FromDays(7).Ticks).Ticks;

                        MonitorRecord<double> sample;
                        if (updates.TryGetValue(timeIndex, out sample))
                            samples.Add(sample);
                    }

                    // ReduceMethodAverage the samples
                    if (samples.Count > 0)
                    {
                        long count = 0;
                        double sum = 0;
                        foreach (var sample in samples)
                        {
                            count += sample.Number;
                            sum += sample.Value * sample.Number;
                        }

                        var mean = sum/count;
                        var expectedValue = new MonitorRecordComparison<double> { TimeStamp = currentTime + halfResolution, Value = mean, Number = (int)count };

                        expectedValues.Add(expectedValue.TimeStamp.Ticks, expectedValue);
                    }
                }
            }
        }
            public void ShouldPickUpLower()
            {
                var cache = new MonitorRecordComparison<double> { TimeStamp = new DateTime(2012, 06, 06) };

                Assert.Equal(1, cache.CompareTo(new MonitorRecord<double>(new DateTime(2012, 06, 05), 1)));
            }