public void Sort_intintIComparer_NegativeRange_ThrowsArgumentOutOfRangeException(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            Tuple <int, int>[] InvalidParameters = new Tuple <int, int>[]
            {
                Tuple.Create(-1, -1),
                Tuple.Create(-1, 0),
                Tuple.Create(-1, 1),
                Tuple.Create(-1, 2),
                Tuple.Create(-2, 0),
                Tuple.Create(int.MinValue, 0),
                Tuple.Create(0, -1),
                Tuple.Create(0, -2),
                Tuple.Create(0, int.MinValue),
                Tuple.Create(1, -1),
                Tuple.Create(2, -1),
            };

            Assert.All(
                InvalidParameters,
                invalidSet =>
            {
                Assert.Throws <ArgumentOutOfRangeException>(
                    () => list.Sort(invalidSet.Item1, invalidSet.Item2, GetIComparer())
                    );
            }
                );
        }
        public void Sort_IComparer_WithoutDuplicates(int count)
        {
            SegmentedList <T> list     = GenericListFactory(count);
            IComparer <T>     comparer = GetIComparer();

            list.Sort(comparer);
            Assert.All(Enumerable.Range(0, count - 2), i =>
            {
                Assert.True(comparer.Compare(list[i], list[i + 1]) < 0);
            });
        }
        public void BinarySearch_Validations(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            list.Sort();
            T element = CreateT(3215);

            Assert.Throws <ArgumentException>(null, () => list.BinarySearch(0, count + 1, element, GetIComparer()));     //"Finding items longer than array should throw ArgumentException"
            Assert.Throws <ArgumentOutOfRangeException>(() => list.BinarySearch(-1, count, element, GetIComparer()));    //"ArgumentOutOfRangeException should be thrown on negative index."
            Assert.Throws <ArgumentOutOfRangeException>(() => list.BinarySearch(0, -1, element, GetIComparer()));        //"ArgumentOutOfRangeException should be thrown on negative count."
            Assert.Throws <ArgumentException>(null, () => list.BinarySearch(count + 1, count, element, GetIComparer())); //"ArgumentException should be thrown on index greater than length of array."
        }
        public void Sort_Comparison_WithoutDuplicates(int count)
        {
            SegmentedList <T> list      = GenericListFactory(count);
            IComparer <T>     iComparer = GetIComparer();
            Comparison <T>    comparer  = ((T first, T second) => { return(iComparer.Compare(first, second)); });

            list.Sort(comparer);
            Assert.All(Enumerable.Range(0, count - 2), i =>
            {
                Assert.True(iComparer.Compare(list[i], list[i + 1]) < 0);
            });
        }
        public void Sort_WithDuplicates(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            list.Add(list[0]);
            IComparer <T> comparer = Comparer <T> .Default;

            list.Sort();
            Assert.All(Enumerable.Range(0, count - 2), i =>
            {
                Assert.True(comparer.Compare(list[i], list[i + 1]) <= 0);
            });
        }
        public void Sort_intintIComparer_InvalidRange_ThrowsArgumentException(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            Tuple <int, int>[] InvalidParameters = new Tuple <int, int>[]
            {
                Tuple.Create(count, 1),
                Tuple.Create(count + 1, 0),
                Tuple.Create(int.MaxValue, 0),
            };

            Assert.All(InvalidParameters, invalidSet =>
            {
                Assert.Throws <ArgumentException>(null, () => list.Sort(invalidSet.Item1, invalidSet.Item2, GetIComparer()));
            });
        }
        public void BinarySearch_ForEveryItemWithDuplicates(int count)
        {
            if (count > 0)
            {
                SegmentedList <T> list = GenericListFactory(count);
                list.Add(list[0]);
                list.Sort();
                SegmentedList <T> beforeList = list.ToSegmentedList();

                Assert.All(Enumerable.Range(0, list.Count), index =>
                {
                    Assert.True(list.BinarySearch(beforeList[index]) >= 0);
                    Assert.True(list.BinarySearch(beforeList[index], GetIComparer()) >= 0);
                    Assert.Equal(beforeList[index], list[index]);
                });
            }
        }
        public void Sort_intintIComparer_WithoutDuplicates(int count)
        {
            SegmentedList <T> unsortedList = GenericListFactory(count);
            IComparer <T>     comparer     = GetIComparer();

            for (int startIndex = 0; startIndex < count - 2; startIndex++)
            {
                for (int sortCount = 1; sortCount < count - startIndex; sortCount++)
                {
                    SegmentedList <T> list = new SegmentedList <T>(unsortedList);
                    list.Sort(startIndex, sortCount + 1, comparer);
                    for (int i = startIndex; i < sortCount; i++)
                    {
                        Assert.InRange(comparer.Compare(list[i], list[i + 1]), int.MinValue, 0);
                    }
                }
            }
        }
        public void BinarySearch_ForEveryItemWithoutDuplicates(int count)
        {
            SegmentedList <T> list = GenericListFactory(count);

            foreach (T item in list)
            {
                while (list.Count((value) => value.Equals(item)) > 1)
                {
                    list.Remove(item);
                }
            }
            list.Sort();
            SegmentedList <T> beforeList = list.ToSegmentedList();

            Assert.All(Enumerable.Range(0, list.Count), index =>
            {
                Assert.Equal(index, list.BinarySearch(beforeList[index]));
                Assert.Equal(index, list.BinarySearch(beforeList[index], GetIComparer()));
                Assert.Equal(beforeList[index], list[index]);
            });
        }
Beispiel #10
0
        public Statistics(IEnumerable <double> values)
        {
            var sortedValues = new SegmentedList <double>(values.Where(d => !double.IsNaN(d)));

            sortedValues.Sort();
            if (sortedValues.Count < 1)
            {
                return;
            }

            var quartiles = Quartiles.FromSorted(sortedValues);

            Min    = quartiles.Min;
            Q1     = quartiles.Q1;
            Median = quartiles.Median;
            Q3     = quartiles.Q3;
            Max    = quartiles.Max;

            Mean = sortedValues.Average();

            var tukey = TukeyOutlierDetector.FromQuartiles(quartiles);

            LowerFence = tukey.LowerFence;
            UpperFence = tukey.UpperFence;

            P0   = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.0);
            P25  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.25);
            P50  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.50);
            P67  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.67);
            P80  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.80);
            P85  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.85);
            P90  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.90);
            P95  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.95);
            P99  = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 0.99);
            P100 = SimpleQuantileEstimator.Instance.GetQuantileFromSorted(sortedValues, 1.00);
        }