Ejemplo n.º 1
0
        public void DataDrivenTest(int[] nums, bool canJumpExpected)
        {
            var  sut     = new JumpGame();
            bool canJump = sut.CanJump(nums);

            canJump.Should().Be(canJumpExpected, nums.Print());
        }
Ejemplo n.º 2
0
        public void Given_array_When_find_Then_return()
        {
            var nums = new int[] { 3, 2, 1, 4 };

            var ret = JumpGame.CanJump(nums);

            Assert.IsTrue(ret);
        }
Ejemplo n.º 3
0
        public void JumpGameResultsInFalse()
        {
            var input = new int[] { 3, 2, 1, 0, 4 };

            var result = JumpGame.canJump(input);

            Assert.False(result);
        }
Ejemplo n.º 4
0
        public void JumpGameResultsInTrue()
        {
            var input = new int[] { 2, 3, 1, 1, 4 };

            var result = JumpGame.canJump(input);

            Assert.True(result);
        }
Ejemplo n.º 5
0
        public void CanJumpFromPositionDynamicGreedy_Success()
        {
            var input = new int[] { 2, 3, 1, 1, 4 };

            var result = new JumpGame().CanJump(input);

            Assert.IsTrue(result);

            input  = new int[] { 3, 2, 1, 0, 4 };
            result = new JumpGame().CanJump(input);
            Assert.IsFalse(result);
        }
Ejemplo n.º 6
0
        public void BackTrack_Success()
        {
            var input = new int[] { 2, 3, 1, 1, 4 };

            var result = new JumpGame().CanJump(input);

            Assert.IsTrue(result);

            input  = new int[] { 3, 2, 1, 0, 4 };
            result = new JumpGame().CanJump(input);
            Assert.IsFalse(result);
        }
Ejemplo n.º 7
0
        public void TestJumpGame1()
        {
            var r = JumpGame.Jump1_S1(new[] { 2, 3, 1, 1, 4 });

            Assert.AreEqual(r, true);

            r = JumpGame.Jump1_S1(new[] { 3, 2, 1, 0, 4 });
            Assert.AreEqual(r, false);

            r = JumpGame.Jump1_S2(new[] { 2, 3, 1, 1, 4 });
            Assert.AreEqual(r, true);

            r = JumpGame.Jump1_S2(new[] { 3, 2, 1, 0, 4 });
            Assert.AreEqual(r, false);
        }
Ejemplo n.º 8
0
 public void Solution2Test(int[] numbers, bool result)
 {
     Assert.Equal(result, JumpGame.Solution2(numbers));
 }
 public void Setup()
 {
     solution = new JumpGame();
 }
Ejemplo n.º 10
0
    [TestCase("2,0,2", 0, false)] // loop
    public void BasicScenario(string source, int startIndex, bool expected)
    {
        var actual = JumpGame.Run(source.Split(',').Select(int.Parse).ToArray(), startIndex);

        Assert.That(actual, Is.EqualTo(expected));
    }
Ejemplo n.º 11
0
        static public void Main(String[] args)
        {
            TwoSumProblem                 twoSumProblem                     = new TwoSumProblem();
            ReverseProblem                reverseProblem                    = new ReverseProblem();
            IsPalindromeProblem           isPalindromeProblem               = new IsPalindromeProblem();
            MaxAreaProblem                maxAreaProblem                    = new MaxAreaProblem();
            ValidParenthesesProblem       validParenthesesProblem           = new ValidParenthesesProblem();
            LetterComboPhoneNumberProblem letterComboPhoneNumberProblem     = new LetterComboPhoneNumberProblem();
            StockArray                      stockArrayProblem               = new StockArray();
            ClimbingStepsProblem            climbingStepsProblem            = new ClimbingStepsProblem();
            RemoveElementTypeProblem        removeElementTypeProblem        = new RemoveElementTypeProblem();
            ValidAnagram                    validAnagramProblem             = new ValidAnagram();
            ProductOfArrayExceptSelfProblem productOfArrayExceptSelfProblem = new ProductOfArrayExceptSelfProblem();
            SearchInsertPosition            searchInsertPositionProblem     = new SearchInsertPosition();
            RomanToIntt                     romanToIntProblem               = new RomanToIntt();
            FoobarProblems                  foobarProblems                  = new FoobarProblems();
            JumpGame             jumpGame      = new JumpGame();
            RobbingHouses        robbingHouses = new RobbingHouses();
            Power                power         = new Power();
            MoveZeroesProblem    moveZeroes    = new MoveZeroesProblem();
            IsSubsequenceProblem isSubsequence = new IsSubsequenceProblem();

            /*
             * int[] nums = new int[] {2, 11, 14, 17};
             * int target = 16;
             * int [] result = twoSumProblem.TwoSum(nums, target);
             * result.ToList().ForEach(i => Console.WriteLine(i.ToString()));
             */

            /*
             * int x = int.MaxValue;
             * int reversed = reverseProblem.Reverse(x);
             * Console.Writeline(x);
             */

            /*
             * int x = 121;
             * Console.WriteLine(isPalindromeProblem.IsPalindrome(x));
             */

            /*
             * int[] height = new int[] {1, 8, 6, 2, 5, 4, 8, 3, 7};
             * Console.WriteLine(maxAreaProblem.MaxArea(height));
             */

            /*
             * string s = "[([]])";
             * Console.WriteLine(validParenthesesProblem.IsValid(s));
             */

            /*
             * string digits = "";
             * foreach (string s in letterComboPhoneNumberProblem.LetterCombinations(digits))
             * {
             *  Console.WriteLine(s);
             * }
             */

            /*
             * int[] prices = new int[] {7, 1, 5, 3, 6, 4};
             * Console.WriteLine(stockArrayProblem.MaxProfit(prices));
             */

            /*
             * int n = 6;
             * Console.WriteLine(climbingStepsProblem.ClimbStairs(n));
             */

            /*
             * int[] nums = new int[] { 3, 2, 2, 3 };
             * int val = 3;
             * Console.WriteLine(removeElementTypeProblem.RemoveElement(nums, val));
             */

            /*
             * string s = "rat";
             * string t = "car";
             * Console.WriteLine(validAnagramProblem.IsAnagram(s, t));
             */

            /*
             * int[] nums = new int[] { 1, 2, 3, 4 };
             * int[] result = productOfArrayExceptSelfProblem.ProductExceptSelf(nums);
             * result.ToList().ForEach(i => Console.WriteLine(i.ToString()));
             */

            /*
             * int[] nums = new int[] { 2, 3, 5, 6 };
             * int target = 4;
             * Console.WriteLine(searchInsertPositionProblem.SearchInsert(nums, target));
             */

            /*
             * string b = "X";
             * Console.WriteLine(romanToIntProblem.RomanToInt(b));
             */

            /*
             * string[] strs = new string[] { "flower", "flow", "flight" };
             * Console.WriteLine(longestPrefixProblem.LongestCommonPrefix(strs));
             */

            /*
             * List<int> x = new List<int>() { 14, 27, 1, 4, 2, 50, 3, 1 };
             * List<int> y = new List<int>() { 2, 4, -4, 3, 1, 1, 14, 27, 50 };
             * Console.WriteLine(foobarProblems.Solution1(x, y));
             */

            /*
             * Console.WriteLine(foobarProblems.Solution2(90, 7));
             */

            /*
             * Console.WriteLine(foobarProblems.Solution3(0, 1));
             */

            /*
             * Console.WriteLine(foobarProblems.Solution4(2, 1));
             */

            /*
             * int[] nums = new int[] {1, 0, 8, 2, 0, 0, 1 };
             * Console.WriteLine(jumpGame.CanJump(nums));
             */

            /*
             * int[] nums = new int[] {1, 3, 6, 3, 1, 1, 1, 1, 2 };
             * Console.WriteLine(robbingHouses.RobHouse(nums));
             */

            /* recursion practice:::::::::
             * Console.WriteLine(robbingHouses.Factorial(5));
             * Console.WriteLine(robbingHouses.PowerTo(7, 2));
             * Console.WriteLine(robbingHouses.SumTillN(10));
             * Console.WriteLine(robbingHouses.Multiply(10, 5));
             * Console.WriteLine(robbingHouses.PowerToNegativeInt(3, -2));
             */

            /*
             * Console.WriteLine(power.IsPowerOfTwo(0));
             * Console.WriteLine(power.IsPowerOfThree(27));
             * Console.WriteLine(power.IsHappy(19));
             * Console.WriteLine(power.AddDigits(38));
             */

            /*
             * int[] nums = new int[] { 0, 1, 0, 3, 12 };
             * Console.WriteLine(moveZeroes.MoveZeroes(nums));
             */

            Console.WriteLine(isSubsequence.IsSubsequence("bb", "abbc"));
            Console.WriteLine(isSubsequence.CanConstruct("aab", "baa"));

            Console.ReadLine();
        }