Beispiel #1
0
def test_ship_rotation_right():
    ship = Ship(Position(0, 0))
    ship.rotate("R", 90)
    assert ship.degrees == 270
    ship.rotate("R", 90)
    assert ship.degrees == 180
    ship.rotate("R", 90)
    assert ship.degrees == 90
    ship.rotate("R", 270)
    assert ship.degrees == 180
Beispiel #2
0
def test_ship_forward():
    ship = Ship(Position(0, 0))
    ship.forward(10)
    assert ship.position == Position(10, 0)
    ship.rotate("R", 180)
    assert ship.position == Position(10, 0)
    ship.forward(10)
    assert ship.position == Position(0, 0)
    ship.forward(30)
    assert ship.position == Position(-30, 0)
Beispiel #3
0
 def test_part2(self):
     input = ["F10", "N3", "F7", "R90", "F11"]
     ship = Ship()
     ship.turnon_waypoint(10, 1)
     ship.print()
     ship.navigate(input)
     self.assertEqual(ship.x, 214)
     self.assertEqual(ship.y, -72)
     self.assertEqual(ship.compute_distance(), 286)
Beispiel #4
0
 def test_rotate_waypoint(self):
     ship = Ship(170, 38)
     ship.turnon_waypoint(10, 4)
     ship.turn_right(90)
     self.assertEqual(ship.x, 170)
     self.assertEqual(ship.y, 38)
     self.assertEqual(ship.wp_x, 4)
     self.assertEqual(ship.wp_y, -10)
     ship.go_forward(11)
     self.assertEqual(ship.x, 214)
     self.assertEqual(ship.y, -72)
     self.assertEqual(ship.compute_distance(), 286)
Beispiel #5
0
def test_navigate_part1():
    starting_position = Position(0, 0)
    ship = Ship(starting_position)
    for i in PART1_INSTR.split("\n")[:-1]:
        navigate(ship, i)
    assert ship.position == Position(17, -8)
    assert ship.position.manhattan() == 25
Beispiel #6
0
 def test_rotate_waypoint_special_cases(self):
     ship = Ship(0, 0)
     ship.turnon_waypoint(1, 0)
     ship.turn_left(90)
     self.assertEqual(ship.wp_x, 0)
     self.assertEqual(ship.wp_y, 1)
     ship.turn_left(90)
     self.assertEqual(ship.wp_x, -1)
     self.assertEqual(ship.wp_y, 0)
Beispiel #7
0
def test_navigate_part2():
    starting_position = Position(0, 0)
    waypoint = Position(10, 1)
    ship = Ship(starting_position)
    for i in PART1_INSTR.split("\n")[:-1]:
        navigate(ship, i, waypoint)
    assert ship.position == Position(214, -72)
    assert ship.position.manhattan() == 286
Beispiel #8
0
 def test_turn_right(self):
     ship = Ship(17, 3, 0)
     ship.turn_right(90)
     ship.go_forward(11)
     self.assertEqual(ship.x, 17)
     self.assertEqual(ship.y, -8)
     self.assertEqual(ship.compute_distance(), 25)
Beispiel #9
0
 def test_part1(self):
     input = ["F10", "N3", "F7", "R90", "F11"]
     ship = Ship()
     ship.print()
     ship.navigate(input)
     self.assertEqual(ship.x, 17)
     self.assertEqual(ship.y, -8)
     self.assertEqual(ship.compute_distance(), 25)
Beispiel #10
0
 def test_part2_turn_left(self):
     input = ["F10", "L180", "F10"]
     ship = Ship()
     ship.turnon_waypoint(10, 1)
     # ship.print()
     ship.navigate(input)
     self.assertEqual(ship.x, 0)
     self.assertEqual(ship.y, 0)
import pytest
from day12 import Ship

move_tests = [("N10", Ship(x=0, y=10, direction='E')),
              ("W10", Ship(x=-10, y=0, direction='E')),
              ("S10", Ship(x=0, y=-10, direction='E')),
              ("E10", Ship(x=10, y=0, direction='E')),
              ("F10", Ship(x=10, y=0, direction='E')),
              ("L90", Ship(x=0, y=0, direction='N')),
              ("L180", Ship(x=0, y=0, direction='W')),
              ("L270", Ship(x=0, y=0, direction='S')),
              ("R90", Ship(x=0, y=0, direction='S')),
              ("R180", Ship(x=0, y=0, direction='W')),
              ("R270", Ship(x=0, y=0, direction='N'))]


@pytest.fixture
def test_file_lines():
    with open("test.txt") as f:
        lines = f.read().rstrip('\n').split('\n')
        return lines


@pytest.mark.parametrize("inp,exp_ship", move_tests)
def test_move(inp, exp_ship):
    test_ship = Ship()
    test_ship.move(inp)
    assert test_ship == exp_ship


def test_trip(test_file_lines):
def test_trip(test_file_lines):
    test_ship = Ship()
    for line in test_file_lines:
        test_ship.move(line)

    assert test_ship.get_man_dist() == 25
Beispiel #13
0
def test_ship_rotation_left():
    ship = Ship(Position(0, 0))
    ship.rotate("L", 90)
    assert ship.degrees == 90
    ship.rotate("L", 90)
    assert ship.degrees == 180
    ship.rotate("L", 90)
    assert ship.degrees == 270
    ship.rotate("L", 90)
    assert ship.degrees == 0
    ship.rotate("L", 180)
    assert ship.degrees == 180
Beispiel #14
0
def test_ship_starting_coords():
    ship = Ship(Position(0, 0))
    assert ship.position == Position(0, 0)
    assert ship.degrees == 0
    def testTurnRight180Deg(self):
        the_ship = Ship()
        the_ship.perform_action(make_action("R", 180))

        self.assertEqual("W", the_ship.direction)
    def testTurnLeft270Deg(self):
        the_ship = Ship()
        the_ship.perform_action(make_action("L", 270))

        self.assertEqual("S", the_ship.direction)
    def testTurnRight90Deg(self):
        the_ship = Ship()
        the_ship.perform_action({"type": "R", "value": 90})

        self.assertEqual("S", the_ship.direction)
def test_move(inp, exp_ship):
    test_ship = Ship()
    test_ship.move(inp)
    assert test_ship == exp_ship