Ejemplo n.º 1
0
        public void TestEraserRemovesWordAsEntered()
        {
            // Act
            paper.Text += pencil.Write(testSentence);
            paper.Text  = eraser.Erase(testWord, paper.Text);

            // Assert
            Assert.AreEqual(testSentenceWithWhiteSpace, paper.Text, "Test sentence should match paper text, eraser should remove entered word");
        }
Ejemplo n.º 2
0
        public void EraseWhiteSpaceHasNoCost()
        {
            var eraser        = new Eraser(1);
            var stringBuilder = new StringBuilder();

            stringBuilder.Append(eraser.Erase(' '));
            stringBuilder.Append(eraser.Erase('j'));
            stringBuilder.Append(eraser.Erase(' '));

            Assert.Equal("   ", stringBuilder.ToString());
        }
        /// <summary>
        ///     Erases the types in <paramref name="vc" /> (if program is polymorphic) and sort let binding.
        ///     Note that this has a side-effect on <paramref name="vc" />..
        /// </summary>
        public VCExpr EraseAndSortLet(VCExpr vc, int polarity = -1)
        {
            var exprWithoutTypes = ProgramIsPolymorphic ? Eraser.Erase(vc, polarity) : vc;
            var letSorter        = new LetBindingSorter(_vcExprGen);

            Contract.Assert(letSorter != null);
            return(letSorter.Mutate(exprWithoutTypes, true));
        }
Ejemplo n.º 4
0
        public void WhenCurrentDurabilityIsZeroEraseMethodWillStopErasing()
        {
            Pencil pencil = new Pencil(20, 5);
            Paper  paper  = new Paper();
            Eraser eraser = new Eraser(5);

            pencil.Write("hello world!", paper);
            eraser.Erase("hello world!", paper);

            Assert.AreEqual("hello w     ", paper.Text);
        }
Ejemplo n.º 5
0
        public void WhenEraseMethodCalledEraserDurabilityDecreasesByOneForNonSpaceCharacters()
        {
            Pencil pencil = new Pencil(20, 5);
            Paper  paper  = new Paper();
            Eraser eraser = new Eraser(20);

            pencil.Write("hello world!", paper);
            eraser.Erase("hello world!", paper);

            Assert.AreEqual(9, eraser.CurrentDurability);
        }
Ejemplo n.º 6
0
        public void WhenEraseMethodCalledRemovesLastInstanceOfParameterString()
        {
            Pencil pencil = new Pencil(20, 20);
            Paper  paper  = new Paper();
            Eraser eraser = new Eraser(20);

            pencil.Write("Hello World!", paper);
            eraser.Erase("World", paper);

            Assert.AreEqual("Hello      !", paper.Text);
        }
Ejemplo n.º 7
0
        public void WhenEditMethodCalledAddsCharsAtIndexWithoutCollision()
        {
            Pencil pencil = new Pencil(500, 5);
            Paper  paper  = new Paper();
            Eraser eraser = new Eraser(20);

            pencil.Write("Hello World", paper);
            eraser.Erase("World", paper);
            pencil.Edit("Howdy", paper);

            Assert.AreEqual("Hello Howdy", paper.Text);
        }
Ejemplo n.º 8
0
        public void WhenEditMethodCalledIfOverwriteCharIsSpaceDoNotReplaceOriginalChar()
        {
            Pencil pencil = new Pencil(500, 5);
            Paper  paper  = new Paper();
            Eraser eraser = new Eraser(20);

            pencil.Write("Hello World", paper);
            eraser.Erase("Wor", paper);
            pencil.Edit("hey u", paper);

            Assert.AreEqual("Hello heyl@", paper.Text);
        }
Ejemplo n.º 9
0
        public void WhenEditMethodCalledIfCharsCollideExistingCharOverwrittenWithSpecialChar()
        {
            Pencil pencil = new Pencil(500, 5);
            Paper  paper  = new Paper();
            Eraser eraser = new Eraser(20);

            pencil.Write("Hello World", paper);
            eraser.Erase("lo", paper);
            pencil.Edit("Howdy", paper);

            Assert.AreEqual("HelHow@@rld", paper.Text);
        }
Ejemplo n.º 10
0
        public void EraseReturnsAllCharacters()
        {
            var eraser        = new Eraser(1000);
            var stringBuilder = new StringBuilder();

            for (var i = 0; i < 5; i++)
            {
                stringBuilder.Append(eraser.Erase('J'));
            }

            Assert.Equal("     ", stringBuilder.ToString());
        }
Ejemplo n.º 11
0
        public void EraseReturnsAllWhiteSpace()
        {
            var eraser        = new Eraser(0);
            var stringBuilder = new StringBuilder();

            for (var i = 0; i < 5; i++)
            {
                stringBuilder.Append(eraser.Erase('j'));
            }

            Assert.Equal("jjjjj", stringBuilder.ToString());
        }
Ejemplo n.º 12
0
 public PaperModel UseEraser(string input, PaperModel paper)
 {
     paper = Eraser.Erase(input, paper);
     IndexOfLastErasedWord = paper.SpaceWhereErasedWordWas;
     return(paper);
 }