Exemplo n.º 1
0
        public void PermMissingElemSolutionTest()
        {
            PermMissingElem permMissingElem = new PermMissingElem();

            int[] arrayTest = new int[] { 2, 3, 1, 5 };
            Assert.AreEqual(4, permMissingElem.Solution(arrayTest));
        }
        public void Solution_LargeNumbers_Correct()
        {
            //Arrange - Given
            var maxrange = 10000;
            var array    = new int[maxrange];

            for (int i = 0; i < maxrange; i++)
            {
                array[i] = i + 1;
            }
            Random rnd = new Random();

            var listHere      = new List <int>(array);
            int selectedIndex = rnd.Next(1, maxrange);

            listHere.RemoveAt(selectedIndex);
            array = listHere.ToArray();

            //Act - When
            var result = PermMissingElem.Solution(array);

            //Assert - Then
            var expectedResult = selectedIndex + 1;

            Assert.Equal(expectedResult, result);
        }
Exemplo n.º 3
0
        public void TestMethod1()
        {
            int[] input    = { 2, 3, 1, 5 };
            int   expected = 4;
            int   result   = PermMissingElem.Solution(input);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 4
0
        public void TestMethod2()
        {
            int[] input    = { 8, 9, 4, 3, 1, 5, 2, 6 };
            int   expected = 7;
            int   result   = PermMissingElem.Solution(input);

            Assert.AreEqual(expected, result);
        }
        public void solutionTest_01()
        {
            var solution = new PermMissingElem();

            int[] A        = new int[] { 2, 3, 1, 5 };
            int   expected = 4;
            int   actual   = solution.Solution(A);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void SolutionSimpleEmptyTest()
        {
            // Arrange
            int[] A = new int[] { };

            // Action
            int actual = PermMissingElem.Solution(A);

            // Assert
            int expected = 1;

            Assert.AreEqual(expected, actual);
        }
        public void Solution_SmallNumbers_Correct()
        {
            //Arrange - Given
            var array = new int[] { 2, 3, 1, 5 };

            //Act - When
            var result = PermMissingElem.Solution(array);

            //Assert - Then
            var expectedResult = 4;

            Assert.Equal(expectedResult, result);
        }
Exemplo n.º 8
0
        public void SolutionTest()
        {
            // Arrange
            int N = 100000;

            int[]      A    = new int[N];
            List <int> list = new List <int>();

            for (int i = 0; i < N + 1; i++)
            {
                list.Add(i + 1);
            }

            list.Remove(505);
            A = list.ToArray();

            // Action
            int actual = PermMissingElem.Solution(A);

            // Assert
            int expected = 505;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
 public void PermMissingElem_EmptyArray_Success()
 {
     Assert.AreEqual(1, PermMissingElem.Solution(new int[] { }));
 }
Exemplo n.º 10
0
 public void PermMissingElem_LastElem_Success()
 {
     Assert.AreEqual(4, PermMissingElem.Solution(new int[] { 2, 1, 3 }));
 }
Exemplo n.º 11
0
 public void PermMissingElem_FirstElem_Success()
 {
     Assert.AreEqual(1, PermMissingElem.Solution(new int[] { 2, 4, 3 }));
 }
Exemplo n.º 12
0
 public void PermMissingElem_SmallArray_Success()
 {
     Assert.AreEqual(3, PermMissingElem.Solution(new int[] { 2, 1, 4 }));
 }
Exemplo n.º 13
0
 public void PermMissingElem_OneElem_Success()
 {
     Assert.AreEqual(1, PermMissingElem.Solution(new int[] { 2 }));
 }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
 public void TestPermMissingElem()
 {
     Assert.AreEqual(PermMissingElem.Solution(new int[] { 2, 3, 5, 4 }), 1);
     Assert.AreEqual(PermMissingElem.Solution(new int[] { 2 }), 1);
 }