def test_hierarchical24():
    """
    Test for hierarchical clustering
    Note that hierarchical_clustering mutates cluster_list
    """
    
    # load small data table
    print
    print "Testing hierarchical_clustering on 24 county set"
    data_24_table = load_data_table(DATA_24_URL)
    
    
    # test data of the form [size of output cluster, sets of county tuples]
    hierdata_24 = [[23, set([('11001', '51013'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('34013',), ('34039',), ('34017',), ('36061',), ('36005',), ('36047',), ('36059',), ('36081',), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [22, set([('11001', '51013'), ('36047', '36081'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('34013',), ('34039',), ('34017',), ('36061',), ('36005',), ('36059',), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [21, set([('11001', '51013'), ('36005', '36061'), ('36047', '36081'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('34013',), ('34039',), ('34017',), ('36059',), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [20, set([('11001', '51013'), ('36005', '36061'), ('36047', '36081'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('34039',), ('34013', '34017'), ('36059',), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [19, set([('34013', '34017', '34039'), ('11001', '51013'), ('36005', '36061'), ('36047', '36081'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('36059',), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [18, set([('34013', '34017', '34039'), ('11001', '51013'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('36059',), ('36005', '36047', '36061', '36081'), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [17, set([('11001', '51013'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('36059',), ('34013', '34017', '34039', '36005', '36047', '36061', '36081'), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [16, set([('11001', '51013'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051',), ('41067',), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [15, set([('11001', '51013'), ('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('24510',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051', '41067'), ('51840',), ('51760',), ('55079',), ('54009',)])],
                   [14, set([('01073',), ('06059',), ('06037',), ('06029',), ('06071',), ('06075',), ('08031',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051', '41067'), ('51840',), ('51760',), ('55079',), ('54009',), ('11001', '24510', '51013')])],
                   [13, set([('06037', '06059'), ('01073',), ('06029',), ('06071',), ('06075',), ('08031',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051', '41067'), ('51840',), ('51760',), ('55079',), ('54009',), ('11001', '24510', '51013')])],
                   [12, set([('06037', '06059'), ('01073',), ('06029',), ('06071',), ('06075',), ('08031',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051', '41067'), ('51760',), ('55079',), ('54009',), ('11001', '24510', '51013', '51840')])],
                   [11, set([('06029', '06037', '06059'), ('01073',), ('06071',), ('06075',), ('08031',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051', '41067'), ('51760',), ('55079',), ('54009',), ('11001', '24510', '51013', '51840')])],
                   [10, set([('06029', '06037', '06059'), ('01073',), ('06071',), ('06075',), ('08031',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051', '41067'), ('55079',), ('54009',), ('11001', '24510', '51013', '51760', '51840')])],
                   [9, set([('01073',), ('06029', '06037', '06059', '06071'), ('06075',), ('08031',), ('34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081'), ('41051', '41067'), ('55079',), ('54009',), ('11001', '24510', '51013', '51760', '51840')])],
                   [8, set([('01073',), ('06029', '06037', '06059', '06071'), ('06075',), ('08031',), ('41051', '41067'), ('55079',), ('54009',), ('11001', '24510', '34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081', '51013', '51760', '51840')])],
                   [7, set([('01073',), ('06029', '06037', '06059', '06071'), ('06075',), ('08031',), ('41051', '41067'), ('55079',), ('11001', '24510', '34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081', '51013', '51760', '51840', '54009')])],
                   [6, set([('06029', '06037', '06059', '06071', '06075'), ('01073',), ('08031',), ('41051', '41067'), ('55079',), ('11001', '24510', '34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081', '51013', '51760', '51840', '54009')])],
                   [5, set([('06029', '06037', '06059', '06071', '06075'), ('08031',), ('41051', '41067'), ('01073', '55079'), ('11001', '24510', '34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081', '51013', '51760', '51840', '54009')])],
                   [4, set([('06029', '06037', '06059', '06071', '06075'), ('01073', '11001', '24510', '34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081', '51013', '51760', '51840', '54009', '55079'), ('08031',), ('41051', '41067')])],
                   [3, set([('06029', '06037', '06059', '06071', '06075', '41051', '41067'), ('01073', '11001', '24510', '34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081', '51013', '51760', '51840', '54009', '55079'), ('08031',)])],
                   [2, set([('01073', '11001', '24510', '34013', '34017', '34039', '36005', '36047', '36059', '36061', '36081', '51013', '51760', '51840', '54009', '55079'), ('06029', '06037', '06059', '06071', '06075', '08031', '41051', '41067')])],
                   ]

        
    suite = poc_simpletest.TestSuite()
    
    for num_clusters, expected_county_tuple in hierdata_24:
        
        # build initial list of clusters for each test since mutation is allowed
        cluster_list = []
        for idx in range(len(data_24_table)):
            line = data_24_table[idx]
            cluster_list.append(alg_cluster.Cluster(set([line[0]]), line[1], line[2], line[3], line[4]))

        # compute student answer
        print "start clustering test"
        student_clustering = student.hierarchical_clustering(cluster_list, num_clusters)
        student_county_tuple = set_of_county_tuples(student_clustering)
        
        # Prepare test
        error_message = "Testing hierarchical_clustering on 24 county table, num_clusters = " + str(num_clusters)
        error_message += "\nStudent county tuples: " + str(student_county_tuple)
        error_message += "\nExpected county tuples: " + str(expected_county_tuple)
        suite.run_test(student_county_tuple == expected_county_tuple, True, error_message)

    suite.report_results()
Beispiel #2
0
def run_suite(mc_update_scores):
    """
    run code to test the mc_update_scores function
    """
    suite = poc_simpletest.TestSuite()

    suite.run_test(
        mc_update_scores(
            [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
            provided.TTTBoard(
                3, False,
                [[provided.PLAYERX, provided.PLAYERX, provided.PLAYERO],
                 [provided.PLAYERO, provided.PLAYERX, provided.EMPTY],
                 [provided.EMPTY, provided.PLAYERX, provided.PLAYERO]]), 2),
        [[1.0, 1.0, -1.0], [-1.0, 1.0, 0], [0, 1.0, -1.0]], "Test #1: ")
    suite.run_test(
        mc_update_scores(
            [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
            provided.TTTBoard(
                3, False,
                [[provided.PLAYERX, provided.PLAYERX, provided.PLAYERO],
                 [provided.PLAYERO, provided.PLAYERX, provided.EMPTY],
                 [provided.EMPTY, provided.PLAYERX, provided.PLAYERO]]), 3),
        [[-1.0, -1.0, 1.0], [1.0, -1.0, 0], [0, -1.0, 1.0]], "Test #2: ")

    suite.report_results()
Beispiel #3
0
def run_test():
    """
    Some informal testing code
    """

    # Create a TestSuite object

    suite = poc_simpletest.TestSuite()

    # Test mm_move

    board = provided.TTTBoard(3, board=[[2, 3, 3], [2, 2, 3], [2, 1, 1]])
    suite.run_test(mm_move(board, provided.PLAYERX), (1, (-1, -1)), "Test 1:")

    board = provided.TTTBoard(3, board=[[2, 3, 3], [3, 2, 2], [3, 2, 3]])
    suite.run_test(mm_move(board, provided.PLAYERX), (0, (-1, -1)), "Test 2:")

    board = provided.TTTBoard(3, board=[[3, 3, 3], [3, 2, 2], [3, 2, 2]])
    suite.run_test(mm_move(board, provided.PLAYERX), (-1, (-1, -1)), "Test 3:")

    board = provided.TTTBoard(3, board=[[3, 2, 2], [3, 2, 1], [1, 3, 2]])
    suite.run_test(mm_move(board, provided.PLAYERO), (-1, (2, 0)), "Test 4:")

    board = provided.TTTBoard(3, board=[[3, 2, 1], [3, 2, 1], [2, 3, 2]])
    suite.run_test(mm_move(board, provided.PLAYERO), (0, (0, 2)), "Test 5:")

    board = provided.TTTBoard(3, board=[[3, 2, 1], [3, 2, 2], [1, 3, 2]])
    suite.run_test(mm_move(board, provided.PLAYERO), (-1, (2, 0)), "Test 6:")

    board = provided.TTTBoard(3, board=[[3, 2, 1], [3, 2, 1], [1, 3, 2]])
    suite.run_test(mm_move(board, provided.PLAYERX), (0, (2, 0)), "Test 7:")

    suite.report_results()
Beispiel #4
0
def test_playero():
    suite = poc_simpletest.TestSuite()
    print "Move PlayerO:"
    board = provided.TTTBoard(3, board=[[3, 2, 1], [3, 2, 1], [2, 3, 2]])
    print board
    suite.run_test(move_wrapper(board, provided.PLAYERO, 1), (0, 2), "Test 2.")
    suite.report_results()
Beispiel #5
0
def test_best_move(get_best_move):
    """ Test for get_best_move() """

    print "Testing the get_best_move function."

    # Create a TestSuite object
    suite = poc_simpletest.TestSuite()

    my_board = provided.TTTBoard(3)
    set_board(my_board, [[2, 3, 2], [1, 1, 1], [1, 2, 3]])
    scores = [[3.0, 5.0, -1.0], [3.0, 2.0, -8.0], [4.0, -2.0, 2.0]]

    print my_board
    print "scores:", scores
    suite.run_test(get_best_move(my_board, scores), (2, 0),
                   "Test 1: Best move")

    my_board = provided.TTTBoard(3)
    set_board(my_board, [[1, 1, 2], [1, 3, 1], [2, 3, 1]])
    scores = [[0.0, 2.0, 1.0], [0.0, 2.0, -1.0], [1.0, -2.0, 2.0]]
    move_set = set([])
    for dummy_idx in range(20):
        move_set.add(get_best_move(my_board, scores))

    print my_board
    print "scores:", scores
    suite.run_test(move_set, set([(0, 1), (2, 2)]),
                   "Test 2: Two possible best moves")

    suite.report_results()
def run_test2(intersect):

    # create a TestSuite object
    suite = poc_simpletest.TestSuite()

    suite.run_test(intersect([], [2, 3, 4]), [], "Test #1: 1st list empty")
    suite.run_test(intersect([1, 2, 3], []), [], "Test #2: 2nd list empty")
    suite.run_test(intersect([], []), [], "Test #3: Both lists empty")
    suite.run_test(intersect([1, 3, 4, 8], [2, 3, 4, 7]), [3, 4],
                   "Test #4: Same length, shared in middle")
    suite.run_test(intersect([1, 3, 4, 8], [1, 3, 5, 8]), [1, 3, 8],
                   "Test #5: Same length, shared at ends")
    suite.run_test(intersect([1, 2, 3], [1, 2, 3]), [1, 2, 3],
                   "Test #6: All shared")
    suite.run_test(intersect([1, 2, 3], [4, 5, 6]), [], "Test #7: No shared")
    suite.run_test(intersect([1, 3, 4, 5, 6], [2, 4, 5, 7]), [4, 5],
                   "Test #8: 1st longer, shared in middle")
    suite.run_test(intersect([1, 3, 4, 5], [2, 3, 4, 6, 7, 8]), [3, 4],
                   "Test #9: 2nd longer, shared in middle")
    suite.run_test(intersect([1, 2, 3, 5], [1, 2, 4]), [1, 2],
                   "Test #10: 1st longer, shared at start")
    suite.run_test(intersect([1, 2, 5, 7], [1, 2, 3, 4, 5, 8]), [1, 2, 5],
                   "Test #11: 2nd longer, shared at start")
    suite.run_test(intersect([1, 2, 3, 5, 6, 8, 9], [5, 6, 7, 8, 9]),
                   [5, 6, 8, 9], "Test #12: 1st longer, shared at end")
    suite.run_test(intersect([1, 2, 5], [2, 3, 4, 5]), [2, 5],
                   "Test #13: 2nd longer, shared at end")
    suite.run_test(
        intersect([1, 2, 5, 9, 12, 22, 25, 26, 27, 30],
                  [2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 26, 27]),
        [2, 5, 12, 26, 27], "Test #14: Long lists")

    suite.report_results()
def test_suite2():

    # create a TestSuite object
    suite = poc_simpletest.TestSuite()

    #create boards to test
    b0 = SolitaireMancala()

    b1 = SolitaireMancala()
    config1 = [0, 1, 2, 3, 4, 5, 7]
    b1.set_board(config1)

    b2 = SolitaireMancala()
    config2 = [0, 0, 0, 0, 0, 0, 1]
    b2.set_board(config2)

    b3 = SolitaireMancala()
    config2 = [5, 0, 0, 0, 0, 0, 0]
    b3.set_board(config2)

    # test the method
    suite.run_test(b0.is_game_won(), True, "Test #1:")
    suite.run_test(b1.is_game_won(), False, "Test #2:")
    suite.run_test(b2.is_game_won(), False, "Test #3:")
    suite.run_test(b3.is_game_won(), True, "Test #4:")

    #report test results
    suite.report_results()
Beispiel #8
0
def simulate_clicker_with_mocks(simulate_clicker):
    """
    Testing the simulate_clicker method itself
    """
    print_header("Starting tests for simulate_clicker using a test strategy")    
    
     # create a TestSuite object
    suite = poc_simpletest.TestSuite()
    
    default_cost = 15.0
    default_cps = 0.1
    
    build_info_mock = BuildInfoMock(default_cost,default_cps);
    strategy_interceptor = StrategyCallInterceptor(["my_item","my_other_item","the_last_item"])
    state = simulate_clicker(build_info_mock, 100, strategy_interceptor.test_strategy)
    
    calls = build_info_mock.get_captured_calls()

    explanation = "\nThis test verifies, that you do not call the same methods more than once per\nturn in the main loop of the simulate_clicker function. However, you can call it as often\nas you like per turn but in general you should call a method once and store it into a\nvariable to avoid too many method calls. (You never know how long the computation within\na method of may take, if you don't know the code within)\n\n"
    
    suite.run_test(calls['clone'], [[]], "Test #1: BuildInfo object was not cloned!\n"+explanation)        
    suite.run_test(calls['get_cost'], ['my_item', 'my_other_item', 'the_last_item'], "Test #2: BuildInfo.get_cost should have been called 3 times but was "+str(len(calls['get_cost']))+" times!\n"+explanation)        
    suite.run_test(calls['get_cps'], ['my_item', 'my_other_item', 'the_last_item'], "Test #3: BuildInfo.get_cps should have been called 3 times but was "+str(len(calls['get_cps']))+" times!\n"+explanation)        
    suite.run_test(calls['update_item'], ['my_item', 'my_other_item', 'the_last_item'], "Test #4: BuildInfo.update_item should have been called 3 times but was "+str(len(calls['get_cps']))+" times!\n"+explanation)        
    
    suite.run_test(state.get_time(), 100.0, "Test #5: ClickerState.get_time was not correct after simulate_clicker. Did you forget to wait until the end of the duration?\n")        
    suite.run_test(str(state.get_cps()), str(1.3), "Test #6: ClickerState.get_cps was not correct after simulate_clicker. Make sure you were buying the items and the buy function works correctly.\n")        
    suite.run_test(str(state.get_cookies()), str(76.4), "Test #7: ClickerState.get_cookies was not correct after simulate_clicker. Make sure you were buying the items and accumulate cookies correctly.\n")        
    suite.run_test(str(state.get_history()), "[(0.0, None, 0.0, 0.0), (15.0, 'my_item', 15.0, 15.0), (29.0, 'my_other_item', 15.0, 30.4), (42.0, 'the_last_item', 15.0, 46.0)]", "Test #8: Your history was not correct. This may be due to some error in the way you buy items within the simulate_clicker function.\n")        
    
    suite.report_results()
def run_suite(gen_all_holds):
    """
    Some informal testing code for gen_all_holds
    """

    # create a TestSuite object
    suite = poc_simpletest.TestSuite()

    # test gen_all_holds on various inputs
    hand = tuple([])
    suite.run_test(gen_all_holds(hand), set([()]), "Test #1:")

    hand = tuple([2, 4])
    suite.run_test(gen_all_holds(hand), set([(), (2, ), (4, ), (2, 4)]),
                   "Test #2:")

    hand = tuple((1, 2, 2))
    suite.run_test(gen_all_holds(hand),
                   set([(), (1, ), (2, ), (1, 2), (2, 2), (1, 2, 2)]),
                   "Test #3:")

    hand = tuple((3, 3, 3))
    suite.run_test(gen_all_holds(hand), set([(), (3, ), (3, 3), (3, 3, 3)]),
                   "Test #4:")

    hand = tuple([2, 3, 6])
    suite.run_test(
        gen_all_holds(hand),
        set([(), (2, ), (3, ), (6, ), (2, 3), (2, 6), (3, 6), (2, 3, 6)]),
        "Test #5:")

    suite.report_results()
Beispiel #10
0
def test_playerx():
    suite = poc_simpletest.TestSuite()
    print "Move PlayerX:"
    board = provided.TTTBoard(3, board=[[3, 2, 1], [3, 2, 1], [1, 3, 2]])
    print board
    suite.run_test(move_wrapper(board, provided.PLAYERX, 1), (2, 0), "Test 1.")
    suite.report_results()
def test_suite3():

    # create a TestSuite object
    suite = poc_simpletest.TestSuite()

    #create boards to test
    b0 = SolitaireMancala()

    b1 = SolitaireMancala()
    config1 = [0, 1, 2, 3, 4, 5, 7]
    b1.set_board(config1)

    b2 = SolitaireMancala()
    config2 = [0, 0, 0, 0, 0, 0, 1]
    b2.set_board(config2)

    b3 = SolitaireMancala()
    config2 = [5, 0, 0, 0, 0, 0, 0]
    b3.set_board(config2)

    # test the method
    suite.run_test(b1.apply_move(1), [1, 0, 2, 3, 4, 5, 7], "Test #1:")
    suite.run_test(b1.apply_move(5), [2, 1, 3, 4, 5, 0, 7], "Test #2:")
    suite.run_test(b1.apply_move(5), [2, 1, 3, 4, 5, 0, 7], "Test #3:")
    suite.run_test(b2.apply_move(6), [0, 0, 0, 0, 0, 0, 1], "Test #4:")

    #report results
    suite.report_results()
def run_test1(remove_duplicates):

    # create a TestSuite object
    suite = poc_simpletest.TestSuite()

    suite.run_test(remove_duplicates([1, 1, 2, 3, 4, 4, 5, 6, 7, 7]),
                   [1, 2, 3, 4, 5, 6, 7], "Test #1: Duplicates at ends")
    suite.run_test(remove_duplicates([1, 2, 3, 3, 4, 4, 5, 5, 6, 7]),
                   [1, 2, 3, 4, 5, 6, 7], "Test #2: Duplicates in middle")
    suite.run_test(
        remove_duplicates(
            [22, 22, 21, 21, 21, 20, 18, 15, 9, 9, 8, 7, 6, 6, 5, 2,
             2]), [22, 21, 20, 18, 15, 9, 8, 7, 6, 5, 2],
        "Test #3: Reverse order dups at ends")
    suite.run_test(
        remove_duplicates([22, 21, 21, 21, 20, 18, 15, 9, 9, 8, 7, 6, 6, 5,
                           2]), [22, 21, 20, 18, 15, 9, 8, 7, 6, 5, 2],
        "Test #4: Reverse order dups in middle")
    suite.run_test(remove_duplicates([4, 5, 6, 9, 15, 22]),
                   [4, 5, 6, 9, 15, 22], "Test #5: No Duplicates")
    suite.run_test(remove_duplicates([22, 16, 8, 7, 6,
                                      5]), [22, 16, 8, 7, 6, 5],
                   "Test #6: No Duplicates Reverse order")
    suite.run_test(remove_duplicates([4, 4]), [4],
                   "Test #7: a pair of Duplicates")
    suite.run_test(remove_duplicates([4]), [4], "Test #8: single element")
    suite.run_test(remove_duplicates([]), [], "Test #9: empty string")

    suite.report_results()
Beispiel #13
0
def run_suite(game_class):
    """
    Some informal testing code
    """
    
    # create a TestSuite object
    suite = poc_simpletest.TestSuite()    
    
    # create a game
    game = game_class()
    
    # add tests using suite.run_test(....) here

    # test the initial configuration of the board using the str method
    suite.run_test(str(game), str([0]), "Test #0: init")

    # check the str and get_num_seeds methods
    config1 = [0, 0, 1, 1, 3, 5, 0]    
    game.set_board(config1)   
    suite.run_test(str(game), str([0, 5, 3, 1, 1, 0, 0]), "Test #1a: str")
    suite.run_test(game.get_num_seeds(1), config1[1], "Test #1b: get_num_seeds")
    suite.run_test(game.get_num_seeds(3), config1[3], "Test #1c: get_num_seeds")
    suite.run_test(game.get_num_seeds(5), config1[5], "Test #1d: get_num_seeds")    
    
    # report number of tests and failures
    suite.report_results()
def test_compute_local_alignment():
    """
    Test the function compute_global_alignment function
    """
    suite = poc_simpletest.TestSuite()
    scoring_matrix = proj4_solution.build_scoring_matrix(
        set(['A', 'C', 'T', 'G']), 10, 4, -6)
    alignment_matrix = proj4_solution.compute_alignment_matrix(
        'AA', 'TAAT', scoring_matrix, False)
    local_alignment_sequence = proj4_solution.compute_local_alignment(
        'AA', 'TAAT', scoring_matrix, alignment_matrix)
    print local_alignment_sequence
    suite.run_test(local_alignment_sequence, (20, 'AA', 'AA'), "Error Found")

    scoring_matrix = proj4_solution.build_scoring_matrix(
        set(['A', 'C', 'T', 'G']), 10, 2, -4)
    alignment_matrix = proj4_solution.compute_alignment_matrix(
        '---AC-C--', 'TTTACACGG', scoring_matrix, False)
    local_alignment_sequence = proj4_solution.compute_local_alignment(
        '---AC-C--', 'TTTACACGG', scoring_matrix, alignment_matrix)
    print local_alignment_sequence
    suite.run_test(local_alignment_sequence, (26, 'AC-C', 'ACAC'),
                   "Error Found")

    local_alignment_sequence = proj4_solution.compute_local_alignment(
        'A', 'A', {
            'A': {
                'A': 6,
                'C': 2,
                '-': -4,
                'T': 2,
                'G': 2
            },
            'C': {
                'A': 2,
                'C': 6,
                '-': -4,
                'T': 2,
                'G': 2
            },
            '-': {
                'A': -4,
                'C': -4,
                '-': -4,
                'T': -4,
                'G': -4
            },
            'G': {
                'A': 2,
                'C': 2,
                '-': -4,
                'T': 2,
                'G': 6
            }
        }, [[0, 0], [0, 6]])
    print local_alignment_sequence
    suite.run_test(local_alignment_sequence, (6, 'A', 'A'), "Error Found")

    suite.report_results()
Beispiel #15
0
def test_expected_value():
    suite = poc_simpletest.TestSuite()
    held_dice = ()
    num_die_sides = 6
    num_free_dice = 2
    suite.run_test(
        round(
            expected_value(held_dice, num_die_sides, num_free_dice), 7), round(
                5.0555556, 7), "Test #1:")

    held_dice = (2, 1, 2)
    num_die_sides = 6
    num_free_dice = 3
    suite.run_test(
        round(
            expected_value(held_dice, num_die_sides, num_free_dice), 7), round(
                6.9120370, 7), "Test #2:")

    held_dice = (2, )
    num_die_sides = 6
    num_free_dice = 5
    suite.run_test(
        round(
            expected_value(held_dice, num_die_sides, num_free_dice), 7), round(
                8.8801440, 7), "Test #3:")

    held_dice = (1, )
    num_die_sides = 6
    num_free_dice = 2
    suite.run_test(
        round(
            expected_value(held_dice, num_die_sides, num_free_dice), 7), round(
                5.0833333, 7), "Test #4:")

    held_dice = (2, 1)
    num_die_sides = 6
    num_free_dice = 3
    suite.run_test(
        round(
            expected_value(held_dice, num_die_sides, num_free_dice), 7), round(
                6.4722222, 7), "Test #5:")

    held_dice = (2, 2)
    num_die_sides = 6
    num_free_dice = 5
    suite.run_test(
        round(
            expected_value(held_dice, num_die_sides, num_free_dice), 7), round(
                9.2250514, 7), "Test #6:")

    held_dice = (1, 2)
    num_die_sides = 6
    num_free_dice = 4
    suite.run_test(
        round(
            expected_value(held_dice, num_die_sides, num_free_dice), 7), round(
                7.6689815, 7), "Test #7:")

    suite.report_results()
Beispiel #16
0
def run_suite(GameClass):
    """
    Some informal testing code
    """

    # creating a TestSuite object
    clicker = GameClass()
    suite = poc_simpletest.TestSuite()

    # testing the __init__() and __str__() methods
    suite.run_test(str(clicker), str([0.0, 1.0, 0.0, 0.0]), "Test #1.1: init.")
    suite.run_test(clicker.get_history(), [(0.0, None, 0.0, 0.0)],
                   "Test 1.2: get_history")

    # testing the wait method
    clicker.wait(-1)
    suite.run_test(str(clicker), str([0.0, 1.0, 0.0, 0.0]), "Test #2.1: wait.")

    clicker.wait(0)
    suite.run_test(str(clicker), str([0.0, 1.0, 0.0, 0.0]), "Test #2.2: wait.")

    clicker.wait(530)
    suite.run_test(str(clicker), str([530.0, 1.0, 530.0, 530.0]),
                   "Test #2.3: wait.")

    clicker.wait(10.5)
    suite.run_test(str(clicker), str([540.5, 1.0, 540.5, 540.5]),
                   "Test #2.4: wait.")

    clicker.buy_item("Tester #1", 500, 3.0)
    clicker.wait(10.5)
    suite.run_test(str(clicker), str([551.0, 4.0, 82.5, 582.5]),
                   "Test #2.5: wait.")

    # testing the time_until() method
    suite.run_test(clicker.time_until(100), 5.0, "Test #3.1: time_until.")
    suite.run_test(clicker.time_until(80), 0.0, "Test #3.2: time_until.")
    suite.run_test(clicker.time_until(82.5), 0.0, "Test #3.3: time_until.")
    suite.run_test(clicker.time_until(83), 1.0, "Test #3.4: time_until.")

    # testing the buy_item() method
    clicker.buy_item("Tester #2", 83, 1.5)
    history_lst = [(0.0, None, 0.0, 0.0), (540.5, "Tester #1", 500, 540.5)]
    suite.run_test(clicker.get_history(), history_lst, "Test #4.1: buy_item.")
    suite.run_test(str(clicker), str([551.0, 4.0, 82.5, 582.5]),
                   "Test #4.2: buy_item.")

    clicker.wait(50)
    clicker.buy_item("Tester #3", 42.5, 2)
    history_lst.append((601.0, "Tester #3", 42.5, 782.5))
    suite.run_test(clicker.get_history(), history_lst, "Test #4.3: buy_item.")
    suite.run_test(str(clicker), str([601.0, 6.0, 240.0, 782.5]),
                   "Test 4.4: buy_item.")

    # one more test of time_until
    suite.run_test(clicker.time_until(480.0), 40.0, "Test 4.5 time_until.")

    # reporting the results of the test
    suite.report_results()
Beispiel #17
0
def test_score():
    suite = poc_simpletest.TestSuite()
    suite.run_test(score([1, 2, 3, 4, 5, 6]), 6, "Test 0: Baisc functionality")
    suite.run_test(score([1, 2, 3, 4, 6, 6]), 12, "Test 1: two are the same.")
    suite.run_test(
        score([1, 1, 1, 1, 1, 5]), 5, "Test 2: two combinatories, same answer")

    suite.report_results()
Beispiel #18
0
def run_suite(
    TwentyFortyEight
):  # here we only pass a class reference, from which we are going to create an object later on
    """ Some informal testing code """
    suite = poc_simpletest.TestSuite()  # create a TestSuite object

    # 1. test 'merge' on various inputs
    suite.run_test(game.merge([2, 0, 2, 2]), [4, 2, 0, 0], "Test #1.1: merge")
    suite.run_test(game.merge([2, 0, 2, 4]), [4, 4, 0, 0], "Test #1.2: merge")
    suite.run_test(game.merge([0, 0, 2, 2]), [4, 0, 0, 0], "Test #1.3: merge")
    suite.run_test(game.merge([2, 2, 0, 0]), [4, 0, 0, 0], "Test #1.4: merge")
    suite.run_test(game.merge([2, 2, 2, 2, 2]), [4, 4, 2, 0, 0],
                   "Test #1.5: merge")
    suite.run_test(game.merge([8, 16, 16, 8]), [8, 32, 8, 0],
                   "Test #1.6: merge")
    suite.run_test(game.merge([4, 2, 2]), [4, 4, 0], "Test #1.7: merge")

    # 2. test 'expected_value' on various inputs
    obj = TwentyFortyEight(4, 4)
    obj.set_tile(0, 0,
                 0), obj.set_tile(0, 1,
                                  0), obj.set_tile(0, 2,
                                                   4), obj.set_tile(0, 3, 2)
    obj.set_tile(1, 0,
                 0), obj.set_tile(1, 1,
                                  0), obj.set_tile(1, 2,
                                                   4), obj.set_tile(1, 3, 2)
    obj.set_tile(2, 0,
                 0), obj.set_tile(2, 1,
                                  0), obj.set_tile(2, 2,
                                                   4), obj.set_tile(2, 3, 2)
    obj.set_tile(3, 0,
                 0), obj.set_tile(3, 1,
                                  0), obj.set_tile(3, 2,
                                                   4), obj.set_tile(3, 3, 2)
    print(obj)
    suite.run_test(obj.get_tile(0, 0), 0,
                   "Test #2.1: checkng the value of a tile - before the move")
    suite.run_test(obj.get_tile(1, 0), 0,
                   "Test #2.2: checkng the value of a tile - before the move")
    suite.run_test(obj.get_tile(2, 0), 0,
                   "Test #2.3: checkng the value of a tile - before the move")
    suite.run_test(obj.get_tile(3, 0), 0,
                   "Test #2.4: checkng the value of a tile - before the move")

    obj.move(game.LEFT)  # now we move everything to the left
    suite.run_test(obj.get_tile(0, 0), 4,
                   "Test #2.5: checkng the value of a tile - after the move")
    suite.run_test(obj.get_tile(1, 0), 4,
                   "Test #2.6: checkng the value of a tile - after the move")
    suite.run_test(obj.get_tile(2, 0), 4,
                   "Test #2.7: checkng the value of a tile - after the move")
    suite.run_test(obj.get_tile(3, 0), 4,
                   "Test #2.8: checkng the value of a tile - after the move")
    print(obj)

    # 3. report number of tests and failures
    suite.report_results()
def run_ev(expected_value):
    """
    Test for expected_value in "Yahtzee"
    """
    # create a TestSuite object
    suite = poc_simpletest.TestSuite()

    # test expected_value on various inputs
    held_dice = ()
    num_die_sides = 6
    num_free_dice = 2
    suite.run_test(
        round(expected_value(held_dice, num_die_sides, num_free_dice), 7),
        round(5.0555556, 7), "Test #1:")

    held_dice = (2, 1, 2)
    num_die_sides = 6
    num_free_dice = 3
    suite.run_test(
        round(expected_value(held_dice, num_die_sides, num_free_dice), 7),
        round(6.9120370, 7), "Test #2:")

    held_dice = (2, )
    num_die_sides = 6
    num_free_dice = 5
    suite.run_test(
        round(expected_value(held_dice, num_die_sides, num_free_dice), 7),
        round(8.8801440, 7), "Test #3:")

    held_dice = (1, )
    num_die_sides = 6
    num_free_dice = 2
    suite.run_test(
        round(expected_value(held_dice, num_die_sides, num_free_dice), 7),
        round(5.0833333, 7), "Test #4:")

    held_dice = (2, 1)
    num_die_sides = 6
    num_free_dice = 3
    suite.run_test(
        round(expected_value(held_dice, num_die_sides, num_free_dice), 7),
        round(6.4722222, 7), "Test #5:")

    held_dice = (2, 2)
    num_die_sides = 6
    num_free_dice = 5
    suite.run_test(
        round(expected_value(held_dice, num_die_sides, num_free_dice), 7),
        round(9.2250514, 7), "Test #6:")

    held_dice = (1, 2)
    num_die_sides = 6
    num_free_dice = 4
    suite.run_test(
        round(expected_value(held_dice, num_die_sides, num_free_dice), 7),
        round(7.6689815, 7), "Test #7:")

    suite.report_results()
def test():
    """
    Test code for X
    """

    suite = poc_simpletest.TestSuite()
    suite.run_test("Computed", "Expected", "Test #: Testing X")

    suite.report_results()
Beispiel #21
0
def test_update_scores(mc_update_scores, mcmatch, mcother):
    """ Test for mc_update_scores() """

    print "Testing the mc_update_scores function with a sequence of scoring."
    print "Try setting different MCMATCH/MCOTHER values for this test."
    print "MCMATCH:", mcmatch
    print "MCOTHER:", mcother
    print

    # Create a TestSuite object
    suite = poc_simpletest.TestSuite()
    scores = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]

    manual_scoring(mc_update_scores, mcmatch, mcother, scores,
                   provided.PLAYERX, [[2, 1, 3], [3, 2, 1], [2, 3, 2]])
    print
    suite.run_test(scores, [[mcmatch, 0.0, -mcother], [-mcother, mcmatch, 0.0],
                            [mcmatch, -mcother, mcmatch]],
                   "Test 1: X won, player is X")
    print
    manual_scoring(mc_update_scores, mcmatch, mcother, scores,
                   provided.PLAYERO, [[2, 1, 3], [3, 2, 1], [2, 3, 2]])
    print
    suite.run_test(
        scores, [[mcmatch + mcother, 0.0, -mcother - mcmatch],
                 [-mcother - mcmatch, mcmatch + mcother, 0.0],
                 [mcmatch + mcother, -mcother - mcmatch, mcmatch + mcother]],
        "Test 2: Same game, X won, player is O")
    print
    manual_scoring(mc_update_scores, mcmatch, mcother, scores,
                   provided.PLAYERX, [[2, 3, 2], [3, 3, 2], [3, 2, 3]])
    print
    suite.run_test(
        scores, [[mcmatch + mcother, 0.0, -mcother - mcmatch],
                 [-mcother - mcmatch, mcmatch + mcother, 0.0],
                 [mcmatch + mcother, -mcother - mcmatch, mcmatch + mcother]],
        "Test 3: Tied game")
    print
    manual_scoring(mc_update_scores, mcmatch, mcother, scores,
                   provided.PLAYERX, [[1, 3, 2], [2, 3, 1], [1, 3, 2]])
    print
    suite.run_test(scores,
                   [[mcmatch + mcother, mcother, -mcother - 2 * mcmatch],
                    [-mcother - 2 * mcmatch, mcmatch + 2 * mcother, 0.0],
                    [mcmatch + mcother, -mcmatch, mcother]],
                   "Test 4: O won, player is X")
    print
    manual_scoring(mc_update_scores, mcmatch, mcother, scores,
                   provided.PLAYERO, [[1, 2, 2], [3, 3, 3], [3, 2, 2]])
    print
    suite.run_test(scores,
                   [[mcmatch + mcother, 0.0, -2 * mcother - 2 * mcmatch],
                    [-mcother - mcmatch, 2 * mcmatch + 2 * mcother, mcmatch],
                    [2 * mcmatch + mcother, -mcmatch - mcother, 0.0]],
                   "Test 5: O won, player is O")

    suite.report_results()
Beispiel #22
0
def run_suite(mc_trial):
    """
    run code to test the mc_trial function
    """
    suite = poc_simpletest.TestSuite()

    suite.run_test(mc_trial("board", "player"), "expected", "Test #1:")

    suite.report_results()
def test_mc_trial(mc_trial):
    """
    Test the mc_trial method:
    1) The trial ends with a win or a draw
    2) The trial does not modify already occupied spaces 
    3) The trial alternates players properly
    """

    # Create a test suite
    suite0 = poc_simpletest.TestSuite()

    # Create a 3x3 board
    board = provided.TTTBoard(3)

    # Run a single trial
    mc_trial(board, provided.PLAYERX)

    # Check that the trial ends with the game won or a draw
    suite0.run_test(board.check_win() != None, True,
                    "Test 1: mc_trial ends with winner or draw: ")

    # Create another 3x3 board
    board = provided.TTTBoard(3)

    # Place some squares on the board
    board.move(0, 0, provided.PLAYERX)
    board.move(0, 1, provided.PLAYERO)
    board.move(0, 2, provided.PLAYERX)

    # Display the initial board
    print "Initial Board: \n", board

    # Run a single trial
    mc_trial(board, provided.PLAYERO)

    # Display the board after the trial
    print "Board after Monte Carlo trial: \n", board

    # Check that the spaces that were already occupied were not modified by the trial
    suite0.run_test(board.square(0, 0), provided.PLAYERX,
                    "Test 2A: mc_trial did not modify existing pieces: ")
    suite0.run_test(board.square(0, 1), provided.PLAYERO,
                    "Test 2B: mc_trial did not modify existing pieces: ")
    suite0.run_test(board.square(0, 2), provided.PLAYERX,
                    "Test 2C: mc_trial did not modify existing pieces: ")

    # Get the number of squares occupied by each player
    num_xs = get_num_squares(board, provided.PLAYERX)
    num_os = get_num_squares(board, provided.PLAYERO)

    # Check that the trial switched players properly
    suite0.run_test(
        math.fabs(num_xs - num_os) <= 1, True,
        "Test 3: mc_trial altered player turns: ")

    suite0.report_results()
Beispiel #24
0
def test_remove_duplicates():
    suite = poc_simpletest.TestSuite()
    print("test_remove_duplicates():"),
    suite.run_test(mycode.remove_duplicates([]), [], "Test 0")
    suite.run_test(mycode.remove_duplicates([1]), [1], "Test 1")
    suite.run_test(mycode.remove_duplicates([1, 1, 1, 1, 2, 3]), [1, 2, 3],
                   "Test 2")
    suite.run_test(mycode.remove_duplicates([1, 2, 2, 2, 2, 3, 3]), [1, 2, 3],
                   "Test 3")
    suite.report_results()
Beispiel #25
0
def test_merge_sort():
    suite = poc_simpletest.TestSuite()
    print("test_merge_sorty():"),
    suite.run_test(mycode.merge_sort([]), [], "Test 0")
    suite.run_test(mycode.merge_sort([1]), [1], "Test 1")
    suite.run_test(mycode.merge_sort([1, 2, 3]), [1, 2, 3], "Test 2")
    suite.run_test(mycode.merge_sort([1, 4, 2, 3]), [1, 2, 3, 4], "Test 3")
    suite.run_test(mycode.merge_sort([38, 27, 43, 3, 9, 82, 10]),
                   [3, 9, 10, 27, 38, 43, 82], "Test 4")
    suite.report_results()
Beispiel #26
0
def test_gen_all_strings():
    suite = poc_simpletest.TestSuite()
    print("test_gen_all_strings():"),
    suite.run_test(
        set(mycode.gen_all_strings("aab")),
        set([
            "", "b", "a", "ab", "ba", "a", "ab", "ba", "aa", "aa", "aab",
            "aab", "aba", "aba", "baa", "baa"
        ]), "Test")
    suite.report_results()
def run_suite(get_best_move):
    """
    run code to test the mc_move function
    """
    suite = poc_simpletest.TestSuite()

    suite.run_suite(get_best_move("board", "scores"), "expected outcome",
                    "Test #1: ")

    suite.report_results
Beispiel #28
0
def test_strategy(func):

    suite = poc_simpletest.TestSuite()

    suite.run_test(func((1, 2), 2), (3.0, (2, )),
                   "Test 1: two-sided die, hand is (1,2).")
    suite.run_test(func((1, 2), 3), (28 / 9.0, ()),
                   "Test 2: three-sided die, hand is (1,2).")

    suite.report_results()
def run_strategy_suite(strategy):
    """
    Some informal testing code for strategy
    """

    suite = poc_simpletest.TestSuite()

    hand = tuple([])
    sides = 6
    suite.run_test(strategy(hand, sides)[0], 0.0, "strategy: empty hand")
    suite.run_test(strategy(hand, sides)[1], (), "strategy: empty hand")

    hand = tuple([1])
    sides = 5
    suite.run_test(
        strategy(hand, sides)[0], 3.0, "strategy: holding one low value card")
    suite.run_test(
        strategy(hand, sides)[1], (), "strategy: holding one low value card")

    hand = tuple([5])
    sides = 5
    suite.run_test(
        strategy(hand, sides)[0], 5.0, "strategy: holding one high value card")
    suite.run_test(
        strategy(hand, sides)[1], (5, ),
        "strategy: holding one high value card")

    hand = tuple([5, 5])
    sides = 5
    suite.run_test(
        strategy(hand, sides)[0], 10.0, "strategy: holding high  pair")
    suite.run_test(
        strategy(hand, sides)[1], (5, 5), "strategy: holding high  pair")

    hand = tuple([1, 1])
    sides = 5
    suite.run_test(strategy(hand, sides)[0], 4.4, "strategy: holding low pair")
    suite.run_test(strategy(hand, sides)[1], (), "strategy: holding low pair")

    hand = tuple([5, 1])
    sides = 5
    suite.run_test(
        strategy(hand, sides)[0], 6.0, "strategy: holding high/low pair")
    suite.run_test(
        strategy(hand, sides)[1], (5, ), "strategy: holding high/low pair")

    hand = tuple([3, 3, 3])
    sides = 5
    suite.run_test(
        strategy(hand, sides)[0], 9.0, "strategy: holding mid-value triplet")
    suite.run_test(
        strategy(hand, sides)[1], (3, 3, 3),
        "strategy: holding mid-value triplet")

    suite.report_results()
Beispiel #30
0
def run_suite(strategy_best):
    """
    Some informal testing code for strategy
    """
    
    # create a TestSuite object
    suite = poc_simpletest.TestSuite()
    
    suite.run_test(simulate_clicker(provided.BuildInfo(), SIM_TIME, strategy_best), "produced 10000000000.0 total cookies", "Test #1:")

    suite.report_results()