Exemplo n.º 1
0
        public void FindShouldReturnMissingElementWhenGivenNonEmptyArray(int[] a, int expected)
        {
            PermMissingElem finder = new PermMissingElem();
            int             actual = finder.Find(a);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
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.º 4
0
        public void PermMissingElemTests(int expected, int[] A)
        {
            PermMissingElem permMissingElem = new PermMissingElem();
            int             answer          = permMissingElem.FindMissingElem(A);

            Assert.Equal(expected, answer);
        }
Exemplo n.º 5
0
        public void ShortArrayMissingFirstElement()
        {
            var permMissingSolver = new PermMissingElem();

            int maxElement = 5;

            int[] entryArray = new int[maxElement - 1];
            for (int i = 1; i < maxElement; i++)
            {
                entryArray[i - 1] = i + 1;
            }

            int solution = permMissingSolver.solution(entryArray);

            Assert.IsTrue(solution == 1);


            maxElement = 1000;
            entryArray = new int[maxElement - 1];
            for (int i = 1; i < maxElement; i++)
            {
                entryArray[i - 1] = i + 1;
            }

            solution = permMissingSolver.solution(entryArray);
            Assert.IsTrue(solution == 1);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void TestMethod1()
        {
            int[] input    = { 2, 3, 1, 5 };
            int   expected = 4;
            int   result   = PermMissingElem.Solution(input);

            Assert.AreEqual(expected, result);
        }
        public void AssertThatSolutionReturnsMissingElementFromArray()
        {
            var target   = new PermMissingElem();
            var given    = new[] { 2, 3, 1, 5 };
            var actual   = target.solution(given);
            var expected = 4;

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void PermMissingElem_Should_Process_Single_Values()
        {
            PermMissingElem subject = new PermMissingElem();

            int[] array = { 2 };

            int result = subject.solution(array);

            Assert.Equal(1, result);
        }
Exemplo n.º 10
0
        public void PermMissingElem_Should_Handle_Empty_Array()
        {
            PermMissingElem subject = new PermMissingElem();

            int[] array = { };

            int result = subject.solution(array);

            Assert.Equal(1, 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.º 12
0
        public void PermMissingElem_Should_Process_Complex_Values()
        {
            PermMissingElem subject = new PermMissingElem();

            int[] array = { 2,   3,  1,  5,  4,  6,  7,  8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                            21, 23, 24, 25, 26, 27, 28, 29, 30 };

            int result = subject.solution(array);

            Assert.Equal(22, result);
        }
Exemplo n.º 13
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.º 15
0
        public void LongArrayTest()
        {
            int maxElement = 100000;

            int[] entryArray = new int[maxElement - 1];
            for (int i = 1; i < maxElement; i++)
            {
                entryArray[i - 1] = i + 1;
            }

            var permMissingSolver = new PermMissingElem();
            int solution          = permMissingSolver.solution(entryArray);

            Assert.AreEqual(solution, 1);
        }
Exemplo n.º 16
0
        public void PermMissingElemSolutionTest()
        {
            var missingElement = new PermMissingElem();

            //N = 4
            int[] array  = new int[] { 2, 3, 1, 5 };
            int   result = missingElement.Solve(array);

            Assert.AreEqual(4, result);

            //N = 1
            array  = new int[] { 2 };
            result = missingElement.Solve(array);
            Assert.AreEqual(1, result);
        }
Exemplo n.º 17
0
        public void ShortArrayMissingRandomElement()
        {
            var permMissingSolver = new PermMissingElem();

            int        maxElement = 100;
            List <int> entryArray = new List <int>();

            for (int i = 0; i < maxElement; i++)
            {
                entryArray.Add(i + 1);
            }

            var rnd = new Random();
            int randomMissingElement = rnd.Next(1, maxElement);

            entryArray.RemoveAt(randomMissingElement - 1);

            int solution = permMissingSolver.solution(entryArray.ToArray());

            Assert.AreEqual(solution, randomMissingElement);
        }
Exemplo n.º 18
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.º 19
0
 public void PermMissingElem_EmptyArray_Success()
 {
     Assert.AreEqual(1, PermMissingElem.Solution(new int[] { }));
 }
Exemplo n.º 20
0
 public void PermMissingElem_LastElem_Success()
 {
     Assert.AreEqual(4, PermMissingElem.Solution(new int[] { 2, 1, 3 }));
 }
Exemplo n.º 21
0
 public void PermMissingElem_FirstElem_Success()
 {
     Assert.AreEqual(1, PermMissingElem.Solution(new int[] { 2, 4, 3 }));
 }
Exemplo n.º 22
0
 public void PermMissingElem_SmallArray_Success()
 {
     Assert.AreEqual(3, PermMissingElem.Solution(new int[] { 2, 1, 4 }));
 }
Exemplo n.º 23
0
 public void PermMissingElem_OneElem_Success()
 {
     Assert.AreEqual(1, PermMissingElem.Solution(new int[] { 2 }));
 }
Exemplo n.º 24
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);
        }
 public PermMissingElemTests()
 {
     permMissingElem = new PermMissingElem();
 }
Exemplo n.º 26
0
 public PermMissingElemTest()
 {
     _pme = new PermMissingElem();
 }
Exemplo n.º 27
0
 public void MainTest(int expected, int[] A)
 {
     Assert.Equal(expected, PermMissingElem.solution(A));
 }
Exemplo n.º 28
0
        public void PermMissingElem()
        {
            var test = new PermMissingElem();

            test.Run();
        }
Exemplo n.º 29
0
 public void Initialize()
 {
     _permMissingElem = new PermMissingElem();
 }
Exemplo n.º 30
0
 public void TestPermMissingElem()
 {
     Assert.AreEqual(PermMissingElem.Solution(new int[] { 2, 3, 5, 4 }), 1);
     Assert.AreEqual(PermMissingElem.Solution(new int[] { 2 }), 1);
 }