public HomeModule() { Get["/"] = _ => { return View["index.html"]; }; Post["/result"] = _ => { RepeatCounter formRepeatCounter = new RepeatCounter(Request.Form["input-word"], Request.Form["input-list"]); string firstString = formRepeatCounter.GetStringOfWords(); string cleanString = formRepeatCounter.RemovePunctuation(firstString); string findWord = formRepeatCounter.GetWord(); int countWords = formRepeatCounter.CountRepeats(findWord, cleanString); return View["result.cshtml", formRepeatCounter]; }; Post["/warandpeace"] = _ => { RepeatCounter wapRepeatCounter = new RepeatCounter(Request.Form["input-word"], Request.Form["input-word"]); string readWarAndPeace = wapRepeatCounter.ReadAFile(); wapRepeatCounter.SetStringOfWords(readWarAndPeace); string firstString = wapRepeatCounter.GetStringOfWords(); string cleanString = wapRepeatCounter.RemovePunctuation(firstString); string findWord = wapRepeatCounter.GetWord(); int countWords = wapRepeatCounter.CountRepeats(findWord, cleanString); return View["warandpeace.cshtml", wapRepeatCounter]; }; }
public static void Main() { Console.Write("Enter a single word: "); string inputWord = Console.ReadLine(); RepeatCounter counter = new RepeatCounter(inputWord); Console.Write("Enter a series of words: "); string inputSentence = Console.ReadLine(); inputWord = counter.RemovePunctuation(inputWord); inputSentence = counter.RemovePunctuation(inputSentence); counter = new RepeatCounter(inputWord, inputSentence); if ((counter.StringCheck(counter.SingleWord)) && (counter.StringCheck(counter.MultipleWords)) && (counter.SpaceCheck(counter.SingleWord)) && (counter.LetterCheck(counter.MultipleWords))) { int countResult = counter.AddCount(counter.SplitString(counter.MultipleWords)); Console.WriteLine("Total matches: " + countResult); } else { Console.WriteLine("Please enter both a single word and a sentence."); Main(); } }
public void FindWord_FindsWordInStringOfMultipleWordsWithPunchtuation_ReturnsCountOfRepeatsRegardlessOfPunctuation() { // Arrange string inputWord = "actually"; string testWord = inputWord.ToUpper(); string testString = "An antelope is like a gazelle in a way but it begins with an A actually."; int testCount = 1; int resultCount = 0; RepeatCounter testRepeatCounter = new RepeatCounter(testWord, testString); string testCleanString = testRepeatCounter.RemovePunctuation(testString); // Act Console.WriteLine("Spec 7 pre-method-call resultCount value: " + resultCount); resultCount = testRepeatCounter.CountRepeats(testWord, testCleanString); // Assert Console.WriteLine("Spec 7 expected: " + testCount + " Spec 7 actual: " + resultCount); Assert.Equal(testCount, resultCount); }