コード例 #1
0
def run_merge_test():
    """
    Test suite for testing merge function
    """
    print "Running test suite for merge function"
    suite = TestSuite()
    for i_index, case in enumerate(MERGE_TEST_CASES):
        suite.run_test(merge(case),
                       MERGE_EXPECTED_RESULTS[i_index],
                       "Test # " + str(i_index + 1))
    suite.report_results()
コード例 #2
0
def run_test():
    """
    Run test suite for Fifteen puzzle.
    """
    suite = TestSuite()
    test_lower_row_invariant(suite)
    test_solve_interior_tile(suite)
    test_solve_col0_tile(suite)
    test_row0_invariant(suite)
    test_row1_invariant(suite)
    test_solve_row0_tile(suite)
    test_solve_row1_tile(suite)
    test_solve_2x2(suite)
    suite.report_results()
コード例 #3
0
def run_2048_reset_test():
    """
    Test for reset function
    """
    print "Running test suite for reset function"
    suite = TestSuite()
    o_game_board = TwentyFortyEight(4, 4)
    arr_board = o_game_board.reset()
    i_test_count = 1
    for i_index_y in range(4):
        for i_index_x in range(4):
            suite.run_test(arr_board[i_index_y][i_index_x], 0,
                           "Test # " + str(i_test_count))
            i_test_count += 1
    suite.report_results()
    print o_game_board
    o_game_board.get_open_tile()
コード例 #4
0
def run_test():
    """
    Run tests for Zombie class
    """

    suite = TestSuite()

    zombie = poc_zombie_template.Zombie(4, 6, None, [(1, 5), (3, 2)])
    suite.run_test(zombie.compute_distance_field(poc_zombie_template.ZOMBIE), \
        [[5, 4, 3, 3, 2, 1], [4, 3, 2, 2, 1, 0], \
        [3, 2, 1, 2, 2, 1], [2, 1, 0, 1, 2, 2]], \
        "#Test 1a: compute_distance_field")

    zombie = poc_zombie_template.Zombie(4, 6, [(1, 2)], [(1, 5), (3, 2)])
    suite.run_test(zombie.compute_distance_field(poc_zombie_template.ZOMBIE), \
        [[5, 4, 4, 3, 2, 1], [4, 3, 2, 2, 1, 0], \
        [3, 2, 1, 2, 2, 1], [2, 1, 0, 1, 2, 2]], \
        "#Test 1b: compute_distance_field")

    suite.report_results()
コード例 #5
0
def run_test():
    """
    Run the test suite of Tic-Tac-Toe.
    """

    suite = TestSuite()

    board = provided.TTTBoard(3)
    scores = [[0 for dummy_col in range(3)] for dummy_row in range(3)]

    mc_trial = tic_tac_toe.mc_trial
    mc_update_scores = tic_tac_toe.mc_update_scores
    get_best_move = tic_tac_toe.get_best_move
    mc_move = tic_tac_toe.mc_move

    for dummy in range(3):
        board_clone = board.clone()
        mc_trial(board_clone, provided.PLAYERX)
        suite.run_test(board_clone.check_win() != None, True, \
            "Test #1: mc_trial")
        print board_clone

        mc_update_scores(scores, board_clone, provided.PLAYERX)
        print scores

    best_move = get_best_move(board, scores)
    print best_move

    move = mc_move(board, provided.PLAYERX, 3)
    print move

    board = provided.TTTBoard(3, False, \
        [[provided.PLAYERX, provided.EMPTY, provided.EMPTY], \
        [provided.PLAYERO, provided.PLAYERO, provided.EMPTY], \
        [provided.EMPTY, provided.PLAYERX, provided.EMPTY]])
    print board
    print mc_move(board, provided.PLAYERX, tic_tac_toe.NTRIALS)

    suite.report_results()
コード例 #6
0
ファイル: cookie_clicker_test.py プロジェクト: algenon/poc
 def __init__(self):
     TestSuite.__init__(self)
コード例 #7
0
 def __init__(self):
     TestSuite.__init__(self)
コード例 #8
0
ファイル: run_test.py プロジェクト: boonchu/python3lab
def run_test():
    """
    https://class.coursera.org/principlescomputing1-004/forum/thread?thread_id=681
    https://class.coursera.org/principlescomputing1-004/forum/thread?thread_id=697
    https://class.coursera.org/principlescomputing1-004/forum/thread?thread_id=700
    """
    suite = TestSuite()
    state_1 = ClickerState()
    suite.run_test(state_1.wait(45.0), None, 'Wrong wait #1')
    suite.run_test(state_1.buy_item('item', 1.0, 3.5), None,
                   "Error with buy item")
    suite.run_test(state_1.__str__(), ("Time: 45.0 Current Cookies: 44.0 CPS: 4.5 Total Cookies: 45.0 History (length: 2): [(0.0, None, 0.0, 0.0), (45.0, 'item', 1.0, 45.0)]"),\
    "Different message from test1")

    state_2 = ClickerState()
    suite.run_test(state_2.wait(45.0), None, 'Wrong wait #2')
    suite.run_test(state_2.__str__(), ("Time: 45.0 Current Cookies: 45.0 CPS: 1.0 Total Cookies: 45.0 History (length: 1): [(0.0, None, 0.0, 0.0)]"),\
        "Different message from test2")

    state_3 = simulate_clicker(
        provided.BuildInfo({'Cursor': [15.0, 0.10000000000000001]}, 1.15),
        5000.0, strategy_none)
    suite.run_test(state_3.__str__(), ("Time: 5000.0 Current Cookies: 5000.0 CPS: 1.0 Total Cookies: 5000.0 History (length: 1): [(0.0, None, 0.0, 0.0)]"),\
        "Different message from test3")

    # For the cheap strategy, you need to choose the item that has the lowest cost (cheapest) each time.
    # This may change throughout the simulation because an item's cost increases after you buy an item.
    #
    # OwlTest tells you that:
    #
    # A - cost 5.0, CPS increment: 1.0
    # B - cost: 50000.0, CPS increment 3.0
    # C - cost: 500.0, CPS increment 2.0
    #
    # - Since you start with 500000.0 cookies, you can definitely build all of them (A, B and C).
    # - Of the items that can be built, append the item costs to a list.  [5.0, 50000.0, 500.0]
    # - Find the cheapest item cost. 5.0
    # - Return the name of the item which costs this amount. A
    state_4 = strategy_cheap(
        500000.0, 1.0, [(0.0, None, 0.0, 0.0)], 5.0,
        provided.BuildInfo(
            {
                'A': [5.0, 1.0],
                'C': [50000.0, 3.0],
                'B': [500.0, 2.0]
            }, 1.15))
    suite.run_test(state_4, ("A"), "expect A from test 4")

    # For the expensive strategy, this is just the opposite.  Choose the item that has the highest cost
    # (most expensive) each time.  However, you also need to factor in how much time is left when
    # deciding which item you can buy.
    state_5 = strategy_expensive(
        500000.0, 1.0, [(0.0, None, 0.0, 0.0)], 5.0,
        provided.BuildInfo(
            {
                'A': [5.0, 1.0],
                'C': [50000.0, 3.0],
                'B': [500.0, 2.0]
            }, 1.15))
    suite.run_test(state_5, ("C"), "expect C from test 5")

    # To achieve this, ensure that the simulate_clicker function continues to loop until the strategy function is either:
    # 1) beyond the time limit (not equal to - since it can still buy items with 0.0 seconds remaining); or
    # 2) returns None (because it no longer wants to buy any items)
    #
    state_6 = simulate_clicker(
        provided.BuildInfo({'Cursor': [15.0, 50.0]}, 1.15), 16.0,
        strategy_cursor_broken)
    suite.run_test(state_6.__str__(), (
        "Time: 16.0 Current Cookies: 13.9125 CPS: 151.0 Total Cookies: 66.0 History (length: 4): [(0.0, None, 0.0, 0.0), (15.0, 'Cursor', 15.0, 15.0), (16.0, 'Cursor', 17.25, 66.0), (16.0, 'Cursor', 19.8375, 66.0)]"
    ), "Different message from test6")

    state_7 = simulate_clicker(provided.BuildInfo({\
        'Cursor': [15.0, 0.10000000000000001],\
        'Portal': [1666666.0, 6666.0],\
        'Shipment': [40000.0, 100.0],\
        'Grandma': [100.0, 0.5],\
        'Farm': [500.0, 4.0],\
        'Time Machine': [123456789.0, 98765.0],\
        'Alchemy Lab': [200000.0, 400.0],\
        'Factory': [3000.0, 10.0],\
        'Antimatter Condenser': [3999999999.0, 999999.0],\
        'Mine': [10000.0, 40.0]}, 1.15), 10000000000.0,\
        strategy_expensive)
    suite.run_test(str(state_7.get_cookies()), '2414.64612076',
                   "Expect value 2414.64612076 from test 7.1")
    suite.run_test(str(state_7.get_cps()), '133980795.7',
                   "Expect value 133980795.7 from test 7.2")
    suite.run_test(str(state_7._total_cookies), '6.83676443443e+17',
                   "Expect value 6.83676443443e+17 from test 7.3")
    #print str(state_7.get_history())

    # Best score from strategy
    # https://class.coursera.org/principlescomputing1-004/forum/thread?thread_id=#3
    #
    state_8 = simulate_clicker(provided.BuildInfo({\
        'Cursor': [15.0, 0.10000000000000001],\
        'Portal': [1666666.0, 6666.0],\
        'Shipment': [40000.0, 100.0],\
        'Grandma': [100.0, 0.5],\
        'Farm': [500.0, 4.0],\
        'Time Machine': [123456789.0, 98765.0],\
        'Alchemy Lab': [200000.0, 400.0],\
        'Factory': [3000.0, 10.0],\
        'Antimatter Condenser': [3999999999.0, 999999.0],\
        'Mine': [10000.0, 40.0]}, 1.15), 10000000000.0,\
        strategy_best)
    print 'Best score from strategy ' + str(state_8._total_cookies)

    suite.report_results()
コード例 #9
0
def run_test():
    """
    Run test for Yahtzee.
    """

    suite = TestSuite()

    suite.run_test(yahtzee.score((1, 2, 3, 4, 5)), 5, "Test #1a: score")
    suite.run_test(yahtzee.score((1, 1, 1, 1, 5)), 5, "Test #1b: score")
    suite.run_test(yahtzee.score((2, 2, 2, 2, 5)), 8, "Test #1c: score")
    suite.run_test(yahtzee.score((2, 2, 2, 3, 3)), 6, "Test #1d: score")
    suite.run_test(yahtzee.score((2, 2, 2, 4, 4)), 8, "Test #1e: score")
    suite.run_test(yahtzee.score((5, 5, 6, 6, 6)), 18, "Test #1f: score")

    suite.run_test(yahtzee.expected_value((6, 6, 6, 6), 6, 1), 25.0, \
        "Test #2a: expected_value")
    suite.run_test(yahtzee.expected_value((1, 1, 1, 1), 5, 1), 4.4, \
        "Test #2b: expected_value")
    suite.run_test(yahtzee.expected_value((1, 1, 1, 1), 4, 1), 4.25, \
        "Test #2c: expected_value")
    suite.run_test(yahtzee.expected_value((6, 6, 6), 6, 2), 20.0, \
        "Test #2d: expected_value")
    suite.run_test(yahtzee.expected_value((2, 2, 2), 6, 2), 7.0, \
        "Test #2e: expected_value")
    suite.run_test(yahtzee.expected_value((3, 3), 8, 5), 11.3590087891, \
        "Test #2f: expected_value")

    suite.run_test(yahtzee.gen_all_holds((1, 1, 1, 1, 1)), \
        set([(), (1,), (1, 1), (1, 1, 1), (1, 1, 1, 1), (1, 1, 1, 1, 1)]), \
        "Test #3a: gen_all_holds")
    suite.run_test(yahtzee.gen_all_holds((1, 1, 1, 1, 6)), \
        set([(), (1,), (1, 1), (1, 1, 1), (1, 1, 1, 1), \
            (6,), (1, 6), (1, 1, 6), (1, 1, 1, 6), (1, 1, 1, 1, 6)]), \
        "Test #3b: gen_all_holds")
    suite.run_test(yahtzee.gen_all_holds((1, 2, 3)), \
        set([(), (1,), (1, 2), (1, 2, 3), (1, 3), (2,), (2, 3), (3,)]), \
        "Test #3c: gen_all_holds")

    suite.run_test(yahtzee.strategy((6, 6, 6, 6, 1), 6), \
        (yahtzee.expected_value((6, 6, 6, 6), 6, 1), (6, 6, 6, 6)), \
        "Test #4: strategy")

    suite.report_results()