Ejemplo n.º 1
0
        public void TapeEquilibriumSolutionTest()
        {
            TapeEquilibrium testTape = new TapeEquilibrium();

            int[] arrayTest = new int[] { 3, 1, 2, 4, 3 };
            Assert.AreEqual(1, testTape.Solution(arrayTest));
        }
Ejemplo n.º 2
0
    public static void Test()
    {
        var A = new int[] { 1, 3, 4, 7, 9, -4000 };
        var R = new TapeEquilibrium().Solution(A);

        Console.WriteLine("Result: " + R);
    }
Ejemplo n.º 3
0
        public void Test()
        {
            TapeEquilibrium tape = new TapeEquilibrium();

            int[] A   = { 3, 1, 2, 4, 3 };
            int   min = tape.solution(A);

            Assert.AreEqual(1, min);

            int[] A2 = { 1, 1, 1, 1, 1 };
            min = tape.solution(A2);
            Assert.AreEqual(1, min);

            int[] A3 = { 1, 1, 1, 1, 1, 1 };
            min = tape.solution(A3);
            Assert.AreEqual(0, min);

            int[] A4 = { 20, 30 };
            min = tape.solution(A4);
            Assert.AreEqual(10, min);

            int[] A5 = { 20 };
            min = tape.solution(A5);
            Assert.AreEqual(20, min);
        }
        public void Tests(int[] data, int expected)
        {
            TapeEquilibrium tp     = new TapeEquilibrium();
            var             result = tp.Solution(data, data.Length);

            Assert.AreEqual(expected, result);
        }
        public void MinimizeShouldReturnMinimalDiferenceWhenGivenNonEmptyArray(int[] a, int expected)
        {
            TapeEquilibrium minimizer = new TapeEquilibrium();
            int             actual    = minimizer.Minimize(a);

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

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 7
0
        public void TestMethod1()
        {
            int[] input    = { 3, 1, 2, 4, 3 };
            int   expected = 1;
            int   result   = TapeEquilibrium.Solution(input);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 8
0
        public void TapeEquilibriumSolutionTest()
        {
            var tape = new TapeEquilibrium();

            int[] array  = new int[] { 3, 1, 2, 4, 3 };
            int   result = tape.Solve(array);

            Assert.AreEqual(1, result);
        }
Ejemplo n.º 9
0
 static void Main(string[] args)
 {
     BinaryGap.Test();
     CyclicRotation.Test();
     OddOccurrencesInArray.Test();
     TapeEquilibrium.Test();
     PermCheck.Test();
     FrogRiverOne.Test();
     MissingInteger.Test();
 }
Ejemplo n.º 10
0
        public void SolutionTest()
        {
            var solution = new TapeEquilibrium();

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

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void TapeEquilibrium_Should_Process_Complex_Array()
        {
            TapeEquilibrium subject = new TapeEquilibrium();

            int[] array = { 1000, 500, 3, 5, -1000 };

            int result = subject.solution(array);

            Assert.Equal(1492, result);
        }
Ejemplo n.º 12
0
        public void TapeEquilibrium_Should_Process_MaxNumbers_Array()
        {
            TapeEquilibrium subject = new TapeEquilibrium();

            int[] array = { -1000, 1000 };

            int result = subject.solution(array);

            Assert.Equal(2000, result);
        }
Ejemplo n.º 13
0
        public void TapeEquilibrium_Should_Handle_Empty_Array()
        {
            TapeEquilibrium subject = new TapeEquilibrium();

            int[] array = {};

            int result = subject.solution(array);

            Assert.Equal(0, result);
        }
Ejemplo n.º 14
0
        public void TapeEquilibrium_Should_Process_Negative_Array()
        {
            TapeEquilibrium subject = new TapeEquilibrium();

            int[] array = { -3, -1, -2, -4, -3 };

            int result = subject.solution(array);

            Assert.Equal(1, result);
        }
Ejemplo n.º 15
0
        public void TapeEquilibrium_Should_Process_Simple_Array()
        {
            TapeEquilibrium subject = new TapeEquilibrium();

            int[] array = { 3, 1, 2, 4, 3 };

            int result = subject.solution(array);

            Assert.Equal(1, result);
        }
Ejemplo n.º 16
0
        public void TestShortTapeSample()
        {
            var        tapeEquilibriumSolver = new TapeEquilibrium();
            List <int> entryArray            = new List <int>()
            {
                3, 1, 2, 4, 3
            };

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

            Assert.AreEqual(solution, 1);
        }
Ejemplo n.º 17
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();
 }
Ejemplo n.º 18
0
        public void Solution_SmallNumbers_Correct()
        {
            //Arrange - Given
            var array = new int[] { 3, 1, 2, 4, 3 };

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

            //Assert - Then
            var expectedResult = 1;

            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            /// CodeWars
            //Vasya_Clerk.Run();

            /// Codility Lessons
            //BinaryGap.Run();
            //CyclicRotation.Run();
            //OddOccurrencesInArray.Run();
            //FrogJmp.Run();
            //PermMissingElem.Run();
            TapeEquilibrium.Run();


            /// LEETCODE CONTEST
            //FindTheDifference_389.Run();
            //EliminationGame_390.Run();
            //WiggleSequence_376.Run();

            /// STRINGS
            //FindDuplicateLetters.Run();
            //StringReverse.Run();
            //StringPermutations.Run();

            /// Math

            /*
             * ArmstrongNumbers.Run();
             * CalculateFactorial.Run();
             * FibonacciRun.Run();
             * StandardDeviation.Run();
             * IsPrime.Run();
             */

            /// PYRAMIDS

            /*
             * Pyramid01.Run();
             * Pyramid02.Run();
             * Pyramid03.Run();
             * Pyramid04.Run();
             * Pyramid05.Run();
             */

            /// SEARCH

            /*
             * LinearSearch.Run();
             * BinarySearch.Run();
             */
        }
Ejemplo n.º 20
0
        public void Case01()
        {
            // Arrange
            var algorithm = new TapeEquilibrium();
            var A         = new int[] { 3, 1, 2, 4, 3 };

            // Act
            var result = algorithm.solution2(A);

            // Assert
            var expected = 1;

            Assert.Equal(expected, result);
        }
Ejemplo n.º 21
0
        public void GetTapeEquilibriumMinimumExtremeLargeTest()
        {
            // Arrange
            TapeEquilibrium tapeEquilibrium = new TapeEquilibrium();

            int[] tape = new int[] { 1082132608, 1082132608, 1082132608, 1082132608, 1082132608 };

            // Action
            var current = tapeEquilibrium.GetTapeEquilibriumMinimum(tape);

            // Assert
            var expected = 1082132608;

            Assert.AreEqual(expected, current);
        }
Ejemplo n.º 22
0
        public void GetTapeEquilibriumMinimumEmptyTest()
        {
            // Arrange
            TapeEquilibrium tapeEquilibrium = new TapeEquilibrium();

            int[] tape = new int[] { };

            // Action
            var current = tapeEquilibrium.GetTapeEquilibriumMinimum(tape);

            // Assert
            var expected = 0;

            Assert.AreEqual(expected, current);
        }
Ejemplo n.º 23
0
        public void TestShortTape()
        {
            var tapeEquilibriumSolver = new TapeEquilibrium();

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

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

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

            Assert.AreEqual(solution, 1);
        }
Ejemplo n.º 24
0
        public void Solution_LargeNumbers_Correct()
        {
            //Arrange - Given
            var    maxrange = 10000;
            var    array    = new int[maxrange];
            Random rnd      = new Random();

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = rnd.Next(2, 100);
            }

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

            //Assert - Then
            Assert.IsType <int>(result);
        }
Ejemplo n.º 25
0
        public void TestShortTapeSkipingOneElement()
        {
            var tapeEquilibriumSolver = new TapeEquilibrium();

            int        maxElement = 10;
            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 = tapeEquilibriumSolver.solution(entryArray.ToArray());

            Assert.AreEqual(solution, 1);
        }
Ejemplo n.º 26
0
 public void TapeEquilibrium_OneElement_Success()
 {
     Assert.AreEqual(1, TapeEquilibrium.Solution(new int[] { 1 }));
 }
Ejemplo n.º 27
0
 public void TapeEquilibrium_EmptyArray_Success()
 {
     Assert.AreEqual(0, TapeEquilibrium.Solution(new int[] { }));
 }
Ejemplo n.º 28
0
 public void TapeEquilibrium_NegativeValues_Success()
 {
     Assert.AreEqual(4, TapeEquilibrium.Solution(new int[] { -3, -1, -7, -4, -3 }));
 }
Ejemplo n.º 29
0
 public void TapeEquilibrium_SmallArray_Success()
 {
     Assert.AreEqual(1, TapeEquilibrium.Solution(new int[] { 3, 1, 2, 4, 3 }));
 }
Ejemplo n.º 30
0
 public void TapeEquilibrium_TwoElements_Success()
 {
     Assert.AreEqual(2, TapeEquilibrium.Solution(new int[] { 1, 3 }));
 }