示例#1
0
def test_move_up_double_different_equal():
    initial_state = Board.from_matrix([[4, 0, 0, 0], [4, 0, 0, 0],
                                       [2, 0, 0, 0], [2, 0, 0, 0]])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result,
                  [[8, 0, 0, 0], [4, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#2
0
def test_move_up_multiple_opposite():
    initial_state = Board.from_matrix([[0, 0, 0, 0], [0, 0, 0, 0],
                                       [0, 0, 0, 0], [2, 4, 8, 16]])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result,
                  [[2, 4, 8, 16], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#3
0
def test_move_right_middle_equal():
    initial_state = Board.from_matrix([[0, 2, 2, 0], [0, 0, 0, 0],
                                       [0, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result,
                  [[0, 0, 0, 4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#4
0
def test_move_right_multiple_columns():
    initial_state = Board.from_matrix([[0, 0, 0, 0], [0, 0, 8, 8],
                                       [0, 0, 0, 2], [0, 0, 0, 4]])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result,
                  [[0, 0, 0, 0], [0, 0, 0, 16], [0, 0, 0, 2], [0, 0, 0, 4]])
示例#5
0
def test_move_right_double_different_equal():
    initial_state = Board.from_matrix([[4, 4, 2, 2], [0, 0, 0, 0],
                                       [0, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result,
                  [[0, 0, 8, 4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#6
0
def test_move_left_multiple_columns():
    initial_state = Board.from_matrix([[0, 0, 0, 0], [8, 8, 0, 0],
                                       [2, 0, 0, 0], [4, 0, 0, 0]])

    result = initial_state.move(Action.move_left).to_matrix()
    assert_equals(result,
                  [[0, 0, 0, 0], [16, 0, 0, 0], [2, 0, 0, 0], [4, 0, 0, 0]])
示例#7
0
def test_move_left_last_column():
    initial_state = Board.from_matrix([[0, 0, 0, 2], [0, 0, 0, 4],
                                       [0, 0, 0, 8], [0, 0, 0, 16]])

    result = initial_state.move(Action.move_left).to_matrix()
    assert_equals(result,
                  [[2, 0, 0, 0], [4, 0, 0, 0], [8, 0, 0, 0], [16, 0, 0, 0]])
示例#8
0
def test_move_left_double_equal():
    initial_state = Board.from_matrix([[2, 2, 2, 2], [0, 0, 0, 0],
                                       [0, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_left).to_matrix()
    assert_equals(result,
                  [[4, 4, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#9
0
def test_move_down_first_equal():
    initial_state = Board.from_matrix([[0, 0, 0, 0], [0, 0, 0, 0],
                                       [2, 0, 0, 0], [2, 0, 0, 0]])

    result = initial_state.move(Action.move_down).to_matrix()
    assert_equals(result,
                  [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [4, 0, 0, 0]])
示例#10
0
def test_move_left_empty():
    initial_state = Board.from_matrix([[0, 0, 0, 0], [0, 0, 0, 0],
                                       [0, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_left).to_matrix()
    assert_equals(result,
                  [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#11
0
def test_move_up_multiple_columns():
    initial_state = Board.from_matrix([[0, 8, 2, 4], [0, 8, 0, 0],
                                       [0, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result,
                  [[0, 16, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#12
0
def test_move_right_first_equal_with_follower():
    initial_state = Board.from_matrix([[0, 2, 2, 2], [0, 0, 0, 0],
                                       [0, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result,
                  [[0, 0, 2, 4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#13
0
def test_move_up_first_equal_with_follower():
    initial_state = Board.from_matrix([[2, 0, 0, 0], [2, 0, 0, 0],
                                       [2, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result,
                  [[4, 0, 0, 0], [2, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#14
0
def test_move_up_first_row():
    initial_state = Board.from_matrix([[2, 4, 8, 16], [0, 0, 0, 0],
                                       [0, 0, 0, 0], [0, 0, 0, 0]])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result,
                  [[2, 4, 8, 16], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
示例#15
0
def test_move_right_multiple_opposite():
    initial_state = Board.from_matrix([[2, 0, 0, 0], [4, 0, 0, 0],
                                       [8, 0, 0, 0], [16, 0, 0, 0]])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result,
                  [[0, 0, 0, 2], [0, 0, 0, 4], [0, 0, 0, 8], [0, 0, 0, 16]])
示例#16
0
def test_move_down_multiple_opposite():
    initial_state = Board.from_matrix([
        [ 2, 4, 8, 16 ],
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ] ])

    result = initial_state.move(Action.move_down).to_matrix()
    assert_equals(result, [
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ],
        [ 2, 4, 8, 16 ] ])
示例#17
0
def test_move_up_last_row():
    initial_state = Board.from_matrix([
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ],
        [ 2, 4, 8, 16 ] ])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result, [
        [ 2, 4, 8, 16 ],
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0,  0 ] ])
示例#18
0
def test_move_right_multiple_columns():
    initial_state = Board.from_matrix([
        [ 0, 0, 0, 0 ],
        [ 0, 0, 8, 8 ],
        [ 0, 0, 0, 2 ],
        [ 0, 0, 0, 4 ] ])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result, [
        [ 0, 0, 0,  0 ],
        [ 0, 0, 0, 16 ],
        [ 0, 0, 0,  2 ],
        [ 0, 0, 0,  4 ] ])
示例#19
0
def test_move_right_double_different_equal():
    initial_state = Board.from_matrix([
        [ 4, 4, 2, 2 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result, [
        [ 0, 0, 8, 4 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])
示例#20
0
def test_move_right_middle_equal():
    initial_state = Board.from_matrix([
        [ 0, 2, 2, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result, [
        [ 0, 0, 0, 4 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])
示例#21
0
def test_move_right_first_equal_with_follower():
    initial_state = Board.from_matrix([
        [ 0, 2, 2, 2 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result, [
        [ 0, 0, 2, 4 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])
示例#22
0
def test_move_left_first_equal():
    initial_state = Board.from_matrix([
        [ 2, 2, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_left).to_matrix()
    assert_equals(result, [
        [ 4, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])
示例#23
0
def test_move_left_multiple_columns():
    initial_state = Board.from_matrix([
        [ 0, 0, 0, 0 ],
        [ 8, 8, 0, 0 ],
        [ 2, 0, 0, 0 ],
        [ 4, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_left).to_matrix()
    assert_equals(result, [
        [  0, 0, 0, 0 ],
        [ 16, 0, 0, 0 ],
        [  2, 0, 0, 0 ],
        [  4, 0, 0, 0 ] ])
示例#24
0
def test_move_right_multiple_opposite():
    initial_state = Board.from_matrix([
        [  2, 0, 0, 0 ],
        [  4, 0, 0, 0 ],
        [  8, 0, 0, 0 ],
        [ 16, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_right).to_matrix()
    assert_equals(result, [
        [ 0, 0, 0,  2 ],
        [ 0, 0, 0,  4 ],
        [ 0, 0, 0,  8 ],
        [ 0, 0, 0, 16 ] ])
示例#25
0
def test_move_left_last_column():
    initial_state = Board.from_matrix([
        [ 0, 0, 0,  2 ],
        [ 0, 0, 0,  4 ],
        [ 0, 0, 0,  8 ],
        [ 0, 0, 0, 16 ] ])

    result = initial_state.move(Action.move_left).to_matrix()
    assert_equals(result, [
        [  2, 0, 0, 0 ],
        [  4, 0, 0, 0 ],
        [  8, 0, 0, 0 ],
        [ 16, 0, 0, 0 ] ])
示例#26
0
def test_move_up_first_equal_with_follower():
    initial_state = Board.from_matrix([
        [ 2, 0, 0, 0 ],
        [ 2, 0, 0, 0 ],
        [ 2, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result, [
        [ 4, 0, 0, 0 ],
        [ 2, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])
示例#27
0
def test_move_down_empty():
    initial_state = Board.from_matrix([
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_down).to_matrix()
    assert_equals(result, [
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])
示例#28
0
def test_move_up_double_equal():
    initial_state = Board.from_matrix([
        [ 2, 0, 0, 0 ],
        [ 2, 0, 0, 0 ],
        [ 2, 0, 0, 0 ],
        [ 2, 0, 0, 0 ] ])

    result = initial_state.move(Action.move_up).to_matrix()
    assert_equals(result, [
        [ 4, 0, 0, 0 ],
        [ 4, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ] ])
示例#29
0
def test_move_down_multiple_columns():
    initial_state = Board.from_matrix([
        [ 0, 0, 0, 0 ],
        [ 0, 0, 0, 0 ],
        [ 0, 8, 0, 0 ],
        [ 0, 8, 2, 4 ] ])

    result = initial_state.move(Action.move_down).to_matrix()
    assert_equals(result, [
        [ 0,  0, 0, 0 ],
        [ 0,  0, 0, 0 ],
        [ 0,  0, 0, 0 ],
        [ 0, 16, 2, 4 ] ])
示例#30
0
def test_value_conversions():
    for exponent in range(1, 16):
        value = 2**exponent
        converted = Board.value_from_raw(Board.value_to_raw(value))
        assert_equals(value, converted)
示例#31
0
def test_value_conversions():
    for exponent in range(1, 16):
        value     = 2 ** exponent
        converted = Board.value_from_raw(Board.value_to_raw(value))
        assert_equals(value, converted)
示例#32
0
def test_value_zero_conversions():
    assert_equals(0, Board.value_from_raw(0))
    assert_equals(0, Board.value_to_raw(0))
示例#33
0
def test_value_zero_conversions():
    assert_equals(0, Board.value_from_raw(0))
    assert_equals(0, Board.value_to_raw(0))