Exemple #1
0
    def __init__(self, station_id, name, color, direction_a=None, direction_b=None):
        self.name = name
        station_name = (
            self.name.lower()
            .replace("/", "_and_")
            .replace(" ", "_")
            .replace("-", "_")
            .replace("'", "")
        )

        #
        #
        # TODO: Complete the below by deciding on a topic name, number of partitions, and number of
        # replicas
        #
        #
        topic_name = f"{station_name}" # TODO: Come up with a better topic name
        super().__init__(
            topic_name,
            key_schema=Station.key_schema,
            value_schema=Station.value_schema, # TODO: Uncomment once schema is defined
            num_partitions=1,
            num_replicas=1,
        )

        self.station_id = int(station_id)
        self.color = color
        self.dir_a = direction_a
        self.dir_b = direction_b
        self.a_train = None
        self.b_train = None
        self.turnstile = Turnstile(self)
Exemple #2
0
def test_logs():
    reg = Register('Metropoliten3')
    t = Turnstile(reg, id_=1, fare=8.0)
    c3 = reg.create_card(CardType.BalanceLimit, 12)
    c4 = reg.create_card(CardType.BalanceLimit, 3)

    t(c3.id)
    t(c4.id)

    log = [ID for ID, _, _ in reg.log]
    assert c3.id in log and c4.id in log
Exemple #3
0
def turnstile_object():
    turnstile = Turnstile()
    return turnstile
Exemple #4
0
def test_pushing_locked_turnstile_remains_locked():
    turnstile = Turnstile()
    turnstile.push()
    assert turnstile.current_state() == "locked"
Exemple #5
0
def test_amount_increases_when_inserting_coin():
    turnstile = Turnstile(amount_for_passing=10)
    turnstile.insert_coin(5)
    assert turnstile.current_amount() == 5
Exemple #6
0
def test_amount_in_turnstile_is_reset_after_unlocking():
    turnstile = Turnstile(amount_for_passing=10)
    turnstile.insert_coin(15)
    assert turnstile.current_amount() == 0
Exemple #7
0
def test_push_locks_previously_unlocked_turnstile():
    turnstile = Turnstile(amount_for_passing=10)
    turnstile.change_state(Unlocked(turnstile))
    turnstile.push()
    assert turnstile.current_state() == "locked"
Exemple #8
0
def test_turnstile_is_locked_after_creation():
    turnstile = Turnstile()
    assert turnstile.current_state() == "locked"
Exemple #9
0
def test_insert_coins_keeps_unlocked_turnstile_unlocked():
    turnstile = Turnstile(amount_for_passing=10)
    turnstile.change_state(Unlocked(turnstile))
    turnstile.insert_coin(5)
    assert turnstile.current_state() == "unlocked"
Exemple #10
0
def test_insert_more_than_sufficient_coins_opens_turnstile():
    turnstile = Turnstile(amount_for_passing=10)
    turnstile.insert_coin(15)
    assert turnstile.current_state() == "unlocked"
Exemple #11
0
def test_inserting_half_the_required_amount_twice_unlocks_turnstile():
    turnstile = Turnstile(amount_for_passing=10)
    turnstile.insert_coin(5)
    assert turnstile.current_state() == "locked"
    turnstile.insert_coin(5)
    assert turnstile.current_state() == "unlocked"
Exemple #12
0
def test_insert_insufficient_coins_keeps_turnstile_locked():
    turnstile = Turnstile(amount_for_passing=10)
    turnstile.insert_coin(5)
    assert turnstile.current_state() == "locked"