Exemple #1
0
def test_sorting_list_of_carts():
    correct_order_coordinates = [(0, 0), (2, 0), (1, 1), (2, 1)]
    carts = [
        Cart(2, 1, "<"),
        Cart(1, 1, "<"),
        Cart(2, 0, "<"),
        Cart(0, 0, "<")
    ]
    carts.sort()
    for i in range(4):
        assert_equal(carts[i].get_coordinates(), correct_order_coordinates[i],
                     f"Wrong coordinates at index {i}")
Exemple #2
0
def find_and_add_carts_with_dir(line, direction, y_pos, carts):
    x_pos = line.find(direction)
    while x_pos > 0:
        carts.append(Cart(x_pos, y_pos, direction))

        # replace cart symbol with track
        if direction == "<" or direction == ">":
            repl_str = "-"
        else:
            repl_str = "|"
        line = line[:x_pos] + repl_str + line[x_pos+1:]

        # next cart
        x_pos = line.find(direction)
    return line
Exemple #3
0
def test_turn_rotate_down_backward():
    cart = Cart(0, 0, "v")
    cart.turn_rotate("\\")
    assert_equal(cart.get_direction(), ">")
Exemple #4
0
def test_turn_rotate_down_forward():
    cart = Cart(0, 0, "v")
    cart.turn_rotate("/")
    assert_equal(cart.get_direction(), "<")
Exemple #5
0
def test_move_forward_upp():
    cart = Cart(3, 3, "^")
    cart.move_forward()
    assert_equal(cart.get_coordinates(), (3, 2), "Expected cart to have moved")
Exemple #6
0
def test_move_forward_right():
    cart = Cart(3, 3, ">")
    cart.move_forward()
    assert_equal(cart.get_coordinates(), (4, 3), "Expected cart to have moved")
Exemple #7
0
def test_intersect_rotate_down():
    cart = Cart(0, 0, "v")
    cart.intersect_rotate()
    assert_equal(cart.get_direction(), ">",
                 "expected cart to have turned left")
    cart.intersect_rotate()
    assert_equal(cart.get_direction(), ">", "expected cart not to have turned")
    cart.intersect_rotate()
    assert_equal(cart.get_direction(), "v",
                 "expected cart to have turned right")
    cart.intersect_rotate()
    assert_equal(cart.get_direction(), ">",
                 "expected cart to have turned left")
Exemple #8
0
def test_turn_rotate_right_forward():
    cart = Cart(0, 0, ">")
    cart.turn_rotate("/")
    assert_equal(cart.get_direction(), "^")
Exemple #9
0
def test_turn_rotate_left_backward():
    cart = Cart(0, 0, "<")
    cart.turn_rotate("\\")
    assert_equal(cart.get_direction(), "^")