Beispiel #1
0
        public static void Loop()
        {
            Console.WriteLine("Please enter a block of text you'd like me to analyze:");
            string userPhrase = Console.ReadLine();

            Console.WriteLine("What word should I search for in this text?");
            string          userWord        = Console.ReadLine();
            WordCounterCalc wordCounterCalc = new WordCounterCalc(userWord, userPhrase);

            wordCounterCalc.PhraseContains();
            int count = wordCounterCalc.Count;

            if (count > 0)
            {
                Console.WriteLine("I found that word in the text. Count: " + count);
            }
            else
            {
                Console.WriteLine("I'm sorry, I couldn't find that word in the text");
            }
            Console.WriteLine("Would you like to try again? [Y/N]");
            string userResponse = Console.ReadLine();

            if (userResponse.ToLower() == "y" || userResponse.ToLower() == "yes")
            {
                Loop();
            }
        }
Beispiel #2
0
        public void PhraseContains_ReturnsWhetherPhraseContainsWord_BoolFalse()
        {
            // Arrange
            WordCounterCalc wordCounter = new WordCounterCalc("this", "that place");
            // Act
            bool actual = wordCounter.PhraseContains();

            // Assert
            Assert.AreEqual(false, actual);
        }
Beispiel #3
0
        public void WordMatch_ReturnsWhetherPhraseMatchesWord_BoolFalse()
        {
            // Arrange
            WordCounterCalc wordCounter = new WordCounterCalc("hat", "pat");
            // Act
            bool actual = wordCounter.WordMatch("hat", "pat");

            // Assert
            Assert.AreEqual(false, actual);
        }
Beispiel #4
0
        public void CharacterCleaner_IgnoresSpecialCharacters_StringCant()
        {
            // Arrange
            WordCounterCalc wordCounter = new WordCounterCalc("", "");
            // Act
            string actual = wordCounter.CharacterCleaner("can't");

            // Assert
            Assert.AreEqual("cant", actual);
        }
Beispiel #5
0
        public void WordMatch_AccountsForCapitals_Int2()
        {
            // Arrange
            WordCounterCalc wordCounter = new WordCounterCalc("an", "An apple and an orange");

            // Act
            wordCounter.PhraseContains();
            int actual = wordCounter.Count;

            // Assert
            Assert.AreEqual(2, actual);
        }
Beispiel #6
0
        public void PhraseContains_CountValueIgnoresPartialMatches_Int2()
        {
            // Arrange
            WordCounterCalc wordCounter = new WordCounterCalc("an", "an apple and an orange");

            // Act
            wordCounter.PhraseContains();
            int actual = wordCounter.Count;

            // Assert
            Assert.AreEqual(2, actual);
        }
Beispiel #7
0
        public void PhraseContains_CountValueisIncreasedByMatches_Int2()
        {
            // Arrange
            WordCounterCalc wordCounter = new WordCounterCalc("an", "an apple, an orange");

            // Act
            wordCounter.PhraseContains();
            int actual = wordCounter.Count;

            // Assert
            Assert.AreEqual(2, actual);
        }
Beispiel #8
0
        public void CharacterCleaner_IgnoresSpecialCharacters_Int1()
        {
            // Arrange
            WordCounterCalc wordCounter = new WordCounterCalc("cant", "I can't");

            // Act
            wordCounter.PhraseContains();
            int actual = wordCounter.Count;

            // Assert
            Assert.AreEqual(1, actual);
        }