private static void Main()
    {
        ArrayRotation arDemo = new ArrayRotation();

        arDemo.TakeInput();
        Console.WriteLine(arDemo.CanGetOrder() ? "YES" : "NO");
    }
        public void Rotate_WhenInputArrayIsNull_ThrowArgumentNullException()
        {
            //Arrange
            ArrayRotation arrayRotation = new ArrayRotation();

            //Act
            var output = arrayRotation.Rotate(null, 2);

            //Assert
        }
Esempio n. 3
0
        public void Should_rotate_an_integer_array_n_times()
        {
            var numberOfRotations = 9;
            var originalArray     = new[] { 1, 2, 3, 4, 5, 6 };
            var expectedArray     = new[] { 4, 5, 6, 1, 2, 3 };

            var rotatedArray = ArrayRotation.RotateArray(originalArray, numberOfRotations);

            Assert.AreEqual(expectedArray, rotatedArray);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            int[] array = new int[7] {
                3, 4, 5, 6, 7, 1, 2
            };
            Console.WriteLine("Input Array : " + string.Join("", array));
            ArrayRotation arrayRotation = new ArrayRotation();
            string        rotatingArray = arrayRotation.RotateArray(array);

            Console.WriteLine("Rotating array : " + rotatingArray);
            //Console.ReadLine();
        }
Esempio n. 5
0
 public void Setup()
 {
     _binaryGap          = new BinaryGap();
     _arrayRotation      = new ArrayRotation();
     _unpairedElements   = new UnpairedElements();
     _frogJump           = new FrogJump();
     _permMissingElement = new PermMissingElement();
     _tapeEquilibrium    = new TapeEquilibrium();
     _frogRiverOne       = new FrogRiverOne();
     _maxCounters        = new MaxCounters();
     _missingInteger     = new MissingInteger();
 }
        public void Rotate_WhenInputNumberIsEqualToArrayLength_ThrowsArgumentOutOfRangeException()
        {
            //Arrange
            ArrayRotation arrayRotation = new ArrayRotation();

            int[] inputArray = new int[5] {
                1, 2, 3, 4, 5
            };

            //Act
            var output = arrayRotation.Rotate(inputArray, inputArray.Length);
        }
        public void FindPairWithGivenSum_WhenArrayContainsValidSum_ReturnsTrue()
        {
            //Arrange
            ArrayRotation arrayRotation = new ArrayRotation();

            int[] inputArray = new int[6] {
                11, 15, 6, 8, 9, 10
            };

            //Act
            var output = arrayRotation.FindPairWithGivenSum(inputArray, 19);

            //Assert
            Assert.IsTrue(output);
        }
        public void RearrangeOddWithPrecedingEvenIndex_InputArrayIsSorted_ReturnsInput()
        {
            //Arrange
            ArrayRotation arrayRotation = new ArrayRotation();

            int[] inputArray = new int[5] {
                1, 2, 3, 4, 5
            };

            //Act
            var output = arrayRotation.RearrangeOddWithPrecedingEvenIndex(inputArray);

            //Assert
            Assert.IsTrue(output.Equals(inputArray));
        }
        public void FindPairWithGivenSum_WhenArrayDoesNotContainSum_ReturnsFalse()
        {
            //Arrange
            ArrayRotation arrayRotation = new ArrayRotation();

            int[] inputArray = new int[6] {
                11, 15, 6, 8, 9, 10
            };

            //Act
            var output = arrayRotation.FindPairWithGivenSum(inputArray, 120);

            //Assert
            Assert.IsFalse(output);
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            ArrayRotation arrayRotation = new ArrayRotation();

            int[] inputArray = new int[5] {
                1, 2, 3, 4, 5
            };
            int[] outputArray = arrayRotation.Rotate(inputArray, 2);

            for (int i = 0; i < outputArray.Length; i++)
            {
                Console.Write(outputArray[i].ToString());
                Console.Write("  ");
            }

            Console.ReadKey();
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to programming test!");
            LineSeperator();

            //Generate string in pattern
            string result = StringGenerator.GenerateString(5, 3);

            Console.WriteLine("Result is - " + result);
            LineSeperator();

            //Find Pair in Array whose sum is provided as input
            Console.WriteLine(FindPairInArray.Find(new int[] { 1, 5, 6, 8, 10, 15 }, 20));
            LineSeperator();

            //Linked List: Length Count
            (new LinkedList()).RunProgram();
            LineSeperator();

            //Sort list of dates
            ListExtensions.RunProgram();
            LineSeperator();

            //find non repeating elements from array
            new FindNonRepeatingElementsinArray().Get2NonRepeatingNos(new int[] { 1, 3, 6, 3, 10, 1, 4 }, 1, 3);
            LineSeperator();

            //reverse sentence
            new StringManipulation().ReverseSentence("My name is Arvind Mishra");
            LineSeperator();

            //rotate array
            ArrayRotation.RotateArray();
            LineSeperator();

            //Dart Game Input Test
            var dartThrows = new string[] { "D20", "T20", "T20", "T20", "T10", "1", "D16", "17" };

            int dartScore = (new DartGame()).CalculateScore(dartThrows, out string message);


            Console.WriteLine($"Dart score : {dartScore}, {message}");

            Console.ReadLine();
        }
Esempio n. 12
0
        public void Rotate_WhenValidArrayAndNumberPassed_RotatesArray()
        {
            //Arrange
            ArrayRotation arrayRotation = new ArrayRotation();

            int[] inputArray = new int[5] {
                1, 2, 3, 4, 5
            };
            int[] expectedArray = new int[5] {
                3, 4, 5, 1, 2
            };

            //Act
            var output = arrayRotation.Rotate(inputArray, 2);

            //Assert
            Assert.IsTrue(expectedArray.IsArrayEqual(output));
        }
Esempio n. 13
0
        public void RearrangeOddWithPrecedingEvenIndex_InputArrayIsUnsorted_ReturnsEvenIndexLessThanOddIndex()
        {
            //Arrange
            ArrayRotation arrayRotation = new ArrayRotation();

            int[] inputArray = new int[5] {
                5, 4, 3, 2, 1
            };
            int[] expectedOutput = new int[5] {
                4, 5, 2, 3, 1
            };

            //Act
            var output = arrayRotation.RearrangeOddWithPrecedingEvenIndex(inputArray);

            //Assert
            Assert.IsTrue(output.IsArrayEqual(expectedOutput));
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Select task of Exercise:");
            Console.WriteLine("1.Train:");
            Console.WriteLine("2.CommonElements:");
            Console.WriteLine("3.ZigZag:");
            Console.WriteLine("4.ArrayRotation:");
            Console.WriteLine("5.TopIntegers:");
            Console.WriteLine("6.EqualSum:");
            Console.WriteLine("7.MaxSequenceEquals:");
            Console.WriteLine("8.MagicSum:");
            Console.WriteLine("9.KaminoFactory:");

            Train             train             = new Train();
            CommonElements    commonElements    = new CommonElements();
            ZigZag            zigZag            = new ZigZag();
            ArrayRotation     arrayRotation     = new ArrayRotation();
            TopIntegers       topIntegers       = new TopIntegers();
            EqualSum          equalSum          = new EqualSum();
            MaxSequenceEquals maxSequenceEquals = new MaxSequenceEquals();
            MagicSum          magicSum          = new MagicSum();
            KaminoFactory     kaminoFactory     = new KaminoFactory();


            int switch_on = int.Parse(Console.ReadLine());

            switch (switch_on)
            {
            case 1: train.TaskTrain();
                break;

            case 2: commonElements.TaskCommonElements();
                break;

            case 3: zigZag.TaskZigZag();
                break;

            case 4:
                arrayRotation.TaskArrayRotation();
                break;

            case 5:
                topIntegers.TaskTopIntegers();
                break;

            case 6:
                equalSum.TaskEqualSum();
                break;

            case 7:
                maxSequenceEquals.TaskMaxSequenceEquals();
                break;

            case 8:
                magicSum.TaskMagicSum();
                break;

            case 9:
                kaminoFactory.TaskKaminoFactory();
                break;

            default:
                Console.WriteLine("Exit:");
                break;
            }
        }
Esempio n. 15
0
 public void Init()
 {
     _sut = new ArrayRotation("1 2 3 4 5");
 }