def __test_all_routes():
    repo = RouteRepository("", RouteValidator())
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    repo.add(A)
    repo.add(B)
    assert repo.all_routes() == [A, B]
示例#2
0
def __test_all_routes():
    repo = RouteRepository("", RouteValidator())
    ctrl = RouteController(repo)
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    ctrl.add(A)
    ctrl.add(B)
    assert ctrl.all_routes() == [A, B]
def __test_cost_for_route():
    repo = RouteRepository("", RouteValidator())
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    repo.add(A)
    repo.add(B)
    assert repo.cost_for_route(2) == 10 / 60.0
    assert repo.cost_for_route(5) == (10 * 60 + 10) / 60.0
示例#4
0
def __test_cost_for_route():
    repo = RouteRepository("", RouteValidator())
    ctrl = RouteController(repo)
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    ctrl.add(A)
    ctrl.add(B)
    assert ctrl.cost_for_route(2) == 10 / 60.0
    assert ctrl.cost_for_route(5) == (10 * 60 + 10) / 60.0
def __test_find():
    repo = RouteRepository("", RouteValidator())
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    repo.add(A)
    repo.add(B)
    assert repo.find(2)
    assert repo.find(5)
    assert not repo.find(1)
示例#6
0
def __test_find():
    repo = RouteRepository("", RouteValidator())
    ctrl = RouteController(repo)
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    ctrl.add(A)
    ctrl.add(B)
    assert ctrl.find(2)
    assert ctrl.find(5)
    assert not ctrl.find(1)
def __test_sell_ticket():
    repo = RouteRepository("", RouteValidator())
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    repo.add(A)
    repo.add(B)
    repo.sell_ticket(2)
    repo.sell_ticket(2)
    repo.sell_ticket(5)
    assert A.tickets == 98
    assert B.tickets == 99
示例#8
0
def __test_check():
    V = RouteValidator()
    R = Route(3, 4, 4, 4, 4, 4)
    assert not V.check(R)
    R = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    assert V.check(R)
    R = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    assert V.check(R)
    R = Route(5, "BananaLand", "25:10", "AppleLand", "20:20", 100)
    assert not V.check(R)
    R = Route(5, "BananaLand", "20:10", "AppleLand", "20:00", 100)
    assert not V.check(R)
def __test_add():
    repo = RouteRepository("", RouteValidator())
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    C = Route(5, "BananaLand", "15:10", "AppleLand", "20:20", 100)
    repo.add(A)
    assert A in repo
    repo.add(B)
    assert B in repo

    try:
        repo.add(C)
        assert False
    except TrainException:
        assert True
示例#10
0
def __test_add():
    repo = RouteRepository("", RouteValidator())
    ctrl = RouteController(repo)
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    C = Route(5, "BananaLand", "15:10", "AppleLand", "20:20", 100)
    ctrl.add(A)
    assert A in ctrl.all_routes()
    ctrl.add(B)
    assert B in repo.all_routes()

    try:
        repo.add(C)
        assert False
    except TrainException:
        assert True
    def run_add(self):
        id = input("Type route's unique ID: ")
        departure_city = input("Type departure city: ")
        departure_time = input("Type departure time: ")
        arrival_city = input("Type arrival city: ")
        arrival_time = input("Type arrival time: ")
        tickets = input("Type available number of tickets: ")

        try:
            id = int(id)
            tickets = int(tickets)
            if tickets < 1:
                raise ValueError()
        except ValueError:
            print("ID and number of tickets must be positive integers.\n")
            return

        try:

            self.__ctrl.add(
                Route(id, departure_city, departure_time, arrival_city,
                      arrival_time, tickets))
            print("Route was successfully added.\n")
        except TrainException as err:
            print(str(err) + "\n")
示例#12
0
def __test_sell_ticket_and_cart():
    repo = RouteRepository("", RouteValidator())
    ctrl = RouteController(repo)
    A = Route(2, "BananaLand", "10:10", "AppleLand", "10:20", 100)
    B = Route(5, "BananaLand", "10:10", "AppleLand", "20:20", 100)
    ctrl.add(A)
    ctrl.add(B)
    ctrl.sell_ticket(2)
    ctrl.sell_ticket(2)
    ctrl.sell_ticket(5)
    assert A.tickets == 98
    assert B.tickets == 99
    assert ctrl.total_income() == round(
        2 * (10 / 60.0) + 1 * ((10 * 60 + 10) / 60.0), 2)
    assert ctrl.ordered_by_sells() == [A, B]
    ctrl.sell_ticket(5)
    ctrl.sell_ticket(5)
    assert A.tickets == 98
    assert B.tickets == 97
    assert ctrl.total_income() == round(
        2 * (10 / 60.0) + 3 * ((10 * 60 + 10) / 60.0), 2)
    assert ctrl.ordered_by_sells() == [B, A]
    def __load(self):
        '''
        Loads from the file the data.
        :return: data is loaded; it does nothing if file doesn't exist;
                 if file does not open, hourly_date is automatically set to 1.00
        '''

        try:
            file = open(self.__filename, "r")
        except IOError:
            self.__hourly_rate = 1.00
            return

        lines = file.read().strip().split("\n")
        line = lines[0].strip()
        self.__hourly_rate = float(line)

        for line in lines[1:]:
            line = line.strip()
            tokens = line.split(";")

            try:
                if len(tokens) != 6:
                    raise ValueError()

                id = int(tokens[0].strip())
                departure_city = tokens[1].strip()
                departure_time = tokens[2].strip()
                arrival_city = tokens[3].strip()
                arrival_time = tokens[4].strip()
                tickets = int(tokens[5].strip())

                self.__data.append(
                    Route(id, departure_city, departure_time, arrival_city,
                          arrival_time, tickets))
            except (ValueError, IndexError):
                continue