public void TestValidAnagram()
        {
            ValidAnagram validAnagram = new ValidAnagram();

            Assert.True(validAnagram.IsAnagram("anagram", "nagaram"));
            Assert.False(validAnagram.IsAnagram("rat", "cat"));
        }
Beispiel #2
0
        public void IsAnagram(string source, string target, bool expected)
        {
            var sut    = new ValidAnagram();
            var actual = sut.IsAnagram(source, target);

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void ValidAnagramTest(string s, string t, bool expected)
        {
            var validAnagram = new ValidAnagram();

            var actual = validAnagram.IsAnagramBestCase(s, t);

            Assert.That(actual, Is.EqualTo(expected));
        }
Beispiel #4
0
        public void ValidAnagramTest()
        {
            var source       = "anagram";
            var target       = "nagaram";
            var validAnagram = new ValidAnagram();
            var result       = validAnagram.IsAnagram(source, target);

            Assert.IsTrue(result,
                          string.Format("Failed to perform pos test source: {0} target {1}", source, target));


            source       = "rat";
            target       = "car";
            validAnagram = new ValidAnagram();
            result       = validAnagram.IsAnagram(source, target);
            Assert.IsFalse(result,
                           string.Format("Failed to perform neg test source: {0} target {1}", source, target));
        }
        public void IsAnagram2Test()
        {
            var inputs1 = new[] {
                "anagram",
                "rat"
            };
            var inputs2 = new[] {
                "nagaram",
                "car"
            };
            var expecteds = new[] { true, false };


            foreach (var((s, t), expected) in inputs1.Zip(inputs2).Zip(expecteds))
            {
                ValidAnagram.IsAnagram2(s, t).Should().Be(expected);
            }
        }
Beispiel #6
0
        public void ValidAnagram_Test()
        {
            var result1 = ValidAnagram.IsValid("anagram", "nagamar");

            Assert.IsTrue(result1);

            var result2 = ValidAnagram.IsValid("a", "b");

            Assert.IsFalse(result2);

            var result3 = ValidAnagram.IsValid("", "");

            Assert.IsTrue(result3);

            var result4 = ValidAnagram.IsValid("", "b");

            Assert.IsFalse(result4);

            var result5 = ValidAnagram.IsValid("a", "");

            Assert.IsFalse(result5);
        }
Beispiel #7
0
 public void Sln1Test(string s, string t, bool valid)
 {
     Assert.Equal(valid, ValidAnagram.Solution1(s, t));
 }
        public void IsAnagramDictionaryTest(string s, string t, bool expected)
        {
            var actual = new ValidAnagram().IsAnagramDictionary(s, t);

            Assert.Equal(expected, actual);
        }
Beispiel #9
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();
        }
Beispiel #10
0
 public void BeforeEach()
 {
     ValidAnagram = new ValidAnagram();
 }
Beispiel #11
0
        void InternalTest(string s, string t, bool expected)
        {
            bool actual = ValidAnagram.IsAnagram(s, t);

            Assert.Equal <bool>(expected, actual);
        }