public void GetLongestWords_ThreeWordsTwoSentences()
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("hi world");
            finder.AddSentence("win");
            Assert.AreEqual(new [] { "world" }, finder.GetLongestWords().ToArray());
        }
        public void GetShortestWords_TwoWordsHavingDifferentLen()
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("hi world");
            Assert.AreEqual(new [] { "hi" }, finder.GetShortestWords().ToArray());
        }
        public void GetShortestWords_SingleWord()
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("hi");
            Assert.AreEqual(new [] { "hi" }, finder.GetShortestWords().ToArray());
        }
        public void GetShortestWords_EmptyString()
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("");
            Assert.AreEqual(new string[] {}, finder.GetShortestWords().ToArray());
        }
        public void GetLongestWords_TwoWordsHavingSameLenAndManySpaces()
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("  hello     world    ");
            Assert.AreEqual(new [] { "hello", "world" }, finder.GetLongestWords().ToArray());
        }
        public void GetLongestWords_TwoWordsHavingSameLenAndReverseOrder()
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("world hello");
            Assert.AreEqual(new [] { "world", "hello" }, finder.GetLongestWords().ToArray());
        }
        public void GetLongestWords_TwoEqualWords()
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("hi hi");
            Assert.AreEqual(new [] { "hi" }, finder.GetLongestWords().ToArray());
        }
Пример #8
0
        static void Main(string[] args)
        {
            var finder = new MinMaxWordFinder();

            finder.AddSentence("hello abc world");
            finder.AddSentence("def asdf qwert");
            Console.WriteLine(string.Join(", ", finder.GetShortestWords()));            // abc, def
            Console.WriteLine(string.Join(", ", finder.GetLongestWords()));             // hello, qwert, world

            finder.AddSentence("  abc     table    ");
            finder.AddSentence("world");
            finder.AddSentence("def");
            Console.WriteLine(string.Join(", ", finder.GetShortestWords()));            // abc, def
            Console.WriteLine(string.Join(", ", finder.GetLongestWords()));             // hello, qwert, table, world

            finder.AddSentence("pool");
            finder.AddSentence("people");
            Console.WriteLine(string.Join(", ", finder.GetShortestWords()));            // abc, def
            Console.WriteLine(string.Join(", ", finder.GetLongestWords()));             // people

            Console.ReadLine();
        }