Esempio n. 1
0
        public void IntegerToRoman_Solutions(string input, int expected)
        {
            var solution = new Solution2();
            var result   = solution.RomanToInt(input);

            Assert.AreEqual(expected, result);
        }
Esempio n. 2
0
        public void IntegerToRoman_Solutions(int input, string expected)
        {
            var solution = new Solution2();
            var result   = solution.IntToRoman(input);

            Assert.AreEqual(expected, result);
        }
Esempio n. 3
0
 public void AddTwoNumbersTest()
 {
     Assert.Equal(FromArray(new int[] { 7, 0, 8 }), Solution2.AddTwoNumbers(FromArray(new int[] { 2, 4, 3 }), FromArray(new int[] { 5, 6, 4 })));
     Assert.Equal(FromArray(new int[] { 0 }), Solution2.AddTwoNumbers(FromArray(new int[] { 0 }), FromArray(new int[] { 0 })));
     Assert.Equal(FromArray(new int[] { 8, 9, 9, 9, 0, 0, 0, 1 }), Solution2.AddTwoNumbers(FromArray(new int[] { 9, 9, 9, 9, 9, 9, 9 }), FromArray(new int[] { 9, 9, 9, 9 })));
     Assert.Equal(FromArray(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }), Solution2.AddTwoNumbers(FromArray(new int[] { 1, 9, 9, 9, 9, 9, 9, 9, 9, 9 }), FromArray(new int[] { 9 })));
 }
Esempio n. 4
0
        public void PermuteUnique_Solutions(int[] nums, string expectedJson)
        {
            var solution = new Solution2();

            var result = solution.PermuteUnique(nums);

            Assert.AreEqual(expectedJson, JsonConvert.SerializeObject(result));
        }
Esempio n. 5
0
        public void GroupAnagrams_Solutions(string[] strs, string expectedJson)
        {
            var solution = new Solution2();

            var result = solution.GroupAnagrams(strs);

            var expected = (IList <IList <string> >)JsonConvert.DeserializeObject <List <IList <string> > >(expectedJson);

            Assert.AreEqual(Sort(expected), Sort(result));
        }
Esempio n. 6
0
        public void Rotate_Solutions(string matrixJson, string expectedJson)
        {
            var matrix = JsonConvert.DeserializeObject <int[][]>(matrixJson);

            var solution = new Solution2();

            solution.Rotate(matrix);

            Assert.AreEqual(expectedJson, JsonConvert.SerializeObject(matrix));
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            var tests = new TestSample[] {
                new TestSample(new int[] { 100001 }, new int[] { 100000 }, 100000.5),
                new TestSample(new int[] { 1, 3 }, new int[] { 2 }, 2),
                new TestSample(new int[] { 1, 2 }, new int[] { 3, 4 }, 2.5),
                new TestSample(new int[] { 1, 2 }, new int[] { 1, 2, 3 }, 2),
                new TestSample(new int[] { 1, 2, 3 }, new int[] { 1, 2 }, 2),
                new TestSample(new int[] { 1 }, new int[] { 2, 3, 4 }, 2.5),
                new TestSample(new int[] { 1, 1, 1 }, new int[] { 1, 1, 1 }, 1),
                new TestSample(new int[] { 2, 3, 4, 5, 6 }, new int[] { 1 }, 3.5),
                new TestSample(new int[] { 1, 2 }, new int[] { }, 1.5),
                new TestSample(new int[] { 2 }, new int[] { 1, 3, 4 }, 2.5),
                new TestSample(new int[] { 3 }, new int[] { 1, 2, 4 }, 2.5),
                new TestSample(new int[] { 5 }, new int[] { 1, 2, 3, 4, 6 }, 3.5),
                new TestSample(new int[] { }, new int[] { 3, 4 }, 3.5),
                new TestSample(null, null)
            };

            var sol = new Solution2();

            RunTests(tests, sol.FindMedianSortedArrays);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var tests = new TestSample[] {
                new TestSample(new int[] { 2, 7, 11, 15 }, 9, new int[] { 0, 1 }),
                new TestSample(new int[] { 3, 2, 4 }, 6, new int[] { 1, 2 }),
                new TestSample(new int[] {
                    230, 863, 916, 585, 981, 404, 316, 785, 88, 12, 70, 435, 384,
                    778, 887, 755, 740, 337, 86, 92, 325, 422, 815, 650, 920, 125,
                    277, 336, 221, 847, 168, 23, 677, 61, 400, 136, 874, 363, 394,
                    199, 863, 997, 794, 587, 124, 321, 212, 957, 764, 173, 314, 422,
                    927, 783, 930, 282, 306, 506, 44, 926, 691, 568, 68, 730, 933,
                    737, 531, 180, 414, 751, 28, 546, 60, 371, 493, 370, 527, 387,
                    43, 541, 13, 457, 328, 227, 652, 365, 430, 803, 59, 858, 538,
                    427, 583, 368, 375, 173, 809, 896, 370, 789
                },
                               542, new int[] { 28, 45 }),
                new TestSample(null, 0)
            };

            var sol = new Solution2();

            RunTests(tests, sol.TwoSum);
        }