def run_test_practice_problem4a():
    """ Tests the    practice_problem4a    function. """
    # ------------------------------------------------------------------
    # 4 tests.  They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem4v((9, 33, 8, 8, 0, 4, 4, 8))
    # and compare the returned value against [2, 5] (the correct answer).
    # ------------------------------------------------------------------
    tests = [
        st.SimpleTestCase(practice_problem4a, [(9, 33, 8, 8, 0, 4, 4, 8)],
                          [2, 5]),
        st.SimpleTestCase(practice_problem4a, [(9, 9, 9, 9, 0, 9, 9, 9)],
                          [0, 1, 2, 5, 6]),
        st.SimpleTestCase(practice_problem4a, [(4, 5, 4, 5, 4, 5, 4)], []),
        st.SimpleTestCase(practice_problem4a, ['abbabbb'], [1, 4, 5]),
    ]

    # Run the 4 tests in the   tests   list constructed above.
    st.SimpleTestCase.run_tests('practice_problem4a', tests)
Beispiel #2
0
def run_test_practice_problem3a():
    """ Tests the    practice_problem3a    function. """
    # ------------------------------------------------------------------
    # 6 tests.
    # They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem3a((rg.Circle(rg.Point(5, 10), 20),
    #                       rg.Circle(rg.Point(2, 20), 20),
    #                       rg.Circle(rg.Point(7, 30), 10),
    #                       rg.Circle(rg.Point(10, 40), 20),
    #                       rg.Circle(rg.Point(2, 50), 10)))
    # and compare the returned value against 1400 (the correct answer).
    # ------------------------------------------------------------------
    tests = [st.SimpleTestCase(practice_problem3a,
                               [(rg.Circle(rg.Point(5, 10), 20),
                                 rg.Circle(rg.Point(2, 20), 20),
                                 rg.Circle(rg.Point(7, 30), 10),
                                 rg.Circle(rg.Point(10, 40), 20),
                                 rg.Circle(rg.Point(2, 50), 10))],
                               5 * 2 * 7 * 10 * 2),
             st.SimpleTestCase(practice_problem3a,
                               [(rg.Circle(rg.Point(58, 10), 20),)],
                               58),
             st.SimpleTestCase(practice_problem3a,
                               [(rg.Circle(rg.Point(84, 100), 200),
                                 rg.Circle(rg.Point(28, 200), 200),
                                 rg.Circle(rg.Point(10005, 300), 100))],
                               84 * 28 * 10005),
             st.SimpleTestCase(practice_problem3a,
                               [()],
                               1),
             st.SimpleTestCase(practice_problem3a,
                               [(rg.Circle(rg.Point(5, 10), 20),
                                 rg.Circle(rg.Point(0, 20), 20),
                                 rg.Circle(rg.Point(7, 30), 10),
                                 rg.Circle(rg.Point(10, 40), 20),
                                 rg.Circle(rg.Point(2, 50), 10))],
                               5 * 0 * 7 * 10 * 2),
             ]

    circles = []
    for k in range(1, 101):
        circles.append(rg.Circle(rg.Point(k, k + 20), 5 * k))
    answer = math.factorial(100)
    tests.append(st.SimpleTestCase(practice_problem3a,
                                   [circles],
                                   answer))

    # ------------------------------------------------------------------
    # Run the 6 tests in the   tests   list constructed above.
    # ------------------------------------------------------------------
    st.SimpleTestCase.run_tests('practice_problem3a', tests)
Beispiel #3
0
def run_test_problem2b():
    """ Tests the    problem2b    function. """
    tests = [
        st.SimpleTestCase(problem2b, [[1, 20, 30], [1, 2, 3]], 1),
        st.SimpleTestCase(problem2b, [[0, -50, 30], [1, 2, 3]], 2),
        st.SimpleTestCase(problem2b, [[10, 11, 12], [1, 2, 3]], 0),
        st.SimpleTestCase(problem2b, [[111], [222]], -1),
        st.SimpleTestCase(problem2b, [[], []], -1),
        st.SimpleTestCase(problem2b, [[3, 3, -3, -3], [3, 3, -3, -30]], 3),
    ]

    st.SimpleTestCase.run_tests('test_problem2b', tests)
Beispiel #4
0
def run_test_problem2a():
    """ Tests the    problem2a    function. """
    tests = [
        st.SimpleTestCase(
            problem2a,
            [[rg.Point(3, 4), rg.Point(3, 4),
              rg.Point(3, 4)]], 12),
        st.SimpleTestCase(problem2a,
                          [[rg.Point(3, 4), rg.Point(3, -4)]], 0),
        st.SimpleTestCase(problem2a, [[rg.Point(3, 4)]], 4),
        st.SimpleTestCase(problem2a, [[]], 0),
        st.SimpleTestCase(problem2a, [[
            rg.Point(100, 40),
            rg.Point(50, 10),
            rg.Point(200, 50),
            rg.Point(120, 30),
            rg.Point(40, 88),
            rg.Point(90, 60)
        ]], 278),
        st.SimpleTestCase(problem2a, [[
            rg.Point(200, 40),
            rg.Point(50, 10),
            rg.Point(10, 50),
            rg.Point(120, 30),
            rg.Point(40, 88),
            rg.Point(90, 60)
        ]], 278),
        st.SimpleTestCase(problem2a, [[
            rg.Point(1, 40),
            rg.Point(2, 10),
            rg.Point(3, 50),
            rg.Point(4, 30),
            rg.Point(5, 88),
            rg.Point(6, 66),
            rg.Point(7, 55),
            rg.Point(8, 44),
            rg.Point(9, 99),
            rg.Point(10, 6)
        ]], 488),
    ]

    st.SimpleTestCase.run_tests('problem2a', tests)
Beispiel #5
0
def test_problem1a():
    """ Tests the    problem1a    function. """
    tests = [
        st.SimpleTestCase(problem1a, [[
            rg.Point(28, 6),
            rg.Point(5, 13),
            rg.Point(24, 6),
            rg.Point(5, 6),
            rg.Point(28, 6),
            rg.Point(6, 5),
        ]], rg.Point(28, 6)),
        st.SimpleTestCase(problem1a, [[
            rg.Point(44, 6),
            rg.Point(5, 13),
            rg.Point(24, 6),
            rg.Point(5, 6),
            rg.Point(28, 6),
            rg.Point(6, 5),
        ]], rg.Point(28, 6)),
        st.SimpleTestCase(problem1a, [[
            rg.Point(24, 6),
            rg.Point(5, 13),
            rg.Point(24, 6),
            rg.Point(5, 6),
            rg.Point(496, 28),
            rg.Point(6, 5),
        ]], rg.Point(496, 28)),
        st.SimpleTestCase(problem1a, [[
            rg.Point(20, 6),
            rg.Point(5, 13),
            rg.Point(24, 6),
            rg.Point(5, 6),
            rg.Point(22, 6),
            rg.Point(493, 24),
        ]], 'BAD'),
        st.SimpleTestCase(problem1a, [[]], 'BAD'),
        st.SimpleTestCase(problem1a, [[
            rg.Point(23, 6),
            rg.Point(5, 13),
            rg.Point(496, 6),
            rg.Point(5, 6),
            rg.Point(20, 6),
            rg.Point(6, 5),
        ]], rg.Point(496, 6)),
    ]

    st.SimpleTestCase.run_tests('problem1a', tests)
Beispiel #6
0
def run_test_problem1c():
    """ Tests the    problem1c    function. """
    tests = [
        st.SimpleTestCase(problem1c, [["foo", "robots"]],
                          ["foo", "robots", "robots"]),
        st.SimpleTestCase(
            problem1c, [["a", "robots", "b", "robots", "c"]],
            ["a", "robots", "robots", "b", "robots", "robots", "c"]),
        st.SimpleTestCase(
            problem1c, [["foo", "robots", "robots", "ok"]],
            ["foo", "robots", "robots", "robots", "robots", "ok"]),
        st.SimpleTestCase(problem1c, [["foo", "the end"]], ["foo", "the end"]),
        st.SimpleTestCase(
            problem1c, [["robots", "foo", "robots", "bar"]],
            ["robots", "robots", "foo", "robots", "robots", "bar"]),
        st.SimpleTestCase(
            problem1c, [["robots", "robots", "robots"]],
            ["robots", "robots", "robots", "robots", "robots", "robots"]),
        st.SimpleTestCase(problem1c, [[]], []),
    ]

    st.SimpleTestCase.run_tests('problem1c', tests)
def run_test_practice_problem3e():
    """ Tests the    practice_problem3e    function. """
    # ------------------------------------------------------------------
    # 5 tests.  They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem3e((12, 33, 18, 9, 13, 3, 9, 20, 19, 20))
    # and compare the returned value against 161 (the correct answer).
    # ------------------------------------------------------------------
    tests = [
        st.SimpleTestCase(practice_problem3e,
                          [(12, 33, 18, 9, 13, 3, 99, 20, 19, 20)], 161),
        st.SimpleTestCase(practice_problem3e, [(3, 12, 10, 8, 8, 9, 8, 11)],
                          29),
        st.SimpleTestCase(practice_problem3e, [(-9999999999, 8888888888)],
                          -9999999999),
        st.SimpleTestCase(practice_problem3e, [(8888888888, -9999999999)],
                          8888888888),
        st.SimpleTestCase(practice_problem3e,
                          [(-77, 20000, -33, 40000, -55, 60000, -11)], -176),
        st.SimpleTestCase(practice_problem3e, [()], 0),
        st.SimpleTestCase(practice_problem3e, [[]], 0),
        st.SimpleTestCase(practice_problem3e, [[8]], 8),
        st.SimpleTestCase(practice_problem3e, [(-77, 8)], -77),
        st.SimpleTestCase(practice_problem3e, [(-77, 8, 77)], 0),
        st.SimpleTestCase(practice_problem3e, [(-77, 8, 78)], 1),
        st.SimpleTestCase(practice_problem3e, [(-77, 8, 78, 100)], 1),
    ]

    # ------------------------------------------------------------------
    # Run the 5 tests in the   tests   list constructed above.
    # ------------------------------------------------------------------
    st.SimpleTestCase.run_tests('practice_problem3e', tests)
def run_test_practice_problem3b():
    """ Tests the    practice_problem3b    function. """
    # ------------------------------------------------------------------
    # 13 tests.  They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem3b([12, 33, 18, 'hello', 9, 13, 3, 9])
    # and compare the returned value against True (the correct answer).
    # ------------------------------------------------------------------
    tests = [
        st.SimpleTestCase(practice_problem3b,
                          [[12, 33, 18, 'hello', 9, 13, 3, 9]], True),
        st.SimpleTestCase(practice_problem3b,
                          [[12, 12, 33, 'hello', 5, 33, 5, 9]], False),
        st.SimpleTestCase(practice_problem3b,
                          [(77, 112, 33, 'hello', 0, 43, 5, 77)], True),
        st.SimpleTestCase(practice_problem3b, [[1, 1, 1, 1, 1, 1, 2]], False),
        st.SimpleTestCase(practice_problem3b, [['aa', 'a']], False),
        st.SimpleTestCase(practice_problem3b, ['aaa'], True),
        st.SimpleTestCase(practice_problem3b,
                          [['aa', 'a', 'b', 'a', 'b', 'a']], True),
        st.SimpleTestCase(practice_problem3b, [[9]], False),
        st.SimpleTestCase(practice_problem3b,
                          [(12, 33, 8, 'hello', 99, 'hello')], True),
        st.SimpleTestCase(practice_problem3b,
                          [['hello there', 'he', 'lo', 'hello']], False),
        st.SimpleTestCase(practice_problem3b,
                          [((8, ), '8', (4 + 4, 4 + 4), [8, 8], 7, 8)], False),
        st.SimpleTestCase(practice_problem3b, [[(8, ), '8', [4 + 4, 4 + 4],
                                                (8, 8), 7, [8, 8]]], True),
        st.SimpleTestCase(practice_problem3b,
                          [[(8, ), '8', [4 + 4, 4 + 4], [8, 8], 7,
                            (8, 8)]], False),
    ]

    # Run the 13 tests in the   tests   list constructed above.
    st.SimpleTestCase.run_tests('practice_problem3b', tests)
Beispiel #9
0
def run_test_practice_problem3():
    """ Tests the   practice_problem3  function. """
    ####################################################################
    # Done: 2. Implement this TEST function.
    #   It TESTS the  practice_problem3  function defined below.
    #   Include at least ** 2 ** ADDITIONAL tests beyond those we wrote.
    #
    #   Try to choose tests that might expose errors in your code!
    #
    #   As usual, include both EXPECTED and ACTUAL results in your tests
    #   and compute the latter BY HAND (not by running your program).
    ####################################################################
    # DIFFICULTY AND TIME RATINGS (see top of this file for explanation)
    #    DIFFICULTY:      3
    #    TIME ESTIMATE:   10 minutes.
    ####################################################################

    # ------------------------------------------------------------------
    # 13 tests, plus a 14th after these.
    # They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem3(-2, 2, 1.3)
    # and compare the returned value against [1, 7] (the correct answer).
    # ------------------------------------------------------------------
    tests = [
        st.SimpleTestCase(practice_problem3, [-2, 2, 1.3], [1, 7]),
        st.SimpleTestCase(practice_problem3, [-5, 3, 0.25], [-5, 0, 1]),
        st.SimpleTestCase(practice_problem3, [-5, 4, 0.25], [-5, 0, 1, 2]),
        st.SimpleTestCase(practice_problem3, [-5, 5, 0.25], [-5, 0, 1, 2, 6]),
        st.SimpleTestCase(practice_problem3, [-5, 6, 0.25],
                          [-5, 0, 1, 2, 6, 7]),
        st.SimpleTestCase(practice_problem3, [-5, 7, 0.25],
                          [-5, 0, 1, 2, 6, 7, 8]),
        st.SimpleTestCase(practice_problem3, [-3, 3, -1.0], [-1, 0, 1]),
        st.SimpleTestCase(practice_problem3, [-3, 4, -1.0], [-1, 0, 1, 2]),
        st.SimpleTestCase(practice_problem3, [-3, 5, -1.0], [-1, 0, 1, 2, 3]),
        st.SimpleTestCase(practice_problem3, [-3, 6, -1.0],
                          [-1, 0, 1, 2, 3, 5]),
        st.SimpleTestCase(practice_problem3, [30, 0, -1000], []),
        st.SimpleTestCase(practice_problem3, [100, 5, 1.414],
                          [139, 183, 516, 560, 849]),
        st.SimpleTestCase(practice_problem3, [0, 1, 1.414213562373], [286602]),
    ]
    # 14th test:
    big_list = []
    for k in range(888, 1888):
        big_list.append(k)
    tests.append(
        st.SimpleTestCase(practice_problem3,
                          [888, 1000, -math.sqrt(2) - 0.00000000001],
                          big_list))

    # ------------------------------------------------------------------
    # Run the 14 tests in the   tests   list constructed above.
    # ------------------------------------------------------------------
    st.SimpleTestCase.run_tests('practice_problem3', tests)

    ####################################################################
    # TO DO 2 continued:  More tests:
    #      YOU add at least **   2   ** additional tests here.
    #
    # You can use the   SimpleTestCase  class as above, or use
    # the ordinary   expected/actual   way, your choice.
    #
    # SUGGESTION: Ask an assistant to CHECK your tests to confirm
    #             that they are adequate tests!
    ####################################################################
    test = st.SimpleTestCase(practice_problem3, [0, 1, 1], [1])
    test2 = st.SimpleTestCase(practice_problem3, [-5, 3, .25], [-5, 0, 1])
    test.run_test()
    test2.run_test()
Beispiel #10
0
def test_problem3b():
    """ Tests the    problem3b    function. """
    # ------------------------------------------------------------------
    # Several tests.
    # They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   problem3b(Point(2, 4),
    #            [Point(2, 10), Point(2, 13), Point(2, 7), Point(2, 11)])
    # and compare the returned value against Point(2, 13) (the correct answer).
    # ------------------------------------------------------------------

    tests = [
        st.SimpleTestCase(problem3b, [
            Point(2, 4),
            (
                Point(2, 10),
                Point(2, 13),
                Point(2, 7),
                Point(2, 11),
            )
        ], Point(2, 13)),
        st.SimpleTestCase(problem3b, [
            Point(3, 4),
            (
                Point(50, 4),
                Point(4, 13),
                Point(7, 7),
                Point(8, 11),
            )
        ], Point(50, 4)),
        st.SimpleTestCase(problem3b, [Point(3, 4), (Point(5000, 4000), )],
                          Point(5000, 4000)),
        st.SimpleTestCase(problem3b, [
            Point(100, 43),
            (
                Point(50, 40),
                Point(99, 83),
                Point(33, 41),
                Point(70, 7),
                Point(88, 11),
                Point(44, 88),
                Point(55, 78),
                Point(95, 90),
                Point(90, 97),
                Point(50, 50),
            )
        ], Point(44, 88)),
        st.SimpleTestCase(problem3b, [
            Point(100, 43),
            (
                Point(44, 88),
                Point(50, 40),
                Point(99, 83),
                Point(33, 41),
                Point(70, 7),
                Point(88, 11),
                Point(55, 78),
                Point(95, 90),
                Point(90, 97),
                Point(50, 50),
            )
        ], Point(44, 88)),
        st.SimpleTestCase(problem3b, [
            Point(100, 43),
            (
                Point(50, 40),
                Point(99, 83),
                Point(33, 41),
                Point(70, 7),
                Point(88, 11),
                Point(55, 78),
                Point(95, 90),
                Point(90, 97),
                Point(50, 50),
                Point(44, 88),
            )
        ], Point(44, 88)),
        st.SimpleTestCase(problem3b, [
            Point(100, 43),
            (
                Point(50, 40),
                Point(99, 83),
                Point(33, 41),
                Point(70, 7),
                Point(88, 11),
                Point(44, 88),
                Point(55, 78),
                Point(95, 90),
                Point(90, 97),
                Point(50, 50),
            )
        ], Point(44, 88)),
        st.SimpleTestCase(problem3b, [
            Point(100, 43),
            (
                Point(50, 40),
                Point(99, 83),
                Point(33, 41),
                Point(70, 7),
                Point(88, 11),
                Point(44, 88),
                Point(55, 78),
                Point(95, 90),
                Point(90, 97),
                Point(50, 50),
            )
        ], Point(44, 88)),
    ]

    st.SimpleTestCase.run_tests('problem3b', tests)
Beispiel #11
0
def run_test_practice_problem2b():
    """ Tests the   practice_problem2b  function. """
    # ------------------------------------------------------------------
    # 4 tests, plus a 5th after these.
    # They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem2b(('hello', 'Bye', 'ok joe'))
    # and compare the returned value against 'hBo' (the correct answer).
    # ------------------------------------------------------------------
    tests = [st.SimpleTestCase(practice_problem2b,
                               [('hello', 'Bye', 'ok joe')],
                               'hBo'),
             st.SimpleTestCase(practice_problem2b,
                               [('Alice', 'Bob', 'Carson', 'Devi')],
                               'ABCD'),
             st.SimpleTestCase(practice_problem2b,
                               [('', 'tricky', '', 'one, no?', '!')],
                               'to!'),
             st.SimpleTestCase(practice_problem2b,
                               [('my very long string', 'ok', 'mmmm')],
                               'mom'),
             ]
    jokes = """
    Q: What is it called when a cat wins a dog show?
    A: A CAT-HAS-TROPHY!

    Q: What do you call a pile of kittens?
    A: a meowntain

    Q: Why don't cats like online shopping?
    A: They prefer a cat-alogue.

    Q: What did the cat say when he lost all his money?
    A: I'm paw!

    Q: Did you hear about the cat who swallowed a ball of yarn?
    A: She had a litter of mittens.

    Q: What do you call a lion who has eaten your mother's sister?
    A: An aunt-eater!

    Q. How do you know when your cat's done cleaning herself?
    A. She's smoking a cigarette.

    source: http://www.jokes4us.com/animaljokes/catjokes.html
    """
    # 5th test: Split  jokes  at spaces to get a list of strings.
    sequence = jokes.split()
    answer = ('QWiicwacwadsAACQWdycapokAamQWdclosAT' +
              'pacQWdtcswhlahmAIpQDyhatcwsaboyAShalom' +
              'QWdycalwheymsAAaQHdykwycdchASsacsh')
    tests.append(st.SimpleTestCase(practice_problem2b,
                                   [sequence],
                                   answer))

    # ------------------------------------------------------------------
    # Run the 5 tests in the   tests   list constructed above.
    # ------------------------------------------------------------------
    st.SimpleTestCase.run_tests('practice_problem2b', tests)
Beispiel #12
0
def run_test_practice_problem3a():
    """ Tests the   practice_problem3a  function. """
    ###########################################################################
    # DONE: 3. Implement this TEST function.
    #   It TESTS the  practice_problem3a  function defined below.
    #   Include at least ** 1 ** ADDITIONAL test beyond those we wrote.
    #  __
    #   Try to choose tests that might expose errors in your code!
    #  __
    #   As usual, include both EXPECTED and ACTUAL results in your tests
    #   and compute the latter BY HAND (not by running your program).
    ###########################################################################
    # DIFFICULTY AND TIME RATINGS (see top of this file for explanation)
    #    DIFFICULTY:      3
    #    TIME ESTIMATE:   10 minutes.
    ###########################################################################

    # -------------------------------------------------------------------------
    # Many tests, followed by extra ones appended at the end.
    # They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem3a(6, 8, 0.81)
    # and compare the returned value against [7, 8] (the correct answer).
    # -------------------------------------------------------------------------
    tests = [
        st.SimpleTestCase(practice_problem3a, [6, 8, 0.81], [7, 8]),
        st.SimpleTestCase(practice_problem3a, [-4, 9, 0.25],
                          [0, 1, 2, 6, 7, 8]),
        st.SimpleTestCase(practice_problem3a, [-5, 4, 0.25], [-5, 0, 1, 2]),
        st.SimpleTestCase(practice_problem3a, [-3, 8, 0.65], [0, 1, 6, 7, 8]),
        st.SimpleTestCase(practice_problem3a, [-4, 8, 0.65], [0, 1, 6, 7, 8]),
        st.SimpleTestCase(practice_problem3a, [-5, 8, 0.65],
                          [-5, 00, 1, 6, 7, 8]),
        st.SimpleTestCase(practice_problem3a, [-3, 3, -1.0], [-1, 0, 1, 2, 3]),
        st.SimpleTestCase(practice_problem3a, [-3, 4, -1.0], [-1, 0, 1, 2, 3]),
        st.SimpleTestCase(practice_problem3a, [-3, 5, -1.0],
                          [-1, 0, 1, 2, 3, 5]),
        st.SimpleTestCase(practice_problem3a, [-3, 6, -1.0],
                          [-1, 0, 1, 2, 3, 5, 6]),
        st.SimpleTestCase(practice_problem3a, [30, 0, -1000], []),
        st.SimpleTestCase(practice_problem3a, [100, 1000, 1.414],
                          [139, 183, 516, 560, 849, 893]),
        st.SimpleTestCase(
            practice_problem3a,
            [-1000, 1000000, math.sqrt(2) - 0.0000000001],
            [286602, 599291, 911980]),
        st.SimpleTestCase(practice_problem3a, [-1000, 1000000, 1.414213562373],
                          [286602]),
        st.SimpleTestCase(practice_problem3a, [-1000, 1000000, 1.414213562374],
                          []),
    ]
    # More tests, with larger lists as the expected returned values
    big_list = []
    for k in range(900, 1001):
        big_list.append(k)
    tests.append(
        st.SimpleTestCase(practice_problem3a,
                          [900, 1000, -math.sqrt(2) + 0.00001], big_list))

    big_list_without_915 = big_list.copy()
    big_list_without_915.remove(915)
    tests.append(
        st.SimpleTestCase(practice_problem3a,
                          [900, 1000, -math.sqrt(2) + 0.0001],
                          big_list_without_915))

    # -------------------------------------------------------------------------
    # Run the tests in the   tests   list constructed above.
    # -------------------------------------------------------------------------
    st.SimpleTestCase.run_tests('practice_problem3a', tests)
Beispiel #13
0
def run_test_practice_problem3():
    """ Tests the   practice_problem3  function. """
    ####################################################################
    # DONE: 2. Implement this TEST function.
    #   It TESTS the  practice_problem3  function defined below.
    #   Include at least ** 2 ** ADDITIONAL tests beyond those we wrote.
    #
    #   Try to choose tests that might expose errors in your code!
    #
    #   As usual, include both EXPECTED and ACTUAL results in your tests
    #   and compute the latter BY HAND (not by running your program).
    ####################################################################
    # DIFFICULTY AND TIME RATINGS (see top of this file for explanation)
    #    DIFFICULTY:      3
    #    TIME ESTIMATE:   10 minutes.
    ####################################################################

    # ------------------------------------------------------------------
    # 13 tests, plus a 14th after these.
    # They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem3(-2, 2, 1.3)
    # and compare the returned value against [1, 7] (the correct answer).
    # ------------------------------------------------------------------
    tests = [st.SimpleTestCase(practice_problem3,
                               [-2, 2, 1.3],
                               [1, 7]),
             st.SimpleTestCase(practice_problem3,
                               [-5, 3, 0.25],
                               [-5, 0, 1]),
             st.SimpleTestCase(practice_problem3,
                               [-5, 4, 0.25],
                               [-5, 0, 1, 2]),
             st.SimpleTestCase(practice_problem3,
                               [-5, 5, 0.25],
                               [-5, 0, 1, 2, 6]),
             st.SimpleTestCase(practice_problem3,
                               [-5, 6, 0.25],
                               [-5, 0, 1, 2, 6, 7]),
             st.SimpleTestCase(practice_problem3,
                               [-5, 7, 0.25],
                               [-5, 0, 1, 2, 6, 7, 8]),
             st.SimpleTestCase(practice_problem3,
                               [-3, 3, -1.0],
                               [-1, 0, 1]),
             st.SimpleTestCase(practice_problem3,
                               [-3, 4, -1.0],
                               [-1, 0, 1, 2]),
             st.SimpleTestCase(practice_problem3,
                               [-3, 5, -1.0],
                               [-1, 0, 1, 2, 3]),
             st.SimpleTestCase(practice_problem3,
                               [-3, 6, -1.0],
                               [-1, 0, 1, 2, 3, 5]),
             st.SimpleTestCase(practice_problem3,
                               [30, 0, -1000],
                               []),
             st.SimpleTestCase(practice_problem3,
                               [100, 5, 1.414],
                               [139, 183, 516, 560, 849]),
             st.SimpleTestCase(practice_problem3,
                               [0, 1, 1.414213562373],
                               [286602]),
             ]
    # 14th test:
    big_list = []
    for k in range(888, 1888):
        big_list.append(k)
    tests.append(st.SimpleTestCase(practice_problem3,
                                   [888, 1000,
                                    - math.sqrt(2) - 0.00000000001],
                                   big_list))

    # ------------------------------------------------------------------
    # Run the 14 tests in the   tests   list constructed above.
    # ------------------------------------------------------------------
    st.SimpleTestCase.run_tests('practice_problem3', tests)

    # Test 2:
    expected2 = [1, 7]
    answer2=practice_problem3(-2,2,1.3)
    print()
    print('Test 2:')
    print('  Expected:', expected2)
    print('  Actual:  ', answer2)

    # Test 3:
    expected3 = [-5, 0, 1, 2, 6, 7, 8]
    answer3=practice_problem3(-5, 7, 0.25)
    print()
    print('Test 3:')
    print('  Expected:', expected3)
    print('  Actual:  ', answer3)
Beispiel #14
0
def run_test_practice_problem3b():
    """ Tests the   practice_problem3b  function. """
    ###########################################################################
    # DONE: 5. Implement this TEST function.
    #   It TESTS the  practice_problem3b  function defined below.
    #   Include at least ** 2 ** ADDITIONAL tests beyond those we wrote.
    #  __
    #   Try to choose tests that might expose errors in your code!
    #  __
    #   As usual, include both EXPECTED and ACTUAL results in your tests
    #   and compute the latter BY HAND (not by running your program).
    ###########################################################################
    # DIFFICULTY AND TIME RATINGS (see top of this file for explanation)
    #    DIFFICULTY:      3
    #    TIME ESTIMATE:   10 minutes.
    ###########################################################################

    # -------------------------------------------------------------------------
    # Many tests, followed by extra ones appended at the end.
    # They use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   practice_problem3b(-2, 2, 1.3)
    # and compare the returned value against [1, 7] (the correct answer).
    # -------------------------------------------------------------------------
    tests = [
        st.SimpleTestCase(practice_problem3b, [-2, 2, 1.3], [1, 7]),
        st.SimpleTestCase(practice_problem3b, [-5, 3, 0.25], [-5, 0, 1]),
        st.SimpleTestCase(practice_problem3b, [-5, 4, 0.25], [-5, 0, 1, 2]),
        st.SimpleTestCase(practice_problem3b, [-5, 5, 0.25], [-5, 0, 1, 2, 6]),
        st.SimpleTestCase(practice_problem3b, [-5, 6, 0.25],
                          [-5, 0, 1, 2, 6, 7]),
        st.SimpleTestCase(practice_problem3b, [-5, 7, 0.25],
                          [-5, 0, 1, 2, 6, 7, 8]),
        st.SimpleTestCase(practice_problem3b, [-3, 3, -1.0], [-1, 0, 1]),
        st.SimpleTestCase(practice_problem3b, [-3, 4, -1.0], [-1, 0, 1, 2]),
        st.SimpleTestCase(practice_problem3b, [-3, 5, -1.0], [-1, 0, 1, 2, 3]),
        st.SimpleTestCase(practice_problem3b, [-3, 6, -1.0],
                          [-1, 0, 1, 2, 3, 5]),
        st.SimpleTestCase(practice_problem3b, [30, 0, -1000], []),
        st.SimpleTestCase(practice_problem3b, [100, 5, 1.414],
                          [139, 183, 516, 560, 849]),
        st.SimpleTestCase(practice_problem3b, [0, 1, 1.414213562373],
                          [286602]),
    ]
    # More tests, with larger lists as the expected returned values
    big_list = []
    for k in range(888, 988):
        big_list.append(k)
    tests.append(
        st.SimpleTestCase(practice_problem3b,
                          [888, 100, -math.sqrt(2) + 0.00000000001], big_list))

    another_big_list = big_list.copy()
    another_big_list.remove(915)
    another_big_list.remove(959)
    another_big_list.append(988)
    another_big_list.append(989)
    tests.append(
        st.SimpleTestCase(practice_problem3b,
                          [888, 100, -math.sqrt(2) + 0.001], another_big_list))

    # -------------------------------------------------------------------------
    # Run the tests in the   tests   list constructed above.
    # -------------------------------------------------------------------------
    st.SimpleTestCase.run_tests('practice_problem3b', tests)

    ###########################################################################
    # DONE: 5 continued:  More tests:
    #      YOU add at least **   2   ** additional tests here.
    #  __
    #   You can use the   SimpleTestCase  class as above, or use
    #   the ordinary   expected/actual   way, your choice.
    #  __
    #   SUGGESTION: Ask an assistant to CHECK your tests to confirm
    #               that they are adequate tests!
    ###########################################################################
    expected = ([1, 2, 3, 4, 5])
    print("Expected:", expected)
    actual = practice_problem3b(1, 5, 2)
    print("Actual:", actual)

    expected = ([])
    print("Expected:", expected)
    actual = practice_problem3b(5, 0, 1)
    print("Actual:", actual)
Beispiel #15
0
def test_problem2a():
    """ Tests the   problem2a   function. """
    # ------------------------------------------------------------------
    # These tests use the imported   simple_testing (st)   module.
    # Each test is a SimpleTestCase with 3 arguments:
    #   -- the function to test,
    #   -- a list containing the argument(s) to send to the function,
    #   -- the correct returned value.
    # For example, the first test below will call
    #   problem2a([Point(100, 3), Point(50, 10), Point(7, 11)])
    # and compare the returned value against  157  (the correct answer).
    # ------------------------------------------------------------------
    tests = [
        st.SimpleTestCase(problem2a, [
            [Point(100, 3), Point(50, 10),
             Point(7, 11)],
        ], 157),
        st.SimpleTestCase(problem2a, [
            [Point(77, 555)],
        ], 77),
        st.SimpleTestCase(problem2a, [
            [Point(10, 5), Point(10, 8),
             Point(10, 8)],
        ], 30),
        st.SimpleTestCase(problem2a, [
            [Point(200, 200),
             Point(500, 500),
             Point(400, 400)],
        ], 1100),
        st.SimpleTestCase(problem2a, [
            [
                Point(100, 10),
                Point(7, 10),
                Point(57, 10),
                Point(10, 10),
                Point(4, 10),
                Point(33, 10),
                Point(20, 10),
                Point(21, 10),
                Point(38, 10),
                Point(59, 10),
                Point(77, 10),
                Point(50, 10),
                Point(37, 10),
                Point(33, 10),
                Point(0, 10),
                Point(90, 10),
                Point(70, 10)
            ],
        ], 706),
        st.SimpleTestCase(problem2a, [
            [Point(0, 3), Point(0, 10),
             Point(0, 11)],
        ], 0),
        st.SimpleTestCase(problem2a, [
            [
                Point(-5, 3),
                Point(0, 10),
                Point(5, 11),
                Point(0, 10),
                Point(40, 11),
                Point(-30, 11),
                Point(-10, 11)
            ],
        ], 0),
        st.SimpleTestCase(problem2a, [
            [],
        ], 0),
    ]

    # ------------------------------------------------------------------
    # Run the tests in the   tests   list constructed above.
    # ------------------------------------------------------------------
    st.SimpleTestCase.run_tests('problem2a', tests)
Beispiel #16
0
def test_problem2b():
    """ Tests the   problem2b   function. """
    tests = [
        st.SimpleTestCase(problem2b, [
            [Point(100, 3), Point(50, 10),
             Point(7, 11)],
            Point(49, 13),
        ], Point(50, 10)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
            ],
            Point(1000, 10000),
        ], Point(77, 555)),
        st.SimpleTestCase(problem2b, [
            [Point(100, 50), Point(10, 8),
             Point(10, 8)],
            Point(11, 7),
        ], Point(10, 8)),
        st.SimpleTestCase(problem2b, [
            [Point(100, 20), Point(1000, 1000),
             Point(0, 60)],
            Point(50, 40),
        ], Point(100, 20)),
        st.SimpleTestCase(problem2b, [
            [
                Point(10, 10),
                Point(20, 20),
                Point(30, 30),
                Point(20, 20),
                Point(15, 15),
            ],
            Point(11, 11),
        ], Point(10, 10)),
        st.SimpleTestCase(problem2b, [
            [
                Point(10, 10),
                Point(20, 20),
                Point(30, 30),
                Point(40, 40),
                Point(15, 15),
            ],
            Point(14, 14),
        ], Point(15, 15)),
        st.SimpleTestCase(problem2b, [
            [
                Point(10, 57),
                Point(10, 56),
                Point(10, 53),
                Point(10, 56),
                Point(9, 55),
            ],
            Point(10, 54),
        ], Point(10, 53)),
        st.SimpleTestCase(problem2b, [
            [
                Point(57, 10),
                Point(56, 10),
                Point(53, 10),
                Point(56, 10),
                Point(54, 9),
            ],
            Point(54, 10),
        ], Point(53, 10)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(0, 0),
                Point(0, 0),
                Point(0, 0),
                Point(0, 0),
            ],
            Point(1000, 10000),
        ], Point(77, 555)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(56, 30),
                Point(40, 100),
                Point(0, 0),
                Point(1, 1),
                Point(30, 10),
                Point(40, 70),
                Point(20, 5)
            ],
            Point(1000, 10000),
        ], Point(77, 555)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(56, 30),
                Point(40, 100),
                Point(0, 0),
                Point(1, 1),
                Point(30, 10),
                Point(40, 70),
                Point(20, 5)
            ],
            Point(40, 33),
        ], Point(56, 30)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(56, 30),
                Point(40, 100),
                Point(0, 0),
                Point(1, 1),
                Point(30, 10),
                Point(40, 70),
                Point(20, 5)
            ],
            Point(45, 85),
        ], Point(40, 100)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(56, 30),
                Point(40, 100),
                Point(0, 0),
                Point(1, 1),
                Point(30, 10),
                Point(40, 70),
                Point(20, 5)
            ],
            Point(45, 84),
        ], Point(40, 70)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(56, 30),
                Point(40, 100),
                Point(0, 0),
                Point(1, 1),
                Point(30, 10),
                Point(40, 70),
                Point(20, 5)
            ],
            Point(0, 1),
        ], Point(0, 0)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(56, 30),
                Point(40, 100),
                Point(1, 1),
                Point(0, 0),
                Point(30, 10),
                Point(40, 70),
                Point(20, 5)
            ],
            Point(0, 1),
        ], Point(1, 1)),
        st.SimpleTestCase(problem2b, [
            [
                Point(77, 555),
                Point(56, 30),
                Point(40, 100),
                Point(1, 1),
                Point(0, 0),
                Point(30, 10),
                Point(40, 70),
                Point(20, 5)
            ],
            Point(25, 7),
        ], Point(20, 5)),
    ]

    # ------------------------------------------------------------------
    # Run the tests in the   tests   list constructed above.
    # ------------------------------------------------------------------
    st.SimpleTestCase.run_tests('problem2b', tests)