コード例 #1
0
        public void Test_ArrayReverse()
        {
            var arrayReverse = new ArrayReverse();

            var result   = arrayReverse.ReverseArray(new[] { 1, 2, 3, 4, 5, 6 }, 0, 5);
            var expected = new[] { 6, 5, 4, 3, 2, 1 };

            Assert.Equal(expected, result);
        }
コード例 #2
0
        public void Can_reverse_empty_array()
        {
            // Arrange
            int[] input = new int[0];

            // Act
            int[] result = ArrayReverse.ReverseArray(input);

            // Assert
            Assert.Empty(result);

            // Not in-place reversal
            Assert.NotSame(input, result);
        }
コード例 #3
0
        public void Can_reverse_array_of_numbers(int[] input, int[] expected)
        {
            // Arrange
            // from input

            // Act
            int[] result = ArrayReverse.ReverseArray(input);

            // Assert
            Assert.Equal(expected, result);

            // Not in-place reversal
            Assert.NotSame(input, result);
        }
コード例 #4
0
        public void Test(int length)
        {
            int[] array = maker.RandomArrayMaker(length);
            Console.WriteLine("\nTest of reverse methods for array with " + length + " values:");
            var timer = Stopwatch.StartNew();

            Array.Reverse(array);
            Console.WriteLine("\n\tMSCoreLib method timing: " + timer.Elapsed.TotalMilliseconds);
            timer.Stop();

            timer.Start();
            ArrayReverse.ReverseArray(array);
            timer.Stop();
            Console.WriteLine("\n\tUser method timing: " + timer.Elapsed.TotalMilliseconds);
        }