예제 #1
0
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                return(View["index.cshtml"]);
            };

            Get["/results"] = _ =>
            {
                return(View["results.cshtml"]);
            };

            Get["/new"] = _ =>
            {
                return(View["index.cshtml"]);
            };

            Post["/results"] = _ =>
            {
                Dictionary <string, string> newDictionary = new Dictionary <string, string>();
                string        userSentence = Request.Form["sentence"];
                string        userWord     = Request.Form["word"];
                RepeatCounter newCounter   = new RepeatCounter(userSentence, userWord);
                int           result       = newCounter.CountRepeats(userSentence, userWord);
                newDictionary.Add("count", result.ToString());
                newDictionary.Add("sentence", newCounter.GetSentence());
                newDictionary.Add("word", newCounter.GetWord());

                // int result = newCounter.CountRepeats(userSentence, userWord);
                return(View["results.cshtml", newDictionary]);
            };
        }
예제 #2
0
 public HomeModule()
 {
     Get["/"]        = _ => View["index.cshtml"];
     Post["/answer"] = _ => {
         RepeatCounter newCounter = new RepeatCounter();
         int           answer     = newCounter.CountRepeats(Request.Form["look-word"], Request.Form["sentence"]);
         return(View["answer.cshtml", answer]);
     };
 }
예제 #3
0
        public void CountRepeats_wordMatchWithOtherWords_True()
        {
            //arrange
            RepeatCounter testObject = new RepeatCounter();
            //act
            int answer = testObject.CountRepeats("zoo", "zoo was a very cool zoo");

            //assert
            Assert.Equal(answer, 2);
        }
예제 #4
0
        public void CountRepeats_wordMatch_True()
        {
            //arrange
            RepeatCounter testObject = new RepeatCounter();
            //act
            int answer = testObject.CountRepeats("zoo", "zoo");

            //assert
            Assert.Equal(answer, 1);
        }
예제 #5
0
        public void CountRepeats_lettersDontMatch_True()
        {
            //arrange
            RepeatCounter testObject = new RepeatCounter();
            //act
            int answer = testObject.CountRepeats("z", "y");

            //assert
            Assert.Equal(answer, 0);
        }
        public void CountRepeats_ReturnNumberOfTimesWordAppears_Int()
        {
            //arrange
            int    expectedOutput = 1;
            string givenWord      = "the";
            string givenString    = "Here rests the old oak tree";
            //act
            RepeatCounter testCounter = new RepeatCounter(givenWord, givenString);

            //assert
            Assert.Equal(expectedOutput, testCounter.CountRepeats());
        }
예제 #7
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Post["/counted-words"] = _ => {
                RepeatCounter wordCount    = new RepeatCounter(Request.Form["word"], Request.Form["text"]);
                int           countedWords = wordCount.CountRepeats();
                return(View["index.cshtml", countedWords]);
            };
        }
        public void CountRepeats_FindMatchesRegardlessOfPunctuation_Int()
        {
            //arrange
            int    expectedOutput = 1;
            string givenWord      = "man";
            string givenString    = "When the baby grows up to be an old man, they bury his body in the ground.";
            //act
            RepeatCounter testCounter = new RepeatCounter(givenWord, givenString);

            //assert
            Assert.Equal(expectedOutput, testCounter.CountRepeats());
        }
        public void CountRepeats_FindMatchesRegardlessOfExtraSpacesInWord_Int()
        {
            //arrange
            int    expectedOutput = 1;
            string givenWord      = "this ";
            string givenString    = "This house is haunted";
            //act
            RepeatCounter testCounter = new RepeatCounter(givenWord, givenString);

            //assert
            Assert.Equal(expectedOutput, testCounter.CountRepeats());
        }
예제 #10
0
        public void Test_CountLikeWordsInText_8()
        {
            //Arrange
            string inputWord = "buffalo";
            string inputText = "The buffalo is large. Buffalo is my name. The buffalo is large. Buffalo is my name. The buffalo is large. Buffalo is my name. The buffalo is large. Buffalo is my name. Buffalo's Rock!";

            //Act
            RepeatCounter testInput  = new RepeatCounter(inputWord, inputText);
            int           testResult = testInput.CountRepeats();

            //Assert
            Assert.Equal(8, testResult);
        }
예제 #11
0
        public void CountRepeats_MultiWordsMultiCount_two()
        {
            //Arrange
            string        sentInput  = "monkeys like to eat bananas for breakfast and bananas for dinner";
            string        wordInput  = "bananas";
            RepeatCounter newCounter = new RepeatCounter(sentInput, wordInput);

            //Act
            int result = newCounter.CountRepeats(sentInput, wordInput);

            //Assert
            Assert.Equal(2, result);
        }
예제 #12
0
        public void CountRepeats_SingleWord_one()
        {
            //Arrange
            string        sentInput  = "bananas";
            string        wordInput  = "bananas";
            RepeatCounter newCounter = new RepeatCounter(sentInput, wordInput);

            //Act
            int result = newCounter.CountRepeats(sentInput, wordInput);

            //Assert
            Assert.Equal(1, result);
        }
예제 #13
0
        public void CountRepeats_Punctuation_one()
        {
            //Arrange
            string        sentInput  = "monkeys like to eat bananas.";
            string        wordInput  = "Bananas";
            RepeatCounter newCounter = new RepeatCounter(sentInput, wordInput);

            //Act
            int result = newCounter.CountRepeats(sentInput, wordInput);

            //Assert
            Assert.Equal(1, result);
        }
예제 #14
0
        public void CountRepeats_MultiWordsCaseInsensitive_one()
        {
            //Arrange
            string        sentInput  = "monkeys like to eat bananas";
            string        wordInput  = "Bananas";
            RepeatCounter newCounter = new RepeatCounter(sentInput, wordInput);

            //Act
            int result = newCounter.CountRepeats(sentInput, wordInput);

            //Assert
            Assert.Equal(1, result);
        }
예제 #15
0
        public void Test_StringEqual_1()
        {
            //Arrange
            string inputWord = "A";
            string inputText = "A";

            //ACT
            RepeatCounter testInput  = new RepeatCounter(inputWord, inputText);
            int           testResult = testInput.CountRepeats();

            //Assert
            Assert.Equal(testResult, 1);
        }
예제 #16
0
        public void CountRepeats_MultiWordsCloseMatchError_zero()
        {
            //Arrange
            string        sentInput  = "monkeys like to eat bananas";
            string        wordInput  = "banana";
            RepeatCounter newCounter = new RepeatCounter(sentInput, wordInput);

            //Act
            int result = newCounter.CountRepeats(sentInput, wordInput);

            //Assert
            Assert.Equal(0, result);
        }
예제 #17
0
        public void Test_StringCompareEqualCaseless_1()
        {
            //Arrange
            string inputWord = "buffalo";
            string inputText = "BuFFalO";

            //Act
            RepeatCounter testInput  = new RepeatCounter(inputWord, inputText);
            int           testResult = testInput.CountRepeats();

            //Assert
            Assert.Equal(testResult, 1);
        }