Ejemplo n.º 1
0
def run_test_RETURN_circle():
    """ Tests the   RETURN_circle   function. """
    print()
    print('-----------------------------------------')
    print('Testing RETURN_circle:')
    print('-----------------------------------------')

    print()
    print('See the graphics window for this test.')
    print('If an error msg appears at any point,')
    print('then you have FAILED this test.')

    # ------------------------------------------------------------------
    # Tests 1 and 2 (on one window):
    # ------------------------------------------------------------------
    window = rg.RoseWindow(500, 400, 'Testing RETURN_circle')
    text = rg.Text(rg.Point(250, 125), '')
    text.attach_to(window.initial_canvas)

    circle = rg.Circle(rg.Point(200, 300), 50)
    circle.fill_color = 'blue'

    circle.attach_to(window.initial_canvas)

    msg = 'Note: If you see an error message at ANY point,\n'
    msg = msg + 'then you have failed this test.\n\n'
    msg = msg + 'I have drawn the original, blue circle.\n\n'
    msg = msg + 'So you should see a BLUE circle below\n'
    msg = msg + '(and nothing else).\n\n'
    msg = msg + 'Click the mouse to continue this test.\n'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    new_circle = RETURN_circle(circle, 'red')

    if new_circle:
        new_circle.attach_to(window.initial_canvas)

    msg = 'I have now called your   RETURN_circle   function\n'
    msg = msg + 'and drawn the CLONED, RED circle that your\n'
    msg = msg + 'RETURN_circle   function should have returned.\n\n'
    msg = msg + 'So you should see a RED circle below\n'
    msg = msg + '(and nothing else, since the blue circle\n'
    msg = msg + 'is beneath the red circle).\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    if new_circle:
        new_circle.detach_from(window.initial_canvas)

    msg = 'I have now UN-drawn the CLONED, RED circle.\n\n'
    msg = msg + 'So you should see the original, BLUE circle below\n'
    msg = msg + '(and nothing else).\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    circle.detach_from(window.initial_canvas)

    msg = 'I have now UN-drawn the ORIGINAL, blue circle.\n\n'
    msg = msg + 'So you should see NO circles below.\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    if new_circle:
        new_circle.attach_to(window.initial_canvas)

    msg = 'Now I have RE-drawn the CLONED, RED circle\n'
    msg = msg + 'that your   RETURN_circle   function\n'
    msg = msg + 'should have returned.\n\n'
    msg = msg + 'So you should see a RED circle below\n'
    msg = msg + '(and nothing else).\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    # ------------------------------------------------------------------
    # Note: The following statements make the variable  new_circle
    #       refer to a new, green circle.  So we can no longer refer
    #       to the RED circle (to which the variable  new_circle  once
    #       referred).  But the red circle still exists!
    # ------------------------------------------------------------------

    new_circle = RETURN_circle(circle, 'green')

    if new_circle:
        new_circle.attach_to(window.initial_canvas)

    msg = 'Now I have ALSO drawn the CLONED, GREEN circle\n'
    msg = msg + 'that your   RETURN_circle   function\n'
    msg = msg + 'should have returned.\n\n'
    msg = msg + 'So you should see a GREEN circle below\n'
    msg = msg + '(and nothing else, since the red circle\n'
    msg = msg + 'is beneath the green circle).\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    if new_circle:
        new_circle.detach_from(window.initial_canvas)

    msg = 'I have now UN-drawn the CLONED, GREEN circle.\n\n'
    msg = msg + 'So you should see the cloned, RED circle below\n'
    msg = msg + '(and nothing else).\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    new_circle2 = RETURN_circle(rg.Circle(rg.Point(250, 350), 25),
                                'white')

    if new_circle:
        new_circle.attach_to(window.initial_canvas)
    if new_circle2:
        new_circle2.attach_to(window.initial_canvas)

    msg = 'I have now RE-drawn the CLONED, GREEN circle.\n'
    msg = msg + 'Additionally, I called your   RETURN_circle   function\n'
    msg = msg + 'again, asking it to return a smaller WHITE circle\n'
    msg = msg + 'that is below and to the right of the other circles.\n\n'
    msg = msg + 'So you should see a GREEN circle below\n'
    msg = msg + 'and a smaller WHITE circle below and to its right\n'
    msg = msg + '(but NOT the red circle, since it\n'
    msg = msg + 'is beneath the green circle).\n\n'
    msg = msg + 'Click the mouse to conclude this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    window.close()
Ejemplo n.º 2
0
def run_test_MUTATE_circle():
    """ Tests the   MUTATE_circle   function. """
    print()
    print('-----------------------------------------')
    print('Testing MUTATE_circle:')
    print('-----------------------------------------')

    print()
    print('See the graphics window for this test.')
    print('If an error msg appears at any point,')
    print('you have failed this test.')

    # Tests 1 and 2 (on one window):
    window = rg.RoseWindow(500, 450, 'Testing MUTATE_circle')
    text = rg.Text(rg.Point(250, 125), '')
    text.attach_to(window.initial_canvas)

    circle = rg.Circle(rg.Point(250, 300), 50)
    circle.fill_color = 'yellow'

    circle.attach_to(window.initial_canvas)

    msg = 'Note: If you see an error message at ANY point,\n'
    msg = msg + 'then you have failed this test.\n\n'
    msg = msg + 'I have drawn the original, yellow circle.\n\n'
    msg = msg + 'So you should see a YELLOW circle below\n'
    msg = msg + '(and nothing else).\n\n'
    msg = msg + 'Click the mouse to continue this test.\n'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    result = MUTATE_circle(circle, 'pink', 200)

    msg = 'I have called your   MUTATE_circle   function.\n'
    msg = msg + 'It should have MUTATED the (sole) circle to be pink\n'
    msg = msg + 'and 200 units to the right of where it was.\n\n'
    msg = msg + 'So you should see (only) a PINK circle below,\n'
    msg = msg + 'almost touching the right side of the window.\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    if result is not None:
        msg = msg + '\n\nERROR: You returned a value! Wrong!!!'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    circle.detach_from(window.initial_canvas)

    msg = 'I have now UN-drawn the (sole) circle.\n\n'
    msg = msg + 'So you should see NO circles below.\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    circle.attach_to(window.initial_canvas)

    msg = 'Now I have RE-drawn the (now pink) circle.\n\n'
    msg = msg + 'So you should see (only) a PINK circle below,\n'
    msg = msg + 'just touching the right side of the window.\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    result = MUTATE_circle(circle, 'black', -400)

    msg = 'I have called your   MUTATE_circle   function again.\n'
    msg = msg + 'It should have MUTATED the (sole) circle to be black\n'
    msg = msg + 'and 400 units to the left of where it was.\n\n'
    msg = msg + 'So you should see (only) a BLACK circle below,\n'
    msg = msg + 'just touching the left side of the window.\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    if result is not None:
        msg = msg + '\n\nERROR: You returned a value! Wrong!!!'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    another_circle = rg.Circle(circle.center, 25)
    another_circle.fill_color = 'red'
    another_circle.attach_to(window.initial_canvas)

    msg = 'I have constructed and drawn another circle.\n'
    msg = msg + 'It is red and smaller than the black circle,\n'
    msg = msg + 'and currently centered on the black circle.\n\n'
    msg = msg + 'So you should now see a BLACK circle below,\n'
    msg = msg + 'just touching the left side of the window,\n'
    msg = msg + 'with a smaller red circle on top of the black circle.\n\n'
    msg = msg + 'Click the mouse to continue this test.'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    result = MUTATE_circle(another_circle, 'white', 65)

    msg = 'I have called your   MUTATE_circle   function again.\n'
    msg = msg + 'It should have MUTATED the small, red circle to be white\n'
    msg = msg + 'and 65 units to the left of where it was.\n\n'
    msg = msg + 'So you should see a BLACK circle below,\n'
    msg = msg + 'just touching the left side of the window,\n'
    msg = msg + 'with a WHITE circle slightly overlapping the black one.\n\n'
    msg = msg + 'Click the mouse to conclude this test.'
    if result is not None:
        msg = msg + '\n\nERROR: You returned a value! Wrong!!!'
    text.text = msg
    window.render(0.5)
    window.get_next_mouse_click()

    window.close()
def run_test_swap_colors():
    """ Tests the   swap_colors   function. """
    print()
    print('--------------------------------------------------')
    print('Testing the   swap_colors   function:')
    print('--------------------------------------------------')

    # ------------------------------------------------------------------
    # Test 1:  Note that it tests both:
    #            -- what was SUPPOSED to be mutated (fill_color) and
    #            -- what was NOT supposed to be mutated (all else).
    #   The code passes this test if the expected value printed
    #   is the same as the actual value printed.
    # ------------------------------------------------------------------
    circle = rg.Circle(rg.Point(100, 150), 50)
    circle.fill_color = 'blue'

    rectangle = rg.Rectangle(rg.Point(200, 30), rg.Point(350, 150))
    rectangle.fill_color = 'green'

    expected_c = 'Circle: center=(100, 150), radius=50,'
    expected_c += ' fill_color=green, outline_color=black,'
    expected_c += ' outline_thickness=1.'

    expected_r = 'Rectangle: corner_1=(200, 30), corner_2=(350, 150),'
    expected_r += ' fill_color=blue, outline_color=black,'
    expected_r += ' outline_thickness=1.'

    swap_colors(circle, rectangle)

    print()
    print('Expected circle after the function call:')
    print(expected_c)
    print('Actual circle after the function call:')
    print(circle)

    print()
    print('Expected rectangle after the function call:')
    print(expected_r)
    print('Actual rectangle after the function call:')
    print(rectangle)

    # ------------------------------------------------------------------
    # Test 2:  This is a VISUAL test.
    #   The code passes this test if the objects are drawn per the test.
    #
    #   Here, that means that when the window pauses and asks the user
    #   to press any key to continue:
    #     -- the circle is black_filled and
    #     -- the rectangle is red_filled
    #   and then when the user presses a key and the window pauses
    #   again, now the reverse is true:
    #     -- the circle is red_filled and
    #     -- the rectangle is black_filled.
    # ------------------------------------------------------------------
    title = 'The code passes the test if the fill colors of the circle'
    title += ' and rectangle get SWAPPED.'
    window = rg.RoseWindow(700, 400, title)

    circle = rg.Circle(rg.Point(100, 50), 40)
    circle.fill_color = 'black'
    circle.attach_to(window)

    rectangle = rg.Rectangle(rg.Point(200, 280), rg.Point(350, 350))
    rectangle.fill_color = 'red'
    rectangle.attach_to(window)

    msg1 = 'At this point, the circle should be filled with BLACK\n'
    msg1 += 'and the rectangle should be filled with RED'
    message = rg.Text(rg.Point(400, 100), msg1)
    message.attach_to(window)

    # At this point, the CIRCLE should be filled with BLACK
    #                   and the RECTANGLE filled with RED.
    window.render()
    window.continue_on_mouse_click()

    swap_colors(circle, rectangle)

    # At this point, the CIRCLE should be filled with RED
    #                   and the RECTANGLE filled with BLACK.
    msg2 = 'Now, the circle should be filled with RED\n'
    msg2 += 'and the rectangle should be filled with BLACK.\n'
    msg2 += 'If so, and if nothing else changed,\n'
    msg2 += 'the code passed this test.'
    message.text = msg2

    window.render()
    window.close_on_mouse_click()