Example #1
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]])
Example #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]])
Example #3
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]])
Example #4
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]])
Example #5
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]])
Example #6
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]])
Example #7
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]])
Example #8
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]])
Example #9
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]])
Example #10
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]])
Example #11
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]])
Example #12
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]])
Example #13
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]])
Example #14
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]])
Example #15
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]])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])
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 ] ])