Exemplo n.º 1
0
def run_test_swell_or_shrink_repeatedly():
    """ Tests the   swell_or_shrink_repeatedly   method. """
    m1_tests.run_test_swell_or_shrink_repeatedly()  # This runs OUR tests
    random.seed(999)  # Lets us determine the results of the randomness

    # This is a VISUAL test.
    # Construct 1 CircleChanger object, printing and drawing it.
    title = 'Testing: the  swell_or_shrink_repeatedly   method'
    m1_tests.start_drawing(title)

    print('After construction:')
    circle_changer1 = CircleChanger(
        200, 150, 30, 'blue',
        ('blue', 'yellow', 'green', 'aquamarine', 'brown'))
    print(circle_changer1)
    circle_changer1.draw("""
    A BLUE circle at (200, 150) with radius 30 and thickness 1.""")

    # Apply the   swell_or_shrink_repeatedly   method.
    print('\nAfter the first   swell_or_shrink_repeatedly   call:')
    circle_changer1.animation_factor = 0.25  # faster animation

    circle_changer1.swell_or_shrink_repeatedly(50, 10)

    print(circle_changer1)
    circle_changer1.draw("""
    The circle should have swelled/shrunk by 50 10 times,
    changing color and thickness each time.
    It should end with the radius that it began (30),
    GREEN with thickness 10.""")
Exemplo n.º 2
0
def run_test_init():
    """ Tests the   __init__   method of the CircleChanger class. """
    m1_tests.run_test_init()  # This runs OUR tests.

    # This is a VISUAL test.
    m1_tests.start_drawing('Testing: the   __init__   method')

    # Construct two CircleChanger objects:
    circle_changer1 = CircleChanger(100, 150, 100, 'blue',
                                    ('red', 'blue', 'green'))
    circle_changer2 = CircleChanger(300, 50, 30, 'yellow', ('green', 'gold'))

    # Print and draw them:
    print('After construction:')
    print(circle_changer1, '\n', circle_changer2, '\n', sep='')
    circle_changer1.draw(0.5)
    circle_changer2.draw("""
    A BLUE circle at (100, 150) with radius 100 and thickness 1,
    and a YELLOW circle at (250, 50) with radius 30 and thickness 1.""")

    # Change some of their characteristics, then print and redraw them:
    circle_changer1.circle.fill_color = circle_changer1.colors[2]
    circle_changer2.circle.outline_thickness = 10
    print('After changing characteristics:')
    print(circle_changer1, '\n', circle_changer2, sep='')
    circle_changer1.draw()
    circle_changer2.draw("""
    Now the leftmost (formerly BLUE) circle is GREEN
    and the YELLOW circle has a thicker outline.""")
Exemplo n.º 3
0
def run_test_swell_or_shrink_once():
    """ Tests the   swell_or_shrink_once   method. """
    m1_tests.run_test_swell_or_shrink_once()  # This runs OUR tests
    random.seed(42)  # Lets us determine the results of the randomness

    # This is a VISUAL test.
    # Construct 3 CircleChanger objects, printing and drawing them.
    m1_tests.start_drawing('Testing: the  swell_or_shrink_once   method')
    print('After construction:')
    circle_changer1 = CircleChanger(
        200, 150, 30, 'blue',
        ('blue', 'yellow', 'green', 'aquamarine', 'brown'))
    print(circle_changer1)
    circle_changer1.draw()

    circle_changer2 = CircleChanger(400, 100, 50, 'red', ('green', ))
    print(circle_changer2)
    circle_changer2.draw()

    circle_changer3 = CircleChanger(300, 200, 10, 'green', ('yellow', 'blue'))
    print(circle_changer3)
    circle_changer3.draw("""
    A BLUE circle at (200, 150) with radius 30 and thickness 1,
    and a RED circle at (400, 100) with radius 50 and thickness 1,
    and a GREEN circle at (300, 200) with radius 10 and thickness 1.""")

    # For each of the three CircleChanger objects,
    #   apply the   swell_or_shrink_once  method, then redraw/reprint.
    print('\nAfter the first set of    swell_or_shrink_once   calls:')
    circle_changer1.swell_or_shrink_once(100)
    print(circle_changer1)
    circle_changer1.draw()

    circle_changer2.swell_or_shrink_once(-30)
    print(circle_changer2)
    circle_changer1.draw()

    circle_changer3.swell_or_shrink_once(40)
    print(circle_changer3)
    circle_changer3.draw("""
    After the first swell_or_shrink, now:
    Left circle is bigger (radius 130), still BLUE but thickness 13,
    Right circle is smaller (radius 20), GREEN with thickness 3,
    Middle circle is bigger (radius 50), YELLOW with thickness 6.""")
Exemplo n.º 4
0
def run_test_change_to_original_color():
    """ Tests the   change_to_original_color   method. """
    m1_tests.run_test_change_to_original_color()  # This runs OUR tests.
    random.seed(123)  # Lets us determine the results of the randomness

    # This is a VISUAL test.
    # Construct 2 CircleChanger objects, printing and drawing them.
    title = 'Testing: the  change_to_original_color   method'
    m1_tests.start_drawing(title)

    print('After construction:')
    circle_changer1 = CircleChanger(100, 100, 100, 'black', ('blue', 'green'))
    circle_changer1.draw()
    print(circle_changer1)
    circle_changer2 = CircleChanger(
        280, 100, 100, 'purple',
        ('yellow', 'magenta', 'blue', 'green', 'yellow', 'aquamarine'))
    print(circle_changer2)
    circle_changer2.draw("""
    A BLACK circle at (100, 100) with radius 100,
    and a PURPLE circle at (280, 100) with radius 100.
    You will next see a bunch of colors,
    ending with BLACK and PURPLE again.""")

    # Flash through many color changes.  Then apply the
    #   change_to_original_color   method and print/draw the results.
    print('\nAfter the first set of  change_to_original_color  calls:')
    for k in range(30):
        circle_changer1.change_color(k % 2)
        circle_changer1.draw(0.05)

        circle_changer2.change_color(k % 6)
        circle_changer2.draw(0.05)

    circle_changer1.change_to_original_color()
    print(circle_changer1)
    circle_changer1.draw()

    circle_changer2.change_to_original_color()
    print(circle_changer2)
    circle_changer2.draw("""
    Should end as it started: BLACK and PURPLE.""")
Exemplo n.º 5
0
def run_test_change_to_next_color_in_tuple():
    """ Tests the   change_to_next_color_in_tuple   method. """
    #     m1_tests.change_to_next_color()  # This runs OUR tests.

    # This is a VISUAL test.
    # Construct 2 CircleChanger objects, printing and drawing them.
    title = 'Testing: the  change_to_next_color   method'
    m1_tests.start_drawing(title)

    print('After construction:')
    circle_changer1 = CircleChanger(100, 100, 100, 'black',
                                    ('blue', 'green', 'red'))
    circle_changer1.draw()
    print(circle_changer1)
    circle_changer2 = CircleChanger(
        280, 100, 40, 'purple',
        ('yellow', 'magenta', 'blue', 'green', 'yellow', 'aquamarine'))
    print(circle_changer2)
    circle_changer2.draw("""
    A BLACK circle at (100, 100) with radius 100,
    and a PURPLE circle at (280, 100) with radius 40.
    You will next see a bunch of colors,
    cycling through BLUE, GREEN, RED (for the left, larger circle)
    and YELLOW, MAGENTA, BLUE, GREEN, YELLOW (again) and AQUAMARINE
    (for the right, smaller circle).""")

    # Cycle through the CircleChanger's tuples of colors:
    print('\nAfter the first set of  change_to_next_color  calls:')
    for _ in range(16):
        circle_changer1.change_to_next_color_in_tuple()
        circle_changer1.draw(0.25)

        circle_changer2.change_to_next_color_in_tuple()
        circle_changer2.draw(0.25)

    circle_changer2.draw("""
    Should end with circles: BLUE and GREEN.""")
Exemplo n.º 6
0
def run_test_change_color():
    """ Tests the   change_color   method. """
    m1_tests.run_test_change_color()  # This runs OUR tests.
    random.seed(77)  # Lets us determine the results of the randomness

    # This is a VISUAL test.
    # Construct 2 CircleChanger objects, printing and drawing them.
    title = 'Testing: the  change_color   method'
    m1_tests.start_drawing(title)

    print('After construction:')
    circle_changer1 = CircleChanger(100, 100, 70, 'black', ('blue', 'yellow'))
    circle_changer1.draw()
    print(circle_changer1)
    circle_changer2 = CircleChanger(
        350, 130, 50, 'purple',
        ('yellow', 'magenta', 'blue', 'green', 'yellow', 'aquamarine'))
    print(circle_changer2)
    circle_changer2.draw("""
    A BLACK circle at (100, 100) with radius 70,
    and a PURPLE circle at (350, 130) with radius 50.""")

    # Apply the   change_color   method.  Then print/draw the results.
    print('\nAfter the first set of   change_color   calls:')

    circle_changer1.change_color(1)
    print(circle_changer1)
    circle_changer1.draw()

    circle_changer2.change_color(5)
    print(circle_changer2)
    circle_changer2.draw("""
    Same circles, but now YELLOW and AQUAMARINE.
    The next test will cycle the LEFT circle through:
      blue and yellow (repeating as needed)
    and the RIGHT circle through:
      yellow, magenta, blue, green, yellow, and aquamarine.""")

    # Another test:
    for k in range(6):
        circle_changer1.change_color(k % 2)
        circle_changer1.draw()

        circle_changer2.change_color(k)
        circle_changer2.draw()

    circle_changer1.draw("""
    Should have finished with YELLOW and AQUAMARINE.""")

    # This tests   change_color   and   swell_and_shrink_once
    # repeatedly.
    for k in range(20, 0, -1):
        circle_changer1.change_color(k % 2)
        circle_changer1.draw(0.05)
        circle_changer1.swell_or_shrink_once((-40 // k) * (k**-1))
        circle_changer1.draw(0.05)

        circle_changer2.change_color(k % 6)
        circle_changer2.draw(0.05)
        circle_changer2.swell_or_shrink_once(50 // k)
        circle_changer1.draw(0.05)

    circle_changer1.draw("""
    Should have ended with two YELLOW circles:
    a TINY one on the LEFT and a HUGE one on the RIGHT.""")
Exemplo n.º 7
0
def run_test_swallow():
    """ Tests the   swallow   method. """
    m1_tests.run_test_swallow()  # This runs OUR tests.

    # This is a VISUAL test.
    # Construct 2 CircleChanger objects, printing and drawing them.
    title = 'Testing: the  swallow   method'
    m1_tests.start_drawing(title)

    print('After construction:')
    circle_changer1 = CircleChanger(200, 150, 50, 'blue',
                                    ('blue', 'yellow', 'green'))
    circle_changer1.draw()
    print(circle_changer1)
    circle_changer2 = CircleChanger(450, 180, 30, 'green',
                                    ('yellow', 'magenta'))
    print(circle_changer2)
    circle_changer2.draw("""
    A BLUE circle at (200, 150) with radius 50,
    and a GREEN circle at (450, 180) with radius 30.""")

    # Apply the   swallow   method.  Then print/draw the resulting
    # circle, drawing the original circles on top of it.
    print('\nAfter the first   swallow   call:')

    circle_changer3 = circle_changer1.swallow(circle_changer2)
    print(circle_changer3)
    circle_changer3.draw("""
    The RED circle should be centered at (325, 165) with radius about 126.
    It should cover approximately HALF of the BLUE and GREEN circles.""")

    circle_changer4 = CircleChanger(200, 150, 50, 'blue',
                                    ('blue', 'yellow', 'green'))
    circle_changer4.draw()
    circle_changer5 = CircleChanger(450, 180, 30, 'green',
                                    ('yellow', 'magenta'))
    circle_changer5.draw("""
    Here are the BLUE and GREEN circles again, on TOP of the RED circle.
    The RED should appear to be underneath approximately HALF
    of each of the BLUE and GREEN circles.""")

    # Test that the swallowing (red) CircleChanger
    # has a   colors   attribute that is the CONCATENATION
    # of the  colors   attributes of the swallowed CircleChangers.
    if circle_changer3.colors != (circle_changer4.colors +
                                  circle_changer5.colors):
        message = """The   colors   instance variable
    of the swallowing CircleChanger (the one RETURNED by
    the   swallow   method) is wrong.
    It should be the CONCATENATION of the   colors   instance
    variables of the two SWALLOWED Animated Circle objects.
    For example, if   circle_changer1.colors   is:
       (blue', 'yellow', 'green')
    and if   circle_changer2.colors   is:
       ('yellow', 'magenta')
    then   circle_changer1.swallow(circle_changer2)   should be:
       ('blue', 'yellow', 'green', 'yellow', 'magenta')
    and    circle_changer2.swallow(circle_changer1)   should be:
       ('yellow', 'magenta', 'blue', 'yellow', 'green')
    """
        time.sleep(0.5)
        print(message, file=sys.stderr)
        print('The   colors   instance  of   circle_changer1   is:',
              '\n   ',
              circle_changer1.colors,
              file=sys.stderr)
        print('The   colors   instance  of   circle_changer2   is:',
              '\n   ',
              circle_changer2.colors,
              file=sys.stderr)
        print('The   colors   instance  of the swallowing', file=sys.stderr)
        print('CircleChanger (circle_changer3)   is:',
              '\n   ',
              circle_changer3.colors,
              file=sys.stderr)
        print('but should be:', file=sys.stderr)
        print("  ('blue', 'yellow', 'green', 'yellow', 'magenta')",
              file=sys.stderr)
        time.sleep(1)