예제 #1
0
 public static void EraseAWord(Pencil pencil, PaperModel paper)
 {
     Console.WriteLine(paper.WrittenContent);
     Console.WriteLine("What word would you like to erase?");
     pencil.UseEraser(Console.ReadLine(), paper);
     Console.WriteLine(paper.WrittenContent);
     ReplaceErasedWord(pencil, paper);
 }
예제 #2
0
        public void ErasingTheSameWordTwiceErasesTheLastTwoInstancesOfTheWord()
        {
            //Arrange
            PeacockQuill = new Pencil(1);
            Parchment    = new PaperModel()
            {
                WrittenContent = "wizarding world of wizards world"
            };
            var wordToBeRemoved = "world";
            var instacesOfWordAfterTwoRemovals = 0;

            //Act
            PeacockQuill.UseEraser(wordToBeRemoved, Parchment);
            PeacockQuill.UseEraser(wordToBeRemoved, Parchment);

            //Assert
            Assert.AreEqual(instacesOfWordAfterTwoRemovals, Regex.Matches(Parchment.WrittenContent, wordToBeRemoved).Count);
        }
예제 #3
0
        public void NoNewWordsMayBeErasedOnceEraserWornOut()
        {
            //Arrange
            PeacockQuill = new Pencil(0, 4);
            Parchment    = new PaperModel()
            {
                WrittenContent = "Maple syrup is tree marinade"
            };
            var firstWordToBeDeleted          = "tree";
            var secondWordToBeDeleted         = "Maple";
            var expectedInstancesOfFirstWord  = 0;
            var expectedInstancesOfSecondWord = 1;

            //Act
            PeacockQuill.UseEraser(firstWordToBeDeleted, Parchment);
            PeacockQuill.UseEraser(secondWordToBeDeleted, Parchment);

            //Assert
            Assert.AreEqual(expectedInstancesOfFirstWord, Regex.Matches(Parchment.WrittenContent, firstWordToBeDeleted).Count);
            Assert.AreEqual(expectedInstancesOfSecondWord, Regex.Matches(Parchment.WrittenContent, secondWordToBeDeleted).Count);
        }
예제 #4
0
        public void ProgramDoesntBreakIfWordToBeErasedDoesntExist()
        {
            //Arrange
            PeacockQuill = new Pencil(1);
            Parchment    = new PaperModel()
            {
                WrittenContent = "wizarding world of wizards world"
            };
            var wordToBeRemoved = "gopher";
            var instacesOfWordAfterTwoRemovals = 0;

            PeacockQuill.UseEraser(wordToBeRemoved, Parchment);

            //Assert
            Assert.AreEqual(instacesOfWordAfterTwoRemovals, Regex.Matches(Parchment.WrittenContent, wordToBeRemoved).Count);
        }
예제 #5
0
        public void ReplaceWordsInTheMiddleOfTheSentence()
        {
            //Arrange
            PeacockQuill = new Pencil(1);
            Parchment    = new PaperModel()
            {
                WrittenContent = "Better be Gryffidor"
            };
            var wordToRemove = "be";
            var instancesOfWordAfterRemoval = 0;

            //Act
            PeacockQuill.UseEraser(wordToRemove, Parchment);

            //Assert
            Assert.AreEqual(instancesOfWordAfterRemoval, Regex.Matches(Parchment.WrittenContent, wordToRemove).Count);
        }
예제 #6
0
        public void EraserWithZeroDurabilityDoesntErase()
        {
            //Arrange
            PeacockQuill = new Pencil(1, 0);
            Parchment    = new PaperModel()
            {
                WrittenContent = "Haha you can't erase me"
            };
            var wordToBeErased            = "me";
            var instancesOfWordToBeErased = 1;

            //Act
            PeacockQuill.UseEraser(wordToBeErased, Parchment);

            //Assert
            Assert.AreEqual(instancesOfWordToBeErased, Regex.Matches(Parchment.WrittenContent, wordToBeErased).Count);
        }
예제 #7
0
        public void RemoveLastInstanceOfGivenWord()
        {
            //Arrange
            PeacockQuill = new Pencil(1);
            Parchment    = new PaperModel()
            {
                WrittenContent = "I like coffee wakes me up makes me fast I love coffee"
            };
            var wordToRemove = "coffee";
            var numberOfCoffeesAfterEraser = 1;

            //Act
            PeacockQuill.UseEraser(wordToRemove, Parchment);

            //Assert
            Assert.AreEqual(numberOfCoffeesAfterEraser, Regex.Matches(Parchment.WrittenContent, wordToRemove).Count);
        }
예제 #8
0
        public void VerifyLowDurabilityErasesExpectedLetters()
        {
            //Arrange
            PeacockQuill = new Pencil(0, 2);
            Parchment    = new PaperModel()
            {
                WrittenContent = "You might know me"
            };
            var wordToBeErased = "know";
            var lettersLeftWhenEraserRunsOut = "kn  ";
            var expectedInstancesOfHalfWords = 1;

            //Act
            PeacockQuill.UseEraser(wordToBeErased, Parchment);

            //Assert
            Assert.AreEqual(expectedInstancesOfHalfWords, Regex.Matches(Parchment.WrittenContent, lettersLeftWhenEraserRunsOut).Count);
            Assert.AreNotEqual(expectedInstancesOfHalfWords, Regex.Matches(Parchment.WrittenContent, wordToBeErased).Count);
        }
예제 #9
0
        public void IndexOfLastWordErasedSavedAsClassProperty()
        {
            //Arrange
            var stringBeingWritten    = "This cantelope is tasty";
            var expectedIndexPosition = 5;
            var wordToBeDeleted       = "cantelope";

            NumberTwoPencil = new Pencil();
            Paper           = new PaperModel()
            {
                WrittenContent = stringBeingWritten
            };

            //Act
            NumberTwoPencil.UseEraser(wordToBeDeleted, Paper);

            //Assert
            Assert.AreEqual(expectedIndexPosition, NumberTwoPencil.IndexOfLastErasedWord);
        }
예제 #10
0
        public void ReplaceErasedWordWithWhiteSpace()
        {
            //Arrange
            PeacockQuill = new Pencil(1);
            Parchment    = new PaperModel()
            {
                WrittenContent = "Troll in the dungeon, thought you ought to know"
            };

            var wordToRemove             = "know";
            var newWhiteSpace            = "    ";
            var instancesOfNewWhiteSpace = 1;

            //Act
            PeacockQuill.UseEraser(wordToRemove, Parchment);

            //Assert
            Assert.AreEqual(instancesOfNewWhiteSpace, Regex.Matches(Parchment.WrittenContent, newWhiteSpace).Count);
            Assert.AreNotEqual(instancesOfNewWhiteSpace, Regex.Matches(Parchment.WrittenContent, wordToRemove).Count);
        }
예제 #11
0
        public void EraserWithDurabilityOfTwoErasesTwoLetters()
        {
            //Arrange
            PeacockQuill = new Pencil(1, 2);
            Parchment    = new PaperModel()
            {
                WrittenContent = "You don't know me"
            };
            var wordToBeErased = "me";
            var expectedInstancesOfDeletedWord = 0;
            var expectedEraserDurability       = 0;


            //Act
            PeacockQuill.UseEraser(wordToBeErased, Parchment);

            //Assert
            Assert.AreEqual(expectedInstancesOfDeletedWord, Regex.Matches(Parchment.WrittenContent, wordToBeErased).Count);
            Assert.AreEqual(expectedEraserDurability, PeacockQuill.Eraser.EraserDurability);
        }
예제 #12
0
        public void LettersOverlappedByReplacementWordReplacedWithSymbol()
        {
            //Arrange
            var stringBeingWritten = "This ham is tasty";
            var wordToBeDeleted    = "ham";
            var replacementWord    = "steak";
            var expectedNewString  = "This stea@s tasty";

            NumberTwoPencil = new Pencil();
            Paper           = new PaperModel()
            {
                WrittenContent = stringBeingWritten
            };

            //Act
            NumberTwoPencil.UseEraser(wordToBeDeleted, Paper);
            NumberTwoPencil.ReplaceErasedWord(replacementWord, Paper);

            //Assert
            StringAssert.AreEqualIgnoringCase(expectedNewString, Paper.WrittenContent);
        }
예제 #13
0
        public void ReplacementWordOfSameLengthTakesPlaceOfWhitespace()
        {
            //Arrange
            var stringBeingWritten = "This ham is tasty";
            var wordToBeDeleted    = "ham";
            var replacementWord    = "egg";
            var expectedNewString  = "This egg is tasty";

            NumberTwoPencil = new Pencil();
            Paper           = new PaperModel()
            {
                WrittenContent = stringBeingWritten
            };

            //Act
            NumberTwoPencil.UseEraser(wordToBeDeleted, Paper);
            NumberTwoPencil.ReplaceErasedWord(replacementWord, Paper);

            //Assert
            StringAssert.AreEqualIgnoringCase(expectedNewString, Paper.WrittenContent);
        }
예제 #14
0
        public void InsertWordAtStoredIndex()
        {
            //Arrange
            var stringBeingWritten    = "This ham is tasty";
            var expectedIndexPosition = 5;
            var wordToBeDeleted       = "ham";
            var replacementWord       = "egg";

            NumberTwoPencil = new Pencil();
            Paper           = new PaperModel()
            {
                WrittenContent = stringBeingWritten
            };

            //Act
            NumberTwoPencil.UseEraser(wordToBeDeleted, Paper);
            NumberTwoPencil.ReplaceErasedWord(replacementWord, Paper);

            //Assert
            Assert.AreEqual(expectedIndexPosition, Paper.WrittenContent.IndexOf(replacementWord));
        }