Example #1
0
 def test_sharpen_pencil_decrease_length_by_one(self):
     p = Pencil(pencilLength=4, eraserDurability=4)
     new_text = p.pencil_write('abcdef')
     self.assertEqual(p.pointDurability, 39994)
     p.pencil_sharpen()
     self.assertEqual(p.pointDurability, 40000)
     self.assertEqual(p.pencilLength, 3)
class Write():
    def __init__(self):
        self.pencil = Pencil(pencilLength=4, eraserDurability=10)
        self.paper = ''

    def write_on_paper(self, desired_text_to_write):
        text_to_write = self.pencil.pencil_write(desired_text_to_write)
        self.paper += text_to_write

    def sharpen_pencil(self):
        self.pencil.pencil_sharpen()

    def erase(self, desired_text_to_erase):
        text_to_erase = self.pencil.pencil_erase(
            text_to_erase=desired_text_to_erase)
        index = self.paper.rfind(desired_text_to_erase)
        self.paper = self.paper[:index] + text_to_erase + self.paper[
            index + len(text_to_erase):]
        return index

    def edit(self, index, text_to_add):
        current_text = self.paper[index:index + len(text_to_add)]
        for i in range(0, len(text_to_add)):
            if current_text[i] != text_to_add[i]:
                if not current_text[i].isspace(
                ) and not text_to_add[i].isspace():
                    text_to_add = text_to_add[:i] + '@' + text_to_add[i + 1:]
                else:
                    text_to_add = text_to_add[:i] + text_to_add[
                        i] + text_to_add[i + 1:]
        text_to_write = self.pencil.pencil_write(text_to_add)
        self.paper = self.paper[:index] + text_to_write + self.paper[
            index + len(text_to_add):]
Example #3
0
 def test_sharpen_pencil_by_five_decrease_length_by_four_set_pencil_durability_to_zero(
         self):
     p = Pencil(pencilLength=4, eraserDurability=4)
     p.pencil_sharpen()
     p.pencil_sharpen()
     p.pencil_sharpen()
     p.pencil_sharpen()
     p.pencil_sharpen()
     self.assertEqual(p.pencilLength, 0)
     self.assertEqual(p.pointDurability, 0)