示例#1
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);
        }
        public void PermMissingElemTest_01()
        {
            var arr    = new int[] { 1, 2, 3, 5 };
            var result = pe.solution(arr);

            Assert.AreEqual(4, 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);
        }
        public void PermMissingElem_Should_Handle_Empty_Array()
        {
            PermMissingElem subject = new PermMissingElem();

            int[] array = { };

            int result = subject.solution(array);

            Assert.Equal(1, result);
        }
        public void PermMissingElem_Should_Process_Single_Values()
        {
            PermMissingElem subject = new PermMissingElem();

            int[] array = { 2 };

            int result = subject.solution(array);

            Assert.Equal(1, result);
        }
        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);
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
        public void PermMissingElemTest_2_3_1_5_Returns4()
        {
            int[] A = { 2, 3, 1, 5 };

            Assert.AreEqual(_pme.solution(A), 4);
        }
示例#10
0
 public void MainTest(int expected, int[] A)
 {
     Assert.Equal(expected, PermMissingElem.solution(A));
 }
示例#11
0
        private void Test(int[] array, int expectedResult)
        {
            var result = _permMissingElem.solution(array);

            Assert.AreEqual(expectedResult, result);
        }