Пример #1
0
        public void ListWithNoGapWillRemainTheSame()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(10, 10),
                new AnnualDecimal(11, 11),
                new AnnualDecimal(12, 12),
                new AnnualDecimal(13, 13),
                new AnnualDecimal(14, 14),
                new AnnualDecimal(15, 15)
            });
            timeSeriesData.FillInGapsWith(year => new AnnualDecimal(year, 55));

            var enumerator = timeSeriesData.GetEnumerator();

            enumerator.Reset();
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(10, 10)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(11, 11)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(12, 12)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(13, 13)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(14, 14)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(15, 15)));
        }
Пример #2
0
        public void GapsAreFilledInAndListSorted()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(10, 99),
                new AnnualDecimal(13, 99),
                new AnnualDecimal(15, 99)
            });
            timeSeriesData.FillInGapsWith(year => new AnnualDecimal(year, 55));

            var enumerator = timeSeriesData.GetEnumerator();

            enumerator.Reset();
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(10, 99)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(11, 55)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(12, 55)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(13, 99)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(14, 55)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(15, 99)));
        }
Пример #3
0
        public void GettingNonExistentYearShouldReturnNull()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(10, null),
                new AnnualDecimal(11, null),
                new AnnualDecimal(12, null),
            });
            Assert.That(timeSeriesData.GetYear(100), Is.Null);
            Assert.That(timeSeriesData.GetYear(10), Is.EqualTo(new AnnualDecimal(10, null)));
            Assert.That(timeSeriesData.GetYear(12), Is.EqualTo(new AnnualDecimal(12, null)));
        }
Пример #4
0
        public void TrimmingAllNullValuesTimeSeriesDataFromTheEnd()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(10, null),
                new AnnualDecimal(11, null),
                new AnnualDecimal(12, null),
                new AnnualDecimal(13, null),
                new AnnualDecimal(14, null),
                new AnnualDecimal(15, null)
            });
            timeSeriesData.TrimNullDataFromTheEnd();
            Assert.That(timeSeriesData.Count, Is.EqualTo(0));
        }
Пример #5
0
        public void ShouldOnlyTrimTheStart()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(10, null),
                new AnnualDecimal(11, null),
                new AnnualDecimal(12, 12),
                new AnnualDecimal(13, 13),
                new AnnualDecimal(14, null),
                new AnnualDecimal(15, null)
            });
            timeSeriesData.TrimNullDataFromTheStart();
            Assert.That(timeSeriesData.Count, Is.EqualTo(4));
            Assert.That(timeSeriesData.GetYear(timeSeriesData.StartYear()), Is.EqualTo(new AnnualDecimal(12, 12)));
            Assert.That(timeSeriesData.GetYear(timeSeriesData.EndYear()), Is.EqualTo(new AnnualDecimal(15, null)));
        }
Пример #6
0
        public void ShouldNotRemoveNullValuesFromTheMiddle()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(10, 10),
                new AnnualDecimal(11, null),
                new AnnualDecimal(12, null),
                new AnnualDecimal(13, null),
                new AnnualDecimal(14, null),
                new AnnualDecimal(15, 15)
            });
            timeSeriesData.TrimNullData();
            Assert.That(timeSeriesData.Count, Is.EqualTo(6));
            Assert.That(timeSeriesData.GetYear(timeSeriesData.StartYear()), Is.EqualTo(new AnnualDecimal(10, 10)));
            Assert.That(timeSeriesData.GetYear(timeSeriesData.EndYear()), Is.EqualTo(new AnnualDecimal(15, 15)));
        }
Пример #7
0
        public void TrimmedNonNullDataWillReturnTheSameTimeSeries()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(10, 10),
                new AnnualDecimal(11, 11),
                new AnnualDecimal(12, 12),
                new AnnualDecimal(13, 13),
                new AnnualDecimal(14, 14),
                new AnnualDecimal(15, 15)
            });
            timeSeriesData.TrimNullData();
            Assert.That(timeSeriesData.Count, Is.EqualTo(6));
            Assert.That(timeSeriesData.GetYear(timeSeriesData.StartYear()), Is.EqualTo(new AnnualDecimal(10, 10)));
            Assert.That(timeSeriesData.GetYear(timeSeriesData.EndYear()), Is.EqualTo(new AnnualDecimal(15, 15)));
        }
Пример #8
0
        public void DataIsSortedAfterAddingRange()
        {
            var timeSeriesData = new TimeSeriesData <AnnualDecimal>();

            timeSeriesData.AddRange(new[]
            {
                new AnnualDecimal(30, 3),
                new AnnualDecimal(10, 1),
                new AnnualDecimal(40, 4),
                new AnnualDecimal(20, 2)
            });

            var enumerator = timeSeriesData.GetEnumerator();

            enumerator.Reset();
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(10, 1)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(20, 2)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(30, 3)));
            enumerator.MoveNext();
            Assert.That(enumerator.Current, Is.EqualTo(new AnnualDecimal(40, 4)));
        }