Example #1
0
        public void ArrayReverseSimple()
        {
            var stack = new Stack <ForthDatum>();

            stack.Push(new ForthDatum(new ForthDatum[] {
                new ForthDatum("value0"),
                new ForthDatum("value1"),
            }));

            var local      = stack.ClonePreservingOrder();
            var parameters = new ForthPrimativeParameters(null, local, null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
            var result     = ArrayReverse.Execute(parameters);

            Assert.NotNull(result);
            Assert.IsTrue(result.IsSuccessful, result.Reason);

            var a = local.Pop();

            Assert.AreEqual(ForthDatum.DatumType.Array, a.Type);
            Assert.NotNull(a.Value);
            Assert.IsInstanceOf <string>(a.Value);

            var arr = a.UnwrapArray();

            Assert.NotNull(arr);
            Assert.AreEqual(2, arr.Length);

            Assert.AreEqual(ForthDatum.DatumType.String, arr[0].Type);
            Assert.AreEqual("value1", arr[0].Value);

            Assert.AreEqual(ForthDatum.DatumType.String, arr[1].Type);
            Assert.AreEqual("value0", arr[1].Value);

            Assert.AreEqual(0, local.Count);
        }
Example #2
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);
        }
        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);
        }
        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);
        }
        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);
        }