コード例 #1
0
    def test_board_method_rejected(self):

        ferry = Ferry(20, 2)  # Setup

        white_car = Car(26, "white")  # Setup
        boarding_car = ferry.board(white_car)  # Execute
        self.assertEqual(boarding_car, "rejected")  # Testing status
コード例 #2
0
    def test_travel(self):
        data = """F10
N3
F7
R90
F11"""
        instructions = data.splitlines()
        ferry = Ferry(instructions)
        distance = ferry.travel()
        self.assertEqual(25, distance)
コード例 #3
0
    def test_board_method_accepted(self):

        ferry = Ferry(20, 2)  # Setup

        blue_car = Car(2, "blue")  # Setup
        boarding_car = ferry.board(blue_car)  # Execute
        self.assertEqual(boarding_car, "accepted")  # Testing status

        brown_car = Car(12, "brown")  # Setup
        boarding_car = ferry.board(brown_car)  # Execute
        self.assertEqual(boarding_car, "accepted")  # Testing status
コード例 #4
0
    def test_move(self):
        data = """F10
N3
F7
R90
F11"""
        instructions = data.splitlines()
        ferry = Ferry(instructions)
        (pos, facing) = ferry.move()
        self.assertEqual((10, 0), pos)
        self.assertEqual(Dir.E, facing)
        (pos, facing) = ferry.move()
        self.assertEqual((10, -3), pos)
        self.assertEqual(Dir.E, facing)
コード例 #5
0
    def test_board_method_car_count(self):

        ferry = Ferry(20, 2)  # Setup

        yellow_car = Car(6, "white")  # Setup
        ferry.board(yellow_car)  # Execute
        self.assertEqual(ferry.car_count, 1)  # Testing boarding cars

        red_car = Car(6, "red")
        ferry.board(red_car)
        self.assertEqual(ferry.car_count, 2)  # Testing boarding cars

        red_car = Car(6, "red")  # Setup
        ferry.board(red_car)  # Execute
        self.assertEqual(ferry.car_count, 3)  # Testing boarding cars
コード例 #6
0
class TestFerryTerminal(unittest.TestCase):
    vehicle1 = Vehicle()
    ferry1 = Ferry()
    car1 = Car()
    van1 = Van()
    bus1 = Bus()
    truck1 = Truck()

    #test functions of vehicle size
    def test_vehicle_size(self):
        self.vehicle1.set_size('small')
        self.assertEqual(self.vehicle1.get_size(), 'small')

    #test functions about vehicle gas
    def test_vehicle_gas(self):
        self.vehicle1.set_current_gas(10)
        self.assertEqual(self.vehicle1.get_current_gas(), 10)
        self.vehicle1.add_gas(20)
        self.assertEqual(self.vehicle1.get_current_gas(), 30)

    #test price functions of the vehicle
    def test_vehicle_price(self):
        self.vehicle1.set_price(3)
        self.assertEqual(self.vehicle1.get_price(), 3)

    def test_max_vehicles_on_ferry(self):
        self.ferry1.set_max_vehicles(6)
        self.assertEqual(self.ferry1.get_max_vehicles(), 6)

    def test_vehicle_parking_on_ferry(self):
        self.ferry1.set_max_vehicles(2)
        self.assertEqual(self.ferry1.get_max_vehicles(), 2)
        self.assertTrue(self.ferry1.space_available())
        self.ferry1.park_vehicle()
        self.assertTrue(self.ferry1.space_available())
        self.ferry1.park_vehicle()
        self.assertFalse(self.ferry1.space_available())

    def test_car_price(self):
        self.assertEqual(self.car1.get_price(), 3)

    def test_van_price(self):
        self.assertEqual(self.van1.get_price(), 4)

    def test_bus_price(self):
        self.assertEqual(self.bus1.get_price(), 5)

    def test_truck_price(self):
        self.assertEqual(self.truck1.get_price(), 6)
コード例 #7
0
    def test_board_people_count(self):

        ferry = Ferry(20, 2)  # Setup

        white_car = Car(6, "white")  # Setup
        ferry.board(white_car)  # Execute
        self.assertEqual(ferry.people_count, 6)  # Testing boarding passengers

        red_car = Car(6, "red")  # Setup
        ferry.board(red_car)  # Execute
        self.assertEqual(ferry.people_count, 12)  # Testing boarding passengers
コード例 #8
0
from ferry import Ferry, Ferry2

if __name__ == "__main__":
    with open("11/input.txt", "r") as file:
        seat_layout = file.read().splitlines()

    ferry = Ferry(seat_layout)
    ferry.simulate_seating()
    occupied_count = ferry.count_occupied_seats()
    print("Part 1:", occupied_count)

    ferry2 = Ferry2(seat_layout)
    ferry2.simulate_seating(occupied_seat_limit=5)
    occupied_count = ferry2.count_occupied_seats()
    print("Part 2:", occupied_count)
コード例 #9
0
from ferry import Ferry

input = [line.strip() for line in open("input.txt").readlines()]

data = []

for line in input:
    l = []
    for c in line:
        l.append(c)
    data.append(l)

ferry = Ferry(data)

while not ferry.execute_round():
    pass

print(ferry.count_all_occupied_seats())