Пример #1
0
        public void Test_Generic <T>(Func <int[][], T> constructor, string[] commands, string matrixStr, string argsStr, string expectedStr) where T : INumMatrix
        {
            var matrix   = ArrayHelper.MatrixFromString <int>(matrixStr);
            var args     = ArrayHelper.MatrixFromString <int>(argsStr);
            var expected = ArrayHelper.ArrayFromString <int>(expectedStr);

            Assert.AreEqual(args.Length, expected.Length);
            Assert.AreEqual(args.Length, commands.Length);

            var sol = constructor(matrix);
            var res = new int[expected.Length];

            for (int i = 0; i < args.Length; i++)
            {
                switch (commands[i])
                {
                case "sumRegion":
                    Assert.AreEqual(4, args[i].Length);
                    res[i] = sol.SumRegion(args[i][0], args[i][1], args[i][2], args[i][3]);
                    break;
                }
            }

            CollectionAssert.AreEqual(expected, res);
        }
Пример #2
0
        public void Test_Generic(string boxes, string expectedStr)
        {
            var sol      = new Solution();
            var res      = sol.MinOperations(boxes);
            var expected = ArrayHelper.ArrayFromString <int>(expectedStr);

            CollectionAssert.AreEqual(res, expected);
        }
Пример #3
0
        public void Test_Generic(string arrStr, int expected)
        {
            var input = ArrayHelper.ArrayFromString <int>(arrStr);

            var sol = new Solution();
            var res = sol.NumSquarefulPerms(input);

            Assert.AreEqual(res, expected);
        }
Пример #4
0
        public void Test_Generic(string numsStr, int target, int expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(numsStr);

            var sol = new Solution();
            var res = sol.Search(nums, target);

            Assert.AreEqual(res, expected);
        }
Пример #5
0
        public void Test_Naive(string numsStr, int expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(numsStr);

            var sol = new Solution_Naive();
            var res = sol.MissingNumber(nums);

            Assert.AreEqual(expected, res);
        }
Пример #6
0
        public void Test_Generic(string inputStr, string expectedStr)
        {
            var temperatures = ArrayHelper.ArrayFromString <int>(inputStr);
            var sol          = new Solution();
            var res          = sol.DailyTemperatures(temperatures);
            var expected     = ArrayHelper.ArrayFromString <int>(expectedStr);

            CollectionAssert.AreEqual(res, expected);
        }
Пример #7
0
        public void Test_Generic(string numsStr, bool expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(numsStr);

            var sol = new Solution();
            var res = sol.Find132pattern(nums);

            Assert.AreEqual(res, expected);
        }
Пример #8
0
        public void Test_Generic(string numsStr, int expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(numsStr);

            var sol = new Solution();
            var res = sol.MajorityElement(nums);

            Assert.AreEqual(res, expected);
        }
Пример #9
0
        public void Test_Generic(string numsStr, int k, int expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(numsStr);

            var sol = new Solution();
            var res = sol.FindPairs(nums, k);

            Assert.AreEqual(res, expected);
        }
Пример #10
0
        public void Test_Generic(string cardsStr, int k, int expected)
        {
            var cardPoints = ArrayHelper.ArrayFromString <int>(cardsStr);

            var sol = new Solution();
            var res = sol.MaxScore(cardPoints, k);

            Assert.AreEqual(expected, res);
        }
Пример #11
0
        public void Test_Generic(string strArr, int expected)
        {
            var time = ArrayHelper.ArrayFromString <int>(strArr);

            var sol = new Solution();
            var res = sol.NumPairsDivisibleBy60(time);

            Assert.AreEqual(res, expected);
        }
Пример #12
0
        public void Test_Generic(string arrStr, bool expected)
        {
            var arr = ArrayHelper.ArrayFromString <int>(arrStr);

            var sol = new Solution();
            var res = sol.CanReorderDoubled(arr);

            Assert.AreEqual(res, expected);
        }
Пример #13
0
        public void Test_GenericStr(string arrStr, int expected)
        {
            var arr = ArrayHelper.ArrayFromString <int>(arrStr);

            var sol = new Solution();
            var res = sol.MinJumps(arr);

            Assert.AreEqual(res, expected);
        }
Пример #14
0
        public void Test_Generic(string strArr, int expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(strArr);

            var sol = new Solution();
            var res = sol.SingleNonDuplicate(nums);

            Assert.AreEqual(res, expected);
        }
Пример #15
0
        public void Test_Generic(string s, string p, string expectedStr)
        {
            var expected = ArrayHelper.ArrayFromString <int>(expectedStr);

            var sol = new Solution();
            var res = sol.FindAnagrams(s, p);

            CollectionAssert.AreEquivalent(res, expected);
        }
Пример #16
0
        public void Test_Generic(string numsStr, bool expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(numsStr);

            var sol = new Solution();
            var res = sol.CheckPossibility(nums);

            Assert.AreEqual(expected, res);
        }
Пример #17
0
        public void Test_Generic(int n, string arrStr, int expected)
        {
            var quantities = ArrayHelper.ArrayFromString <int>(arrStr);

            var sol = new Solution();
            var res = sol.MinimizedMaximum(n, quantities);

            Assert.AreEqual(res, expected);
        }
Пример #18
0
        public void Test_Generic(string seatsArr, int expected)
        {
            var seats = ArrayHelper.ArrayFromString <int>(seatsArr);

            var sol = new Solution();
            var res = sol.MaxDistToClosest(seats);

            Assert.AreEqual(res, expected);
        }
Пример #19
0
        public void Test_GenericStr(string heightsStr, int bricks, int ladders, int expected)
        {
            var heights = ArrayHelper.ArrayFromString <int>(heightsStr);

            var sol = new Solution();
            var res = sol.FurthestBuilding(heights, bricks, ladders);

            Assert.AreEqual(expected, res);
        }
Пример #20
0
        public void Test_Generic(string arrStr, int n, bool expected)
        {
            var arr = ArrayHelper.ArrayFromString <int>(arrStr);

            var sol = new Solution();
            var res = sol.CanPlaceFlowers(arr, n);

            Assert.AreEqual(res, expected);
        }
Пример #21
0
        public void Test_Stack(int n, string expectedStr)
        {
            var expected = ArrayHelper.ArrayFromString <int>(expectedStr);

            var sol = new Solution();
            var res = sol.CountBits(n);

            Assert.AreEqual(res, expected);
        }
Пример #22
0
        public void Test_Generic(string numsStr, int k, int expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(numsStr);

            var sol = new Solution();
            var res = sol.PartitionArray(nums, k);

            Assert.AreEqual(expected, res);
        }
Пример #23
0
        public void Test_Recursive(string coinsStr, int amount, int expected)
        {
            var coins = ArrayHelper.ArrayFromString <int>(coinsStr);

            var sol = new Solution_Recursive();
            var res = sol.CoinChange(coins, amount);

            Assert.AreEqual(expected, res);
        }
Пример #24
0
        public void Test_GenericStr(string tragetStr, bool expected)
        {
            var target = ArrayHelper.ArrayFromString <int>(tragetStr);

            var sol = new Solution();
            var res = sol.IsPossible(target);

            Assert.AreEqual(expected, res);
        }
Пример #25
0
        public void Test_Generic(string s, string spacesStr, string expected)
        {
            var spaces = ArrayHelper.ArrayFromString <int>(spacesStr);

            var sol = new Solution();
            var res = sol.AddSpaces(s, spaces);

            Assert.AreEqual(res, expected);
        }
Пример #26
0
        public void Test_Generic(string s, string expectedStr)
        {
            var expected = ArrayHelper.ArrayFromString <int>(expectedStr);

            var sol = new Solution();
            var res = sol.PartitionLabels(s);

            CollectionAssert.AreEqual(res, expected);
        }
Пример #27
0
        public void Test_Generic(string arrStr, int expected)
        {
            var nums = ArrayHelper.ArrayFromString <int>(arrStr);

            var sol = new Solution();
            var res = sol.FindUnsortedSubarray(nums);

            Assert.AreEqual(res, expected);
        }
Пример #28
0
        public void Test_GenericStr(string stonesStr, int expected)
        {
            var stones = ArrayHelper.ArrayFromString <int>(stonesStr);

            var sol = new Solution();
            var res = sol.LastStoneWeight(stones);

            Assert.AreEqual(res, expected);
        }
Пример #29
0
        public void Test_Parallel(string arrStr, string expected)
        {
            var arr = ArrayHelper.ArrayFromString <int>(arrStr);

            var sol = new Solution_Parallel();
            var res = sol.SortedSquares(arr);

            CollectionAssert.AreEquivalent(res, ArrayHelper.ArrayFromString <int>(expected));
        }
Пример #30
0
        public void Test_Generic(string hiddenStr, int lower, int upper, int expected)
        {
            var hidden = ArrayHelper.ArrayFromString <int>(hiddenStr);

            var sol = new Solution();
            var res = sol.NumberOfArrays(hidden, lower, upper);

            Assert.AreEqual(expected, res);
        }