예제 #1
0
 public void TestCyclicRotation()
 {
     Assert.AreEqual(string.Join(",", CyclicRotation.Solution(new int[] { 1, 2, 3, 4, 5 }, 2)), "4,5,1,2,3");
     Assert.AreEqual(string.Join(",", CyclicRotation.Solution(new int[] { 1, 2, 3, 4, 5 }, 0)), "1,2,3,4,5");
     Assert.AreEqual(string.Join(",", CyclicRotation.Solution(new int[] { 1 }, 4)), "1");
     Assert.AreEqual(string.Join(",", CyclicRotation.Solution(new int[] { }, 2)), "");
 }
예제 #2
0
        public void CyclicRotationSolutionTestWith1Rotation()
        {
            CyclicRotation testRotation = new CyclicRotation();

            int[] arrayTest = new int[] { 0, 0, 0 };
            int[] result    = new int[] { 0, 0, 0 };
            Assert.IsTrue(result.SequenceEqual(testRotation.Solution(arrayTest, 1)));
        }
예제 #3
0
        public void CyclicRotationSolutionTestWithNegativeValues()
        {
            CyclicRotation testRotation = new CyclicRotation();

            int[] arrayTest = new int[] { 1, -2, 3, -4 };
            int[] result    = new int[] { 1, -2, 3, -4 };
            Assert.IsTrue(result.SequenceEqual(testRotation.Solution(arrayTest, 4)));
        }
예제 #4
0
        public void CyclicRotationSolutionTest()
        {
            CyclicRotation testRotation = new CyclicRotation();

            int[] arrayTest = new int[] { 3, 8, 9, 7, 6 };
            int[] result    = new int[] { 9, 7, 6, 3, 8 };
            Assert.IsTrue(result.SequenceEqual(testRotation.Solution(arrayTest, 3)));
        }
예제 #5
0
        public void TestMethod1()
        {
            int moves = 3;

            int[] input    = { 3, 8, 9, 7, 6 };
            int[] expected = { 9, 7, 6, 3, 8 };
            int[] result   = CyclicRotation.Solution(input, moves);

            CollectionAssert.AreEqual(expected, result);
        }
예제 #6
0
        public void TestMethod3()
        {
            int moves = 4;

            int[] input    = { 1, 2, 3, 4 };
            int[] expected = { 1, 2, 3, 4 };
            int[] result   = CyclicRotation.Solution(input, moves);

            CollectionAssert.AreEqual(expected, result);
        }
예제 #7
0
        public void when_num_is_negative_should_return_same()
        {
            // Arrange
            var input  = new int[] { 1, 2, 3, 4 };
            var output = new int[] { 1, 2, 3, 4 };
            //Act
            var result = CyclicRotation.Solution(input, -1);

            //Assert
            CollectionAssert.AreEqual(result, output);
        }
예제 #8
0
        public void when_k_is_greater_than_n()
        {
            // Arrange
            var input  = new int[] { 1, 1, 2, 3, 5 };
            var output = new int[] { 3, 5, 1, 1, 2 };
            //Act
            var result = CyclicRotation.Solution(input, 42);

            //Assert
            CollectionAssert.AreEqual(result, output);
        }
예제 #9
0
        public void when_array_is_empty()
        {
            // Arrange
            var input  = new int[] { };
            var output = new int[] { };
            //Act
            var result = CyclicRotation.Solution(input, 1);

            //Assert
            CollectionAssert.AreEqual(result, output);
        }
예제 #10
0
        public void test_CyclicRotation_small()
        {
            // Arrange
            var input  = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var output = new int[] { 6, 7, 1, 2, 3, 4, 5 };
            //Act
            var result = CyclicRotation.Solution(input, 2);

            //Assert
            CollectionAssert.AreEqual(result, output);
        }
예제 #11
0
        public void test_CyclicRotation_double()
        {
            // Arrange
            var input  = new int[] { 5, -1000 };
            var output = new int[] { -1000, 5 };
            //Act
            var result = CyclicRotation.Solution(input, 1);

            //Assert
            CollectionAssert.AreEqual(result, output);
        }
예제 #12
0
        public void test_CyclicRotation_by_three()
        {
            // Arrange
            var input  = new int[] { 3, 8, 9, 7, 6 };
            var output = new int[] { 9, 7, 6, 3, 8 };
            //Act
            var result = CyclicRotation.Solution(input, 3);

            //Assert
            CollectionAssert.AreEqual(result, output);
        }
        public void SolutionTest_04()
        {
            var solution = new CyclicRotation();

            int[] A = new int[] { 3, 8, 9, 7, 6 };
            int   K = 3;

            int[] expected = new int[] { 9, 7, 6, 3, 8 };
            int[] actual   = solution.Solution(A, K);
            Assert.AreEqual(expected, actual);
        }
예제 #14
0
        public void when_array_is_same_number_return_same()
        {
            // Arrange
            var input  = new int[] { 0, 0, 0 };
            var output = new int[] { 0, 0, 0 };
            //Act
            var result = CyclicRotation.Solution(input, 1);

            //Assert
            CollectionAssert.AreEqual(result, output);
        }
예제 #15
0
        public void Solution_SmallNumbers_Corect()
        {
            //Arrange - Given
            var array     = new int[] { 1, 2, 3, 4 };
            var rotations = 2;

            //Act - When
            var result = CyclicRotation.Solution(array, rotations);

            //Assert - Then
            var expectedResult = new int[] { 3, 4, 1, 2 };

            Assert.Equal(expectedResult, result);
        }
예제 #16
0
        public void SimpleRotations()
        {
            //Arrange
            var CyclicRotationSolver = new CyclicRotation();
            //Act
            var TestArray    = new int[] { 3, 8, 9, 7, 6 };
            var RotatedArray = new int[] { 9, 7, 6, 3, 8 };
            var rotation     = 3;

            //Test
            var rotationResult = CyclicRotationSolver.Solution(TestArray, rotation);

            Assert.AreEqual(rotationResult.Length, RotatedArray.Length);
            for (int i = 0; i < rotationResult.Length; i++)
            {
                Assert.AreEqual(rotationResult[i], RotatedArray[i]);
            }
        }
예제 #17
0
        public void TwoElements()
        {
            //Arrange
            var CyclicRotationSolver = new CyclicRotation();
            //Act
            var TestArray    = new int[] { 5, -1000 };
            var RotatedArray = new int[] { -1000, 5 };
            var rotation     = 1;

            //Test
            var rotationResult = CyclicRotationSolver.Solution(TestArray, rotation);

            Assert.AreEqual(rotationResult.Length, RotatedArray.Length);
            for (int i = 0; i < rotationResult.Length; i++)
            {
                Assert.AreEqual(rotationResult[i], RotatedArray[i]);
            }
        }
예제 #18
0
        static void Main(string[] args)
        {
            Console.WriteLine($"BinaryGap is {BinaryGap.Solution(9)}");
            Console.WriteLine($"BinaryGap is {BinaryGap.Solution(529)}");
            Console.WriteLine($"BinaryGap is {BinaryGap.Solution(20)}");
            Console.WriteLine($"BinaryGap is {BinaryGap.Solution(15)}");
            Console.WriteLine($"BinaryGap is {BinaryGap.Solution(32)}");
            Console.WriteLine($"BinaryGap is {BinaryGap.Solution(1041)}");
            Console.WriteLine(Environment.NewLine);

            var result = CyclicRotation.Solution(new[] { 1, 2, 3, 4 }, 2);

            Console.WriteLine($"CyclicRotation: {string.Join('-', result)}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"OddOccurrencesInArray: {OddOccurrencesInArray.Solution(new[] {1, 1, 2, 2, 3, 4, 4})}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"FrogJmp: {FrogJmp.Solution(10, 85, 30)}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"PermMissingElem: {PermMissingElem.Solution(new[] {6, 7, 8, 1, 2, 4, 5})}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"TapeEquilibrium: {TapeEquilibrium.Solution(new[] {3,1,2,4,3})}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"FrogRiverOne: {FrogRiverOne.Solution(5,new[] {1,3,1,4,2,3,6,5,4})}");
            Console.WriteLine(Environment.NewLine);

            var maxCounter = MaxCounters.Solution(5, new[] { 3, 4, 4, 6, 1, 4, 4 });

            Console.WriteLine($"MaxCounters: {string.Join('-', maxCounter)}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"MissingInteger: {MissingInteger.Solution(new []{1, 3, 6, 4, 1, 2})}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"PermCheck: {PermCheck.Solution(new []{4,1,3,2})}");
            Console.WriteLine($"PermCheck: {PermCheck.Solution(new []{4,1,3})}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"CountDiv: {CountDiv.Solution(11, 345, 17)}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"PassingCars: {PassingCars.Solution(new []{0,1,0,1,1})}");
            Console.WriteLine(Environment.NewLine);

            // Console.WriteLine($"MinAvgTwoSlice: {MinAvgTwoSlice.Solution(new []{4,2,2,5,1,5,8})}");
            // Console.WriteLine(Environment.NewLine);
            //
            Console.WriteLine($"MaxProductOfThree: {MaxProductOfThree.Solution(new []{-3,1,2,-2,5,6})}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"Triangle: {Triangle.Solution(new []{10,2,5,1,8,20})}");
            Console.WriteLine($"Triangle: {Triangle.Solution(new []{10,50,5,1})}");
            Console.WriteLine(Environment.NewLine);

            Console.WriteLine($"Brackets: {Brackets.Solution("{[()()]}")}");
            Console.WriteLine($"Brackets: {Brackets.Solution("([)()]")}");
            Console.WriteLine(Environment.NewLine);
        }
예제 #19
0
 public void CyclicRotation_NoRotation_Success()
 {
     int[] result = CyclicRotation.Solution(new int[] { 1, 2, 3, 4 }, 0);
     CollectionAssert.AreEqual(new int[] { 1, 2, 3, 4 }, result);
 }
예제 #20
0
 public void CyclicRotation_KGreaterN_Success()
 {
     int[] result = CyclicRotation.Solution(new int[] { 1, 2, 3, 4 }, 6);
     CollectionAssert.AreEqual(new int[] { 3, 4, 1, 2 }, result);
 }
        public int[] test(int[] array, int k)
        {
            var cyclicRotation = new CyclicRotation();

            return(cyclicRotation.Solution(array, k));
        }