示例#1
0
        public void test_solution_receivesPrematureArray_shouldReturn1(int[] given, int expected)
        {
            var target = new PermCheck();
            var actual = target.solution(given);

            Assert.AreEqual(expected, actual);
        }
        public void CheckShouldReturn1ForPermutationOr0IfItsNotWhenGivenA(int[] a, int expected)
        {
            PermCheck checker = new PermCheck();
            int       actual  = checker.Check(a);

            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void PermCheckSolutionTest()
        {
            PermCheck testPermCheck = new PermCheck();

            int[] arrayTest = new int[] { 4, 1, 3, 2 };
            Assert.AreEqual(1, testPermCheck.Solution(arrayTest));
        }
示例#4
0
        public void PermCheckSolutionTestNoPermutation()
        {
            PermCheck testPermCheck = new PermCheck();

            int[] arrayTest = new int[] { 4, 1, 3 };
            Assert.AreEqual(0, testPermCheck.Solution(arrayTest));
        }
示例#5
0
        private static void RunPermCheck()
        {
            Console.WriteLine($" --------- 4.1 PermCheck --------- ");

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

            Console.WriteLine($"result = {result}");
        }
示例#6
0
文件: Tests.cs 项目: nads205/Codility
        public void Test1()
        {
            var testCase = new int[] { 4, 1, 3, 2 };

            Assert.AreEqual(PermCheck.solution(testCase), 1);
            testCase = new int[] { 4, 1, 3 };
            Assert.AreEqual(PermCheck.solution(testCase), 0);
        }
示例#7
0
        public void TestMethod1()
        {
            int[] input    = { 4, 1, 3, 2 };
            int   expected = 1;
            int   result   = PermCheck.Solution(input);

            Assert.AreEqual(expected, result);
        }
        public void PermCheck_Should_Handle_Empty_Array()
        {
            PermCheck subject = new PermCheck();

            int[] array = { };

            int result = subject.solution(array);

            Assert.Equal(0, result);
        }
        public void PermCheck_Should_Invalidate_Non_Permutation_Array()
        {
            PermCheck subject = new PermCheck();

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

            int result = subject.solution(array);

            Assert.Equal(0, result);
        }
        public void PermCheck_Should_Validate_Single_Permutation_Array()
        {
            PermCheck subject = new PermCheck();

            int[] array = { 1 };

            int result = subject.solution(array);

            Assert.Equal(1, result);
        }
示例#11
0
 static void Main(string[] args)
 {
     BinaryGap.Test();
     CyclicRotation.Test();
     OddOccurrencesInArray.Test();
     TapeEquilibrium.Test();
     PermCheck.Test();
     FrogRiverOne.Test();
     MissingInteger.Test();
 }
示例#12
0
        public void SolutionEmptyTest()
        {
            // Arrange
            int[] A = new int[] { };

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

            // Assert
            int expected = 0;

            Assert.AreEqual(expected, actual);
        }
示例#13
0
        public void SolutionSimpleNoPermutationTest()
        {
            // Arrange
            int[] A = new int[] { 4, 1, 3 };

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

            // Assert
            int expected = 0;

            Assert.AreEqual(expected, actual);
        }
示例#14
0
        public void Case1()
        {
            // Arrange
            var algorithm = new PermCheck();
            var A         = new int[] { 4, 1, 3, 2 };

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

            // Assert
            var expected = 1;

            Assert.Equal(expected, result);
        }
示例#15
0
    public static void Test()
    {
        var A = new int[] { 7, 6, 2, 1, 5, 3, 4 };
        var R = new PermCheck().Solution(A);

        Console.WriteLine("Result: " + R);

        A = new int[] { 7, 7, 2, 1, 4, 3, 4 };
        R = new PermCheck().Solution(A);
        Console.WriteLine("Result: " + R);

        A = new int[] { 9, 5, 2, 1, 4, 3, 4 };
        R = new PermCheck().Solution(A);
        Console.WriteLine("Result: " + R);
    }
示例#16
0
        public void SolutionOneHundredNumbersPermutationTest()
        {
            // Arrange
            int length = 100000;

            int[] A = new int[length];
            for (int i = 0; i < length; i++)
            {
                A[i] = i + 1;
            }

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

            // Assert
            int expected = 1;

            Assert.AreEqual(expected, actual);
        }
示例#17
0
        public void SolutionBigNumbersTest()
        {
            // Arrange
            int length = 100000;

            int[] A = new int[length];
            for (int i = 0; i < length - 10; i++)
            {
                A[i] = i + 1;
            }
            for (int i = length - 10; i < length; i++)
            {
                A[i] = 1000000000 - i;
            }

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

            // Assert
            int expected = 0;

            Assert.AreEqual(expected, actual);
        }
示例#18
0
 public void PermCheck_OneElement_NoPerm_Success()
 {
     Assert.AreEqual(0, PermCheck.Solution(new int[] { 2 }));
 }
示例#19
0
 public void PermCheck_SmallArray_GreaterN_NoPerm_Success()
 {
     Assert.AreEqual(0, PermCheck.Solution(new int[] { 1, 2, 6, 3 }));
 }
示例#20
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);
        }
示例#21
0
 public void PermCheck_SmallArray_SumCorrect_NoPerm_Success()
 {
     Assert.AreEqual(0, PermCheck.Solution(new int[] { 1, 4, 1 }));
 }
示例#22
0
 public void PermCheck_OneElement_WithPerm_Success()
 {
     Assert.AreEqual(1, PermCheck.Solution(new int[] { 1 }));
 }
 public void Initialize()
 {
     _permCheck = new PermCheck();
 }
示例#24
0
 public void PermCheck_SmallArray_WithPerm_Success()
 {
     Assert.AreEqual(1, PermCheck.Solution(new int[] { 1, 2, 4, 3 }));
 }