Пример #1
0
        public void ReverseOddInt()
        {
            List <int> array = new List <int> {
                1, 2, 3
            };

            _reverseService.Reverse(array);

            Assert.AreEqual(3, array[0]);
            Assert.AreEqual(2, array[1]);
            Assert.AreEqual(1, array[2]);
        }
Пример #2
0
        static void Main()
        {
            int length;

            string[]       array;
            ReverseService reverseService = new ReverseService();

            while (true)
            {
                Console.WriteLine("Please enter length of array");
                Int32.TryParse(Console.ReadLine(), out length);
                if (length > 0)
                {
                    break;
                }
            }

            while (true)
            {
                Console.WriteLine("Please enter the array - separate elements using spaces");

                array = Console.ReadLine().Split(" ");
                //There was no requirement about the type of elements.
                //Hence, the assumption that empty elements are ok.
                if (array.Length != length)
                {
                    Console.WriteLine("The provided length in not equal to the given array");
                }
                else
                {
                    break;
                }
            }

            reverseService.Reverse(array);

            //String.Join will not perform the best from memory performance point of view.
            //It could be just a loop with Console.Write for better memory performance.
            //However, with String.Join the readability is better.
            Console.WriteLine(String.Join(" ", array));

            Console.Read();
        }
        public void ReverseService_ReversesString()
        {
            // Arrange

            var actual = default(string);

            var input    = "foo bar";
            var expected = "rab oof";

            // Act

            using (var service = new ReverseService())
            {
                actual = service.Reverse(input);
            }

            // Asset

            Assert.Equal(expected, actual);
        }