Ejemplo n.º 1
0
    def test_editing_should_replace_erased_word_with_new_text(self):
        pencil = Pencil()

        pencil.write(self.paper, "An       a day keeps the doctor away")
        pencil.edit(self.paper, "onion")

        self.assertEqual("An onion a day keeps the doctor away", self.paper.read())
Ejemplo n.º 2
0
def test_once_sharpened_to_length_0_it_does_not_restore_point_durability():
    pencil = Pencil(5, 1)
    assert pencil.write('Texts') == 'Text '
    pencil.sharpen()
    assert pencil.write('Texts') == 'Text '
    pencil.sharpen()
    assert pencil.write('Texts') == '     '
Ejemplo n.º 3
0
    def test_when_new_word_is_too_long_it_should_replace_characters_with_at_symbol(self):
        pencil = Pencil()

        pencil.write(self.paper, "An       a day keeps the doctor away")
        pencil.edit(self.paper, "artichoke")

        self.assertEqual("An artich@k@ay keeps the doctor away", self.paper.read())
Ejemplo n.º 4
0
    def test_pencil_should_write_text(self):
        pencil = Pencil()

        text = "What possessed the first man to ride a horse?"
        pencil.write(self.paper, text)

        self.assertEqual(text, self.paper.read())
Ejemplo n.º 5
0
    def test_when_new_word_goes_beyond_end_of_paper_it_should_be_appended_to_the_end(self):
        pencil = Pencil()

        pencil.write(self.paper, "A short phrase")
        pencil.erase(self.paper, "phrase")
        pencil.edit(self.paper, "sentence")

        self.assertEqual("A short sentence", self.paper.read())
Ejemplo n.º 6
0
    def test_pencil_cannot_be_sharpened_past_its_length(self):
        pencil = Pencil(point_durability=1, length=2)

        for c in "text":
            pencil.write(self.paper, c)
            pencil.sharpen()

        self.assertEqual("tex ", self.paper.read())
Ejemplo n.º 7
0
def test_write_throws_when_given_non_string_text():
    pencil = Pencil()
    raisedException = False
    try:
        pencil.write(7)
    except ValueError:
        raisedException = True
    assert (raisedException)
Ejemplo n.º 8
0
    def test_when_pencil_is_sharpened_it_regains_full_durability(self):
        pencil = Pencil(point_durability=4)

        pencil.write(self.paper, "text")
        pencil.sharpen()
        pencil.write(self.paper, "texts")

        self.assertEqual("texttext ", self.paper.read())
Ejemplo n.º 9
0
 def test_whitespaceDoesntDepleteErasers(self):
     p = Pencil(length=40, pointDurability=1000, eraserDurability=5)
     p.write("last on last night's schedule was immigration law")
     p.erase(" was ")
     self.assertTrue(
         p.getText() == "last on last night's schedule     immigration law")
     p.erase("la")
     self.assertTrue(
         p.getText() == "last on last night's schedule     immigration   w")
Ejemplo n.º 10
0
 def test_erasersWearOut(self):
     p = Pencil(length=40, pointDurability=1000, eraserDurability=2)
     p.write("last on last night's schedule was immigration law")
     p.erase("la")
     self.assertTrue(
         p.getText() == "last on last night's schedule was immigration   w")
     p.erase("la")
     self.assertTrue(
         p.getText() == "last on last night's schedule was immigration   w")
Ejemplo n.º 11
0
 def test_erasingTextReplacesItsLastOccurrenceWithSpaces(self):
     p = Pencil(length=40, pointDurability=1000, eraserDurability=200)
     p.write("last on last night's schedule was immigration law")
     p.erase("la")
     self.assertTrue(
         p.getText() == "last on last night's schedule was immigration   w")
     p.erase("la")
     self.assertTrue(
         p.getText() == "last on   st night's schedule was immigration   w")
    def test_when_pencil_eraser_degrades_fully_it_should_stop_erasing(self):
        eraser = Eraser(durability=4)
        pencil = Pencil(eraser=eraser)

        pencil.write(self.paper, "I am related to Buffalo Bill")
        pencil.erase(self.paper, "Bill")
        pencil.erase(self.paper, "Buffalo")

        self.assertEqual("I am related to Buffalo     ", self.paper.read())
    def test_erasing_should_erase_opposite_direction_of_the_written_order(
            self):
        eraser = Eraser(durability=3)
        pencil = Pencil(eraser=eraser)

        pencil.write(self.paper, "I am related to Buffalo Bill")
        pencil.erase(self.paper, "Bill")

        self.assertEqual("I am related to Buffalo B   ", self.paper.read())
    def test_when_the_word_to_be_erased_is_not_found_nothing_should_be_erased(
            self):
        eraser = Eraser()
        pencil = Pencil(eraser=eraser)

        text = "Nothing to erase here"
        pencil.write(self.paper, text)
        pencil.erase(self.paper, "Something")

        self.assertEqual(text, self.paper.read())
Ejemplo n.º 15
0
    def test_when_pencil_writes_additional_text_it_should_append_to_existing_text(self):
        pencil = Pencil()

        text_part_a = "I'm not the kind of man "
        text_part_b = "who can just walk into a bouncy castle."

        pencil.write(self.paper, text_part_a)
        pencil.write(self.paper, text_part_b)

        expected = text_part_a + text_part_b

        self.assertEqual(expected, self.paper.read())
Ejemplo n.º 16
0
 def test_aPencilWritesBlanksAfterPointLosesDurability(self):
     p = Pencil(length=40, pointDurability=4, eraserDurability=200)
     p.write("ambidextrous")
     self.assertTrue(p.getText() == "ambi        ")
Ejemplo n.º 17
0
def test_dulling(char, value):
    paper = Paper()
    pencil = Pencil()
    pencil.write(paper, char)
    assert pencil.point == value
Ejemplo n.º 18
0
 def test_textIsErasedFromTheRight(self):
     p = Pencil(length=40, pointDurability=1000, eraserDurability=5)
     p.write("a Kafkaesque bureaucracy")
     p.erase("Kafkaesque")
     self.assertTrue(p.getText() == "a Kafka      bureaucracy")
Ejemplo n.º 19
0
 def test_aSharpenedPencilCanWriteAgain(self):
     p = Pencil(length=40, pointDurability=4, eraserDurability=200)
     p.write("ambi")
     p.sharpen()
     p.write("dextrous")
     self.assertTrue(p.getText() == "ambidext    ")
Ejemplo n.º 20
0
 def test_editingOverwritesErasedText(self):
     p = Pencil(length=40, pointDurability=1000, eraserDurability=200)
     p.write("An apple a day keeps the doctor away")
     p.erase("apple")
     p.overwrite("onion")
     self.assertTrue(p.getText() == "An onion a day keeps the doctor away")
Ejemplo n.º 21
0
 def test_aPencilWithSufficientlyDurablePointCanWrite(self):
     p = Pencil(length=40, pointDurability=1000, eraserDurability=200)
     text = "Four score and seven years ago"
     p.write(text)
     self.assertTrue(p.getText() == text)
Ejemplo n.º 22
0
def test_dulling_with_writing(text, output_value):
    paper = Paper()
    pencil = Pencil(point_value=4)
    pencil.write(paper, text)
    assert paper.buffer == output_value
Ejemplo n.º 23
0
 def test_editingMarksCollisionsWithNonSpaceWithAt(self):
     p = Pencil(length=40, pointDurability=1000, eraserDurability=200)
     p.write("An apple a day keeps the doctor away")
     p.erase("apple")
     p.overwrite("artichoke")
     self.assertTrue(p.getText() == "An artich@k@ay keeps the doctor away")
Ejemplo n.º 24
0
 def test_when_pencil_writes_whitespace_it_should_not_degrade(self):
     pencil = Pencil(point_durability=4)
     text = """a b 
               c d"""
     pencil.write(self.paper, text)
     self.assertEqual(text, self.paper.read())
Ejemplo n.º 25
0
 def test_when_pencil_writes_uppercase_letters_it_should_degrade_by_two(self):
     pencil = Pencil(point_durability=4)
     pencil.write(self.paper, "Text")
     self.assertEqual("Tex ", self.paper.read())
Ejemplo n.º 26
0
 def test_when_pencil_writes_lowercase_letters_it_should_degrade_by_one(self):
     pencil = Pencil(point_durability=2)
     pencil.write(self.paper, "text")
     self.assertEqual("te  ", self.paper.read())
Ejemplo n.º 27
0
 def test_when_pencil_is_completely_dull_it_should_write_spaces(self):
     pencil = Pencil(point_durability=0)
     pencil.write(self.paper, "text")
     self.assertEqual("    ", self.paper.read())
Ejemplo n.º 28
0
def test_can_be_sharpened_to_regain_point_durability():
    pencil = Pencil(5)
    assert pencil.write('string') == 'strin '
    pencil.sharpen()
    assert pencil.write('text') == 'text'
Ejemplo n.º 29
0
def test_writing():
    paper = Paper("She sells sea shells")
    pencil = Pencil()
    pencil.write(paper, " by the sea shore")
    assert paper.buffer == "She sells sea shells by the sea shore"
Ejemplo n.º 30
0
def test_writing_whitespace_escape_chars_does_not_degrade_point():
    pencil = Pencil(5)
    assert pencil.write('\n\t\v\f\r   string') == '\n\t\v\f\r   strin '