예제 #1
0
        public void GapTests(int input, int output)
        {
            BinaryGap gap    = new BinaryGap();
            var       result = gap.Calculate(input);

            Assert.AreEqual(output, result);
        }
예제 #2
0
        public void CountDivTest()
        {
            Console.WriteLine("Start");

            int t1, t2;

            for (int a = 100; a < 200; a++)
            {
                for (int b = 100; b < 200; b++)
                {
                    if (b < a)
                    {
                        continue;
                    }
                    for (int k = 1; k < 101; k++)
                    {
                        t1 = CountDiv.solution1(a, b, k);
                        t2 = CountDiv.solution(a, b, k);
                        Assert.AreEqual(t1, t2, 0, $"Result: {a}-{b}-{k}: [ex:{t1} ,go: {t2}]");
                    }
                }
            }

            CountDiv.solution1(1, 1, 1);

            // Random r = new Random(DateTime.Now.Millisecond);

            Assert.AreEqual(BinaryGap.solution(1041), 5);
            Assert.AreEqual(BinaryGap.solution(12343), 6);
        }
예제 #3
0
        public void FindShouldReturnLogestSequenceOfZerosInBinaryRepresentation(int n, int expected)
        {
            BinaryGap finder = new BinaryGap();
            int       actual = finder.Find(n);

            Assert.AreEqual(expected, actual);
        }
예제 #4
0
        public void Test3()
        {
            BinaryGap bg     = new BinaryGap();
            long      result = bg.getBinaryGap(887966);

            Assert.Equal(3, result);
        }
예제 #5
0
파일: Tests.cs 프로젝트: nads205/Codility
 public void Test1()
 {
     Assert.AreEqual(4, BinaryGap.solution(529));
     Assert.AreEqual(2, BinaryGap.solution(9));
     Assert.AreEqual(1, BinaryGap.solution(20));
     Assert.AreEqual(0, BinaryGap.solution(15));
 }
예제 #6
0
        public void Test1()
        {
            BinaryGap bg     = new BinaryGap();
            long      result = bg.getBinaryGap(20);

            Assert.Equal(1, result);
        }
예제 #7
0
        public void Test4()
        {
            BinaryGap bg     = new BinaryGap();
            long      result = bg.getBinaryGap(9999999999);

            Assert.Equal(6, result);
        }
예제 #8
0
        public void CheckBinaryGap_ForBinary_ShouldReturnNumberOfZeros(int number, int expectedResult)
        {
            var binaryGap = new BinaryGap();
            var result    = binaryGap.CheckBinaryGap(number);

            Assert.AreEqual(expectedResult, result);
        }
예제 #9
0
        public void Test2()
        {
            BinaryGap bg     = new BinaryGap();
            long      result = bg.getBinaryGap(529);

            Assert.Equal(4, result);
        }
예제 #10
0
        public void EdgeTest_32t()
        {
            var n = 32;

            var result = new BinaryGap().solution(n);

            Assert.Equal(0, result);
        }
예제 #11
0
파일: Tests.cs 프로젝트: nads205/Codility
 public void TestBinaryConversion()
 {
     Assert.AreEqual("1000010001", BinaryGap.convertToBinary(529));
     Assert.AreEqual("1001", BinaryGap.convertToBinary(9));
     Assert.AreEqual("10100", BinaryGap.convertToBinary(20));
     Assert.AreEqual("1111", BinaryGap.convertToBinary(15));
     Assert.AreEqual("1111111111111111111111111111111", BinaryGap.convertToBinary(2147483647));
 }
예제 #12
0
        public void SimpleTest_20()
        {
            var n = 20;

            var result = new BinaryGap().solution(n);

            Assert.Equal(1, result);
        }
예제 #13
0
        public void SimpleTest_529()
        {
            var n = 529;

            var result = new BinaryGap().solution(n);

            Assert.Equal(4, result);
        }
예제 #14
0
        public void BinaryGap_Should_Handle_Zero_Value()
        {
            BinaryGap subject = new BinaryGap();

            int result = subject.solution(0);

            Assert.Equal(0, result);
        }
예제 #15
0
        public void SimpleTest_15()
        {
            var n = 15;

            var result = new BinaryGap().solution(n);

            Assert.Equal(0, result);
        }
예제 #16
0
        public void BinaryGap_Should_Process_Complex_Value()
        {
            BinaryGap subject = new BinaryGap();

            int result = subject.solution(51712);

            Assert.Equal(2, result);
        }
예제 #17
0
        public void EdgeTest_BigInt()
        {
            var n = Int32.MaxValue - 36339;

            var result = new BinaryGap().solution(n);

            Assert.Equal(5, result);
        }
예제 #18
0
        public void EdgeTest_MaxInt()
        {
            var n = Int32.MaxValue;

            var result = new BinaryGap().solution(n);

            Assert.Equal(0, result);
        }
예제 #19
0
        public void TestMethod1()
        {
            int input    = 9;
            int expected = 2;
            int result   = BinaryGap.Solution(input);

            Assert.AreEqual(expected, result);
        }
        public void WhenPassIntegerReturnsTheLongestGap(int argument, int expected)
        {
            var target = new BinaryGap();

            var actual = target.solution(argument);

            Assert.AreEqual(expected, actual);
        }
예제 #21
0
        public void BinaryGap_Should_Process_Simple_Value()
        {
            BinaryGap subject = new BinaryGap();

            int result = subject.solution(6);

            Assert.Equal(0, result);
        }
예제 #22
0
        public void BinaryGapZeroIfNotFound()
        {
            //Arrange
            var BinaryGapSolver = new BinaryGap();

            //Act
            //Test
            Assert.AreEqual(0, BinaryGapSolver.Solution(15));
        }
예제 #23
0
        public void BinaryGapTest()
        {
            Console.WriteLine("Start");

            // Random r = new Random(DateTime.Now.Millisecond);

            Assert.AreEqual(BinaryGap.solution(1041), 5);
            Assert.AreEqual(BinaryGap.solution(12343), 6);
        }
예제 #24
0
        public void BinaryGapCorrectIfNotTwoOnes()
        {
            //Arrange
            var BinaryGapSolver = new BinaryGap();

            //Act
            //Test
            Assert.AreEqual(4, BinaryGapSolver.Solution(33));
        }
예제 #25
0
        public void SolutionTest_32()
        {
            var solution = new BinaryGap();

            int N        = 32;
            int expected = 0;
            int actual   = solution.Solution(N);

            Assert.AreEqual(expected, actual);
        }
예제 #26
0
        public void MaximumBinaryGapOfTwoGapsShouldBeReturned()
        {
            //Arrange
            var BinaryGapSolver = new BinaryGap();

            //Act
            //Test
            Assert.AreEqual(4, BinaryGapSolver.Solution(133));
            Assert.AreEqual(4, BinaryGapSolver.Solution(2123));
        }
예제 #27
0
        public void BinaryGapZeroIfNotBetweenTwoOnes()
        {
            //Arrange
            var BinaryGapSolver = new BinaryGap();

            //Act
            //Test
            Assert.AreEqual(0, BinaryGapSolver.Solution(1));
            Assert.AreEqual(0, BinaryGapSolver.Solution(2));
            Assert.AreEqual(0, BinaryGapSolver.Solution(32));
        }
예제 #28
0
    static void Main()
    {
        Console.WriteLine(BinaryReversal("4567"));

        Console.WriteLine("1, 3, 4, 7, 13", "1, 2, 4, 13, 15");
        Console.WriteLine(FindIntersection(new string[] { "1, 3, 4, 7, 13", "1, 2, 4, 13, 15" }));

        int[] array = new int[] { 10, 17, 25, 35, 52, 55, 62, 77, 90, 95 };
        int   index = BinarySearchDisplay(array, 77);

        Console.WriteLine("Index: {0}, Value: {1}", index, array[index]);

        string words = WordSplit(new string[] { "baseball", "a,all,b,ball,bas,base,cat,code,d,e,quit,z" });

        Console.WriteLine("Words: {0}", words);

        int[] profit = maxProfit(new int[] { 5, 11, 3, 50, 60, 90 });
        Console.WriteLine("Buy: {0}, Sell: {1}, Profit: {2}", profit[0], profit[1], profit[2]);

        int[] A1      = new int[] { 1, 3, 6, 4, 1, 2 };
        int[] A2      = new int[] { 1, 2, 3 };
        int[] A3      = new int[] { -3, 0, 1 };
        int   result1 = solution(A1);
        int   result2 = solution(A2);
        int   result3 = solution(A3);

        Console.WriteLine("result is: {0}, {1}, {2}", result1, result2, result3);

        FindElement();

        int[] A5  = new int[] { 20, -1, 10, 5, 1, 9, -89, 159 };
        int   in1 = solution1(A5);

        Console.WriteLine("solution1: {0}", in1);

        int[] A6  = new int[] { -3, -1, 10, 3, 1, 9, -89, 159 };
        int   in2 = solution2(A6);

        Console.WriteLine("solution2: {0}", in2);

        Console.WriteLine("--------------------------------------------");
        Console.WriteLine("--------------------------------------------");

        BinaryGap binaryGap = new BinaryGap();

        Console.WriteLine("binaryGap: {0}", binaryGap.solution(9));
        Console.WriteLine("binaryGap: {0}", binaryGap.solution(529));
        Console.WriteLine("binaryGap: {0}", binaryGap.solution(20));
        Console.WriteLine("binaryGap: {0}", binaryGap.solution(15));
        Console.WriteLine("binaryGap: {0}", binaryGap.solution(32));
        Console.WriteLine("binaryGap: {0}", binaryGap.solution(561892));

        Console.ReadKey();
    }
예제 #29
0
        public void BinaryGapTest()
        {
            //Arrange
            int number   = 1041;
            int expected = 5;
            int actual   = 0;

            //Act
            actual = BinaryGap.GetGap(number);
            //Assert
            Assert.Equal(expected, actual);
        }
예제 #30
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();
 }