Exemple #1
0
 def test_that_pencil_not_dull_when_lower_case_text_len_is_less_than_point_durability(
         self):
     point_durability = 10
     pencil = Pencil(point_durability=point_durability)
     paper = Paper()
     pencil.write(paper, 'test')
     self.assertEqual(6, pencil.point_durability)
Exemple #2
0
 def test_that_pencil_not_dull_when_upper_case_text_should_not_use_up_point_durability(
         self):
     point_durability = 10
     pencil = Pencil(point_durability=point_durability)
     paper = Paper()
     pencil.write(paper, 'TEST')
     self.assertEqual(2, pencil.point_durability)
def testEraserDurabilityWhereWeCanEraseTheEntireWord():
    correctOutput = "She sells sea shells down by the     shore"
    pencil = Pencil()
    originalText = "She sells sea shells down by the sea shore"
    textToErase = "sea"
    assert correctOutput == pencil.erase(originalText, textToErase)
    assert pencil.eraserDurability == 97
Exemple #4
0
 def test_that_pencil_that_starts_dull_only_writes_empty_spaces(self):
     point_durability = 0
     pencil = Pencil(point_durability=point_durability)
     paper = Paper()
     pencil.write(paper, 'test')
     self.assertEqual('    ',
                      paper.display_page())  # paper should contain 4 spaces
Exemple #5
0
 def setUp(self):
     durability = 10
     self.eraser = Eraser(durability=durability)
     point_durability = 100
     initial_length = 5
     self.pencil = Pencil(point_durability=point_durability, initial_length=initial_length, eraser=self.eraser)
     self.paper = Paper()
 def __init__(self):
     self.pencil = Pencil()
     self.level = Level(1)
     self.affichage = Affichage()
     self.player = self.get_user()
     self.nb_python = 0
     self.db = Database()
Exemple #7
0
 def test_that_pencil_point_durability_does_not_change_for_newline_characters(
         self):
     point_durability = 10
     pencil = Pencil(point_durability=point_durability)
     paper = Paper()
     pencil.write(paper,
                  '\ntest\ntest\n\n\n')  # 4 newlines written to paper
     self.assertEqual(2, pencil.point_durability)
Exemple #8
0
 def test_that_pencil_point_durability_decrements_by_one_for_special_characters(
         self):
     point_durability = 30
     pencil = Pencil(point_durability=point_durability)
     paper = Paper()
     pencil.write(paper, '~!@#$%^&*()_+`-=:",./<>?{}[]|'
                  )  # 29 special chars written to paper
     self.assertEqual(1, pencil.point_durability)
def testWriteFunctionality():
    correctOutput = "She sells sea shells down by the sea shore"
    pencil = Pencil()
    currentSentenceOnPaper = "She sells sea shells"
    sentenceToWrite = " down by the sea shore"

    assert correctOutput == pencil.write(currentSentenceOnPaper,
                                         sentenceToWrite)
def testEditWhereWeInsertArtichokeInTheWhiteSpaceGap():
    originalText = "An       a day keeps the doctor away"
    replacingWord = "artichoke"
    correctOutput = "An artich@k@ay keeps the doctor away"
    replacingStartIndex = 3
    pencil = Pencil()
    assert correctOutput == pencil.edit(originalText, replacingWord,
                                        replacingStartIndex)
def testPencilDegradationWhereWeCantFinishASentence():
    correctOutput = "She sells sea shells down by the sea      "
    durability = 12
    pencil = Pencil(durability)
    currentSentenceOnPaper = "She sells sea shells"
    sentenceToWrite = " down by the sea shore"

    assert correctOutput == pencil.write(currentSentenceOnPaper,
                                         sentenceToWrite)
Exemple #12
0
 def test_that_pencil_that_becomes_dull_during_writing_writes_empty_spaces(
         self):
     point_durability = 4
     pencil = Pencil(point_durability=point_durability)
     paper = Paper()
     pencil.write(paper, 'Test')
     self.assertEqual(
         'Tes ',
         paper.display_page())  # paper should contain one space at end
def testEditWhereTheWhiteSpaceGapIsAtTheEndButTheReplacingWordIsTooLongForTheSentence(
):
    originalText = "The doctor fears the      ."
    replacingWord = "artichoke"
    correctOutput = "The doctor fears the artic@"
    replacingStartIndex = 21
    pencil = Pencil()
    assert correctOutput == pencil.edit(originalText, replacingWord,
                                        replacingStartIndex)
Exemple #14
0
    def test_eraser_cannot_erase_when_durability_zero(self):
        test_durability = 3
        self.pencil = Pencil(eraser_durability=test_durability)
        string_to_write = "wrist"
        string_to_erase = "wrist"

        self.pencil.write(self.paper, string_to_write)
        self.pencil.erase(self.paper, string_to_erase)

        self.assertEqual(self.paper.text.count(' '), test_durability)
def testEraserDurabilityWhereWeCantFinishErasingTheWord():
    correctOutput = "She sells sea shells down by the s   shore"
    leadDurability = 0
    pencilLength = 0
    eraserDurability = 2
    pencil = Pencil(leadDurability, pencilLength, eraserDurability)
    originalText = "She sells sea shells down by the sea shore"
    textToErase = "sea"
    assert correctOutput == pencil.erase(originalText, textToErase)
    assert pencil.eraserDurability == 0
def testWriteExtendedWithNewlineCharacters():
    exampleText1 = "I met a traveller from an antique land\n"
    exampleText2 = "Who said: Two vast and trunkless legs of stone\n"
    exampleText3 = "Stand in the desert..."
    correct = """I met a traveller from an antique land
Who said: Two vast and trunkless legs of stone
Stand in the desert..."""
    pencil = Pencil(durability=1000)
    out = pencil.write(exampleText1, exampleText2)
    out = pencil.write(out, exampleText3)
    assert correct == out
Exemple #17
0
    def test_pencil_sharpening_resets_point_durability(self):
        self.pencil = Pencil(10)
        number_of_characters = 10

        string_to_write = self.get_randomized_string(number_of_characters)

        self.pencil.write(self.paper, string_to_write)

        self.pencil.sharpen()

        self.assertEqual(self.pencil.start_point_durability,
                         self.pencil.point_durability)
Exemple #18
0
 def render(self, surface, start_draw_pos):
     GameEntity.render(self, surface, start_draw_pos)
     if self.mine < self.max_mine:
         x, y = self.location.x + start_draw_pos[
             0], self.location.y + start_draw_pos[1]
         w, h = self.image.get_size()
         text_x = x - 20
         text_y = y + h // 2
         Pencil.write_text(surface,
                           "%3d/%3d" % (self.mine, self.max_mine),
                           [text_x, text_y],
                           10,
                           color=(200, 200, 200))
Exemple #19
0
    def test_eraser_erases_characters_right_to_left(self):
        test_durability = 3
        self.pencil = Pencil(eraser_durability=test_durability)
        string_to_write = "which"
        string_to_erase = "which"

        expected_string = string_to_write[:-test_durability]
        expected_string += ' ' * test_durability

        self.pencil.write(self.paper, string_to_write)
        self.pencil.erase(self.paper, string_to_erase)

        self.assertEqual(self.paper.text, expected_string)
def testSharpenPencilWithZeroLength():
    correctOutput = "She sells sea shells down by the sea "
    durability = 12
    length = 0
    pencil = Pencil(durability, length)
    currentSentenceOnPaper = "She sells sea shells"
    sentenceToWrite = " down by the sea "

    writingOutput = pencil.write(currentSentenceOnPaper, sentenceToWrite)
    assert correctOutput == writingOutput
    assert pencil.durability == 0

    pencil.sharpen()
    assert pencil.durability == 0
Exemple #21
0
    def test_pencils_cannot_write_with_zero_durability(self):
        self.pencil = Pencil(10)
        number_of_characters = 20

        # Fill the string with random characters
        string_to_write = self.get_randomized_string(number_of_characters)

        self.pencil.write(self.paper, string_to_write)

        paper_text_count = len(self.paper.text.strip())

        self.assertEqual(
            paper_text_count,
            number_of_characters - self.pencil.start_point_durability)
def testEditExtendedCompleteAndReplaceEntireSentanceWithSpaces():
    exampleText1 = "An       a day keeps the doctor away."
    correctOutput1 = "An apple a day keeps the doctor away."
    exampleText2 = exampleText1
    correctOutput2 = "An apples@u@@y keeps the doctor away."
    exampleText3 = correctOutput1
    correctOutput3 = "@@ @@@@@ @ @@@ @@@@@ @@@ @@@@@@ @@@@@"
    pencil = Pencil(durability=1000)
    out1 = pencil.edit(exampleText1, "apple", 3)
    out2 = pencil.edit(exampleText2, "applesauce", 3)
    out3 = pencil.edit(exampleText3, ' ' * len(exampleText1), 0)
    assert pencil.durability == 988
    assert correctOutput1 == out1
    assert correctOutput2 == out2
    assert correctOutput3 == out3
 def draw_poly_area(screen,
                    building_color,
                    building_pos,
                    building_name,
                    width=0,
                    name_size=20,
                    name_color=(0, 0, 0)):
     Pencil.draw_poly_rect(screen,
                           pointlist=building_pos,
                           color=building_color,
                           width=width)
     Pencil.write_text(
         screen,
         building_name,
         font_pos=[building_pos[0][0] + 5, building_pos[0][1] + 5],
         font_size=name_size,
         color=name_color)
 def draw_area(screen,
               building_color,
               building_pos,
               building_name,
               width=0,
               name_size=20,
               name_color=(0, 0, 0)):
     Pencil.draw_rect(screen, building_pos, building_color, width=width)
     name_length = len(building_name)
     Pencil.write_text(
         screen,
         building_name,
         font_pos=[
             building_pos[0] + building_pos[2] / 2 -
             (name_length / 2 * 0.6 * name_size),
             building_pos[1] + building_pos[3] / 2 - name_size * 0.5
         ],
         font_size=name_size,
         color=name_color)
Exemple #25
0
 def render(self, surface, start_draw_pos):
     GameEntity.render(self, surface, start_draw_pos)
     if self.wood < self.max_wood:
         x, y = self.location.x + start_draw_pos[
             0], self.location.y + start_draw_pos[1]
         w, h = self.image.get_size()
         # bar_w = 40
         # bar_h = 4
         # bar_x = x - bar_w // 2
         # bar_y = y + h // 2 + 10
         # surface.fill((150, 0, 0), (bar_x, bar_y, bar_w, 4))
         # surface.fill((0, 150, 0), (bar_x, bar_y, self.wood / self.max_wood * bar_w, bar_h))
         text_x = x - 20
         text_y = y + h // 2
         Pencil.write_text(surface,
                           "%3d/%3d" % (self.wood, self.max_wood),
                           [text_x, text_y],
                           10,
                           color=(200, 200, 200))
Exemple #26
0
 def test_that_pencil_that_is_sharpened_before_going_dull_continues_to_write(
         self):
     point_durability = 20
     initial_length = 5
     pencil = Pencil(point_durability=point_durability,
                     initial_length=initial_length)
     paper = Paper()
     pencil.write(paper, 'Testing sharpening.')
     pencil.sharpen()
     pencil.write(paper, ' Testing sharpening.')
     self.assertEqual('Testing sharpening. Testing sharpening.',
                      paper.display_page())
Exemple #27
0
 def test_that_pencil_that_becomes_dull_picks_up_after_spaces_when_sharpened(
         self):
     point_durability = 5
     initial_length = 5
     pencil = Pencil(point_durability=point_durability,
                     initial_length=initial_length)
     paper = Paper()
     pencil.write(paper, 'Test sharpening')
     self.assertEqual(0, pencil.point_durability)
     pencil.sharpen()
     pencil.write(paper, 'Test sharpening')
     self.assertEqual('Test           Test           ',
                      paper.display_page())
Exemple #28
0
 def test_that_pencil_writes_where_it_left_off(self):
     paper = Paper()
     point_durability = 50
     pencil = Pencil(point_durability=point_durability)
     pencil.write(paper, 'She sells sea shells')
     pencil.write(paper, ' down by the sea shore')
     self.assertEqual('She sells sea shells down by the sea shore',
                      paper.display_page())
def testDurabilityIncompleteAndCantSharpenAnymore():
    pencil = Pencil(durability=4, length=0)
    assert pencil.durability == 4
    assert pencil.length == 0
    exampleText1 = "temp"
    exampleText2 = "temp2"
    exampleText3 = "temp3"
    out = pencil.write(exampleText1, exampleText2)
    assert pencil.durability == 0
    assert out == "temptemp "
    pencil.sharpen()
    assert pencil.durability == 0
    out = pencil.write(out, exampleText3)
    assert out == "temptemp      "
    pencil.sharpen()
    assert pencil.durability == 0
    assert pencil.length == 0
Exemple #30
0
 def test_that_eraser_erases_word_in_opposite_order(self):
     durability = 3
     eraser = Eraser(durability=durability)
     point_durability = 100
     initial_length = 5
     pencil = Pencil(point_durability=point_durability, initial_length=initial_length, eraser=eraser)
     paper = Paper()
     pencil.write(paper, 'Buffalo Bill')
     pencil.erase(paper, 'Bill')
     self.assertEqual('Buffalo B   ', paper.display_page())