Пример #1
0
        public void TooLongArray()
        {
            var input = new byte[byte.MaxValue + 1];
            var sut   = new CountingSort(11);

            Assert.Throws <ArgumentOutOfRangeException>(() => sut.Sort(input));
        }
Пример #2
0
        public void ArrayOfReverseOrderValues()
        {
            var input  = OrderedArray.Reverse().ToArray();
            var sut    = new CountingSort(11);
            var result = sut.Sort(input);

            Assert.Equal(OrderedArray, result);
        }
Пример #3
0
        public void ArrayOfOrderedValues()
        {
            var input  = OrderedArray;
            var sut    = new CountingSort(11);
            var result = sut.Sort(input);

            Assert.Equal(OrderedArray, result);
        }
Пример #4
0
        public void ArrayOfOnes()
        {
            var input  = Enumerable.Repeat((byte)1, 11).ToArray();
            var sut    = new CountingSort(11);
            var result = sut.Sort(input);

            Assert.Equal(input, result);
        }
Пример #5
0
        public void ArrayWithManyBigValues()
        {
            var random   = new Random(12345);
            var input    = Enumerable.Repeat((byte)255, 255).ToArray();
            var expected = (byte[])input.Clone();

            Array.Sort(expected);

            var sut    = new CountingSort(255);
            var result = sut.Sort(input);

            Assert.Equal(expected, result);
        }
Пример #6
0
        public void ArrayWithDuplicatedValues()
        {
            var random   = new Random(12345);
            var input    = new byte[] { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6 };
            var expected = (byte[])input.Clone();

            Array.Sort(expected);

            var sut    = new CountingSort(11);
            var result = sut.Sort(input);

            Assert.Equal(expected, result);
        }
Пример #7
0
        public void ArrayOfRandomValues()
        {
            var random = new Random(12345);
            var input  = new byte[255];

            random.NextBytes(input);
            var expected = (byte[])input.Clone();

            Array.Sort(expected);

            var sut    = new CountingSort(byte.MaxValue);
            var result = sut.Sort(input);

            Assert.Equal(expected, result);
        }
Пример #8
0
        public void PerformanceTest(int numOfPasses)
        {
            var random = new Random(12345);
            var input  = new byte[11];

            random.NextBytes(input);

            this.output.WriteLine("Counting sort...");
            using (new MeassureTime(this.output))
            {
                for (int i = 0; i < numOfPasses; i++)
                {
                    var counting = new CountingSort(byte.MaxValue);
                    counting.Sort((byte[])input.Clone());
                }
            }
        }