Пример #1
0
        public void RunProblem()
        {
            var temp = FindWords(new char[][]
            {
                new char[] { 'o', 'a', 'a', 'n' },
                new char[] { 'e', 't', 'a', 'e' },
                new char[] { 'i', 'h', 'k', 'r' },
                new char[] { 'i', 'f', 'l', 'v' },
            },
                                 new string[] { "oath", "pea", "eat", "rain" });

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new string[] { "eat", "oath" }))
            {
                throw new Exception();
            }

            temp = FindWords(new char[][]
            {
                new char[] { 'a', 'a' }
            },
                             new string[] { "aaa" });
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new string[] { "" }))
            {
                throw new Exception();
            }
        }
Пример #2
0
        public void RunProblem()
        {
            var temp = FindSmallestSetOfVertices(6, new List <IList <int> >()
            {
                new List <int>()
                {
                    0, 1
                },
                new List <int>()
                {
                    0, 2
                },
                new List <int>()
                {
                    2, 5
                },
                new List <int>()
                {
                    3, 4
                },
                new List <int>()
                {
                    4, 2
                },
            });

            if (ProblemHelper.ArrayEqual(new[] { 0, 3 }, temp))
            {
                throw new Exception();
            }
        }
Пример #3
0
        public void RunProblem()
        {
            var temp = LargestDivisibleSubset(new int[] { 1, 2, 3 });

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 1, 2 }))
            {
                throw new Exception();
            }

            temp = LargestDivisibleSubset(new int[] { 1, 2, 4, 8 });
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 1, 2, 4, 8 }))
            {
                throw new Exception();
            }

            temp = LargestDivisibleSubset(new int[] { });
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { }))
            {
                throw new Exception();
            }

            temp = LargestDivisibleSubset(new int[] { 4, 8, 10, 240 });
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 4, 8, 240 }))
            {
                throw new Exception();
            }
        }
Пример #4
0
        public void RunProblem()
        {
            var temp = SplitIntoFibonacci("123456579");

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 123, 456, 579 }))
            {
                throw new Exception();
            }

            temp = SplitIntoFibonacci("11235813");
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 1, 1, 2, 3, 5, 8, 13 }))
            {
                throw new Exception();
            }

            temp = SplitIntoFibonacci("112358130");
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { }))
            {
                throw new Exception();
            }

            temp = SplitIntoFibonacci("0123");
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { }))
            {
                throw new Exception();
            }

            temp = SplitIntoFibonacci("1101111");
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 110, 1, 111 }))
            {
                throw new Exception();
            }
        }
Пример #5
0
        public void RunProblem()
        {
            var temp = NumSmallerByFrequency(new string[]
            {
                "cbd",
            }, new string[]
            {
                "zaaaz"
            });

            if (!ProblemHelper.ArrayIsEqual(new int[] { 1 }, temp, false))
            {
                throw new Exception();
            }

            temp = NumSmallerByFrequency(new string[]
            {
                "bbb",
                "cc"
            }, new string[]
            {
                "a",
                "aa",
                "aaa",
                "aaaa"
            });
            if (!ProblemHelper.ArrayIsEqual(new int[] { 1, 2 }, temp, false))
            {
                throw new Exception();
            }
        }
Пример #6
0
        public void RunProblem()
        {
            var temp = FindUnsortedSubarray(new int[] { 2, 1 });

            ProblemHelper.AEqual(temp, 2);

            temp = FindUnsortedSubarray(new int[] { 2, 3, 3, 2, 4 });
        }
Пример #7
0
        public void RunProblem()
        {
            var temp = Spellchecker(new string[] { "KiTe", "kite", "hare", "Hare" }, new string[] { "kite", "Kite", "KiTe", "Hare", "HARE", "Hear", "hear", "keti", "keet", "keto" });

            if (!ProblemHelper.ArrayIsEqual(temp, new string[] { "kite", "KiTe", "KiTe", "Hare", "hare", "", "", "KiTe", "", "KiTe" }, false))
            {
                throw new Exception();
            }
        }
Пример #8
0
        public void RunProblem()
        {
            var temp = FindErrorNums(new int[] { 1, 2, 2, 4 });

            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 2, 3 }))
            {
                throw new Exception();
            }
        }
Пример #9
0
        public void RunProblem()
        {
            var temp = FindDisappearedNumbers(new int[] { 4, 3, 2, 7, 8, 2, 3, 1 });

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 5, 6 }, false))
            {
                throw new Exception();
            }
        }
Пример #10
0
        public void RunProblem()
        {
            var temp = CountSmaller(new int[] { 5, 2, 6, 1 });

            if (!ProblemHelper.ArrayIsEqual(new int[] { 2, 1, 1, 0 }, temp.ToArray(), false))
            {
                throw new Exception();
            }
        }
Пример #11
0
        public void RunProblem()
        {
            var temp = SuperEggDrop(1, 2);

            ProblemHelper.AEqual(temp, 2);

            temp = SuperEggDrop(2, 6);
            ProblemHelper.AEqual(temp, 3);
        }
Пример #12
0
        public void RunProblem()
        {
            var tree = ProblemHelper.MadeTreeV2(new int?[] { 1, null, 1, 1, 1, null, null, 1, 1, null, 1, null, null, null, 1, null, 1 });
            var temp = LongestZigZag(tree);

            tree = ProblemHelper.MadeTreeV2(new int?[] { 1, 1, 1, null, 1, null, null, 1, 1, null, 1 });
            temp = LongestZigZag(tree);

            tree = ProblemHelper.MadeTreeV2(new int?[] { 1 });
            temp = LongestZigZag(tree);
        }
Пример #13
0
        private void MadeTreeV2Test()
        {
            int?[] array = new int?[] { 1, null, 1, 1, 1, null, null, 1, 1, null, 1, null, null, null, 1, null, 1 };
            var    root  = ProblemHelper.MadeTreeV2(array);

            array = new int?[] { 1, 1, 1, null, 1, null, null, 1, 1, null, 1 };
            root  = ProblemHelper.MadeTreeV2(array);

            array = new int?[] { 1 };
            root  = ProblemHelper.MadeTreeV2(array);
        }
Пример #14
0
        public void RunProblem()
        {
            var temp = PrisonAfterNDays(new int[] { 0, 1, 0, 1, 1, 0, 0, 1 }, 7);

            if (!ProblemHelper.ArrayIsEqual(new int[] { 0, 0, 1, 1, 0, 0, 0, 0 }, temp))
            {
                throw new Exception();
            }

            temp = PrisonAfterNDays(new int[] { 1, 0, 0, 1, 0, 0, 1, 0 }, 1000000000);
            if (!ProblemHelper.ArrayIsEqual(new int[] { 0, 0, 1, 1, 1, 1, 1, 0 }, temp))
            {
                throw new Exception();
            }
        }
Пример #15
0
        public void RunProblem()
        {
            var temp = FindAnagrams("cbaebabacd", "abc");

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 0, 6 }))
            {
                throw new Exception();
            }

            temp = FindAnagrams("abab", "ab");
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 0, 1, 2 }))
            {
                throw new Exception();
            }
        }
Пример #16
0
        public void RunProblem()
        {
            var temp = CircularPermutation(2, 3);

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 3, 2, 0, 1 }))
            {
                throw new Exception();
            }

            temp = CircularPermutation(3, 2);
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 2, 6, 7, 5, 4, 0, 1, 3 }))
            {
                throw new Exception();
            }
        }
Пример #17
0
        public void RunProblem()
        {
            var temp = Intersect(new int[] { 1, 2, 2, 1 }, new int[] { 2, 2 });

            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 2, 2 }))
            {
                throw new Exception();
            }

            temp = Intersect(new int[] { 4, 9, 5 }, new int[] { 9, 4, 9, 8, 4 });
            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 4, 9 }))
            {
                throw new Exception();
            }
        }
Пример #18
0
        public void RunProblem()
        {
            var temp = MaxSlidingWindow(new[] { 1, 3, -1, -3, 5, 3, 6, 7 }, 3);

            if (!ProblemHelper.ArrayEqual(temp, new[] { 3, 3, 5, 5, 6, 7 }))
            {
                throw new Exception();
            }

            temp = MaxSlidingWindow(new[] { 7, 2, 4 }, 2);
            if (!ProblemHelper.ArrayEqual(temp, new[] { 7, 4 }))
            {
                throw new Exception();
            }
        }
Пример #19
0
        public void RunProblem()
        {
            var temp = HitBricks(new int[][]
            {
                new int[] { 1, 0, 0, 0 },
                new int[] { 1, 1, 1, 0 }
            },
                                 new int[][]
            {
                new int[] { 1, 0 }
            });

            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 2 }))
            {
                throw new Exception();
            }

            temp = HitBricks(new int[][]
            {
                new int[] { 1, 0, 0, 0 },
                new int[] { 1, 1, 0, 0 }
            },
                             new int[][]
            {
                new int[] { 1, 1 },
                new int[] { 1, 0 }
            });
            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 0, 0 }))
            {
                throw new Exception();
            }

            temp = HitBricks(new int[][]
            {
                new int[] { 1, 0, 1 },
                new int[] { 1, 1, 1 }
            },
                             new int[][]
            {
                new int[] { 0, 0 },
                new int[] { 0, 2 },
                new int[] { 1, 1 }
            });
            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 0, 3, 0 }))
            {
                throw new Exception();
            }
        }
Пример #20
0
        public void RunProblem()
        {
            var temp = PowerfulIntegers(2, 3, 10);

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 2, 3, 4, 5, 7, 9, 10 }))
            {
                throw new Exception();
            }

            temp = PowerfulIntegers(3, 5, 15);
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 2, 4, 6, 8, 10, 14 }))
            {
                throw new Exception();
            }

            temp = PowerfulIntegers(2, 1, 10);
        }
Пример #21
0
        public void RunProblem()
        {
            var temp = TopKFrequent(new int[] { 1, 1, 1, 2, 2, 3 }, 2);

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 1, 2 }))
            {
                throw new Exception();
            }

            temp = TopKFrequent(new int[] { 1 }, 1);
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { 1 }))
            {
                throw new Exception();
            }

            temp = TopKFrequent(new int[] { -1, -1 }, 1);
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new int[] { -1 }))
            {
                throw new Exception();
            }
        }
Пример #22
0
        public void RunProblem()
        {
            var temp = PrintVertically("HOW ARE YOU");

            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new string[] { "HAY", "ORO", "WEU" }))
            {
                throw new Exception();
            }

            temp = PrintVertically("TO BE OR NOT TO BE");
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new string[] { "TBONTB", "OEROOE", "   T" }))
            {
                throw new Exception();
            }

            temp = PrintVertically("CONTEST IS COMING");
            if (!ProblemHelper.ArrayIsEqual(temp.ToArray(), new string[] { "CIC", "OSO", "N M", "T I", "E N", "S G", "T" }))
            {
                throw new Exception();
            }
        }
Пример #23
0
        public void RunProblem()
        {
            var temp = ArrayRankTransform(new int[] { 40, 10, 20, 30 });

            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 4, 1, 2, 3 }, false))
            {
                throw new Exception();
            }

            temp = ArrayRankTransform(new int[] { 100, 100, 100 });
            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 1, 1, 1 }, false))
            {
                throw new Exception();
            }

            temp = ArrayRankTransform(new int[] { 37, 12, 28, 9, 100, 56, 80, 5, 12 });
            if (!ProblemHelper.ArrayIsEqual(temp, new int[] { 5, 3, 4, 2, 8, 6, 7, 1, 3 }, false))
            {
                throw new Exception();
            }
        }
Пример #24
0
        private void ArrayEqualTest()
        {
            var a1 = new[] { 1, 2, 3, 4 };
            var a2 = new[] { 3, 4, 1, 2 };

            var temp = ProblemHelper.ArrayEqual(a1, a2);

            var b1 = new List <int>()
            {
                '1', '2', '4', '6'
            };
            var b2 = new List <int>()
            {
                '1', '2', '4', '6'
            };

            temp = ProblemHelper.ArrayEqual(b1, b2, false);

            var c1 = new[] { 'a', 'b', 'c' };
            var c2 = new[] { 'b', 'a', 'c' };

            temp = ProblemHelper.ArrayEqual(c1, c2, false);
            temp = ProblemHelper.ArrayEqual(c1, c2);
        }
Пример #25
0
 private void GetPrimeSetTest()
 {
     var temp = ProblemHelper.GetPrimeSet(100);
 }
Пример #26
0
        private void AssertEqualTest()
        {
            ProblemHelper.AEqual(5, 5);

            ProblemHelper.AEqual(5, 6);
        }