<commit_before>import sys
import unittest

import pytest

from core.simulation.bus import Bus
from core.simulation.line import Line, LineStop
from utils.helpers import get_full_class_name

if sys.version_info[0] >= 3:
    import unittest.mock as mock
    from unittest.mock import PropertyMock
else:
    import mock
    from mock import PropertyMock


class BusTests(unittest.TestCase):
    line_name = get_full_class_name(Line)

    @staticmethod
    def get_empty_line():
        return Line({'id': 0, 'bus_capacity': 0, "frequency1": 0, "frequency2": 0}, [], [])

    def test_create(self):
        with mock.patch(BusTests.line_name + ".routes", new_callable=PropertyMock) as mocked_routes:
            mocked_routes.return_value = [[LineStop('A', 0), LineStop('', 0)], [LineStop('B', 0), LineStop('', 0)]]
            line = BusTests.get_empty_line()
            bus = Bus(line, 0)
            bus2 = Bus(line, 1)
            assert bus.passengers == []
            assert bus.line == line
            assert bus.time_to_next_stop == 0
            assert bus.current_stop_name == 'A'
            assert bus.current_stop == 0
            assert bus2.passengers == []
            assert bus2.line == line
            assert bus2.time_to_next_stop == 0
            assert bus2.current_stop_name == 'B'
            assert bus2.current_stop == 0


counts = [[i] * (2 * i - 1) for i in range(2, 7)]
q = []
for c in counts:
    q.append(list(zip([i for i in range(1, len(c) - 1)], c)))
q = [item for sublist in q for item in sublist]


@pytest.mark.parametrize(("steps", "stops"), q)
def test_move(steps, stops):
    with mock.patch(BusTests.line_name + ".routes", new_callable=PropertyMock) as mocked_routes:

        lines_left = [LineStop('l' + str(i), 2) for i in range(stops)]
        lines_left = [LineStop('P', 1)] + lines_left

        lines_right = [LineStop('r' + str(i), 2) for i in range(stops)]
        lines_right = [LineStop('P', 1)] + lines_right
        mocked_routes.return_value = [
            lines_left,
            lines_right
        ]
        line = BusTests.get_empty_line()

        bus = Bus(line, 0)
        bus2 = Bus(line, 1)
        bus.move()
        bus2.move()

        stop = 0
        for i in range(steps):
            bus.move()
            bus2.move()
            if 2 - (i % 3) == 0:
                stop += 1
            assert bus.time_to_next_stop == 2 - (i % 3), "i = {}".format(i)
            assert bus.current_stop_name == 'l' + str(stop)
            assert bus.current_stop == (i // 3) + 1, "i = {}".format(i)

            assert bus2.time_to_next_stop == 2 - (i % 3), "i = {}".format(i)
            assert bus2.current_stop_name == 'r' + str(stop)
            assert bus2.current_stop == (i // 3) + 1, "i = {}".format(i)
        if stops * 2 <= steps:
            assert bus.next_stop_name is None
            assert bus2.next_stop_name is None
        else:
            assert bus.next_stop_name is not None
            assert bus2.next_stop_name is not None<commit_msg>fix bus tests<commit_after>import sys
import unittest

import pytest

from core.simulation.bus import Bus
from core.simulation.line import Line, LineStop
from utils.helpers import get_full_class_name

if sys.version_info[0] >= 3:
    import unittest.mock as mock
    from unittest.mock import PropertyMock
else:
    import mock
    from mock import PropertyMock


class BusTests(unittest.TestCase):
    line_name = get_full_class_name(Line)

    @staticmethod
    def get_empty_line():
        return Line({'id': 0, 'bus_capacity': 0, "frequency1": 0, "frequency2": 0}, [], [])

    def test_create(self):
        with mock.patch(BusTests.line_name + ".routes", new_callable=PropertyMock) as mocked_routes:
            mocked_routes.return_value = [[LineStop('A', 0), LineStop('', 0)], [LineStop('B', 0), LineStop('', 0)]]
            line = BusTests.get_empty_line()
            bus = Bus(line, 0)
            bus2 = Bus(line, 1)
            assert bus.passengers == []
            assert bus.line == line
            assert bus.time_to_next_stop == 0
            assert bus.current_stop_name == 'A'
            assert bus.current_stop == 0
            assert bus2.passengers == []
            assert bus2.line == line
            assert bus2.time_to_next_stop == 0
            assert bus2.current_stop_name == 'B'
            assert bus2.current_stop == 0


N = 7
counts = [[i] * ((2 * i) + N + 1) for i in range(2, N)]
q = []
for c in counts:
    q.append(list(zip([i for i in range(1, len(c) - 1)], c)))
q = [item for sublist in q for item in sublist]


@pytest.mark.parametrize(("steps", "stops"), q)
def test_move(steps, stops):
    with mock.patch(BusTests.line_name + ".routes", new_callable=PropertyMock) as mocked_routes:

        lines_left = [LineStop('l' + str(i), 2) for i in range(stops)]
        lines_left = [LineStop('P', 1)] + lines_left

        lines_right = [LineStop('r' + str(i), 2) for i in range(stops)]
        lines_right = [LineStop('P', 1)] + lines_right
        mocked_routes.return_value = [
            lines_left,
            lines_right
        ]
        line = BusTests.get_empty_line()

        bus = Bus(line, 0)
        bus2 = Bus(line, 1)
        bus.move()
        bus2.move()

        stop = 0
        for i in range(min(3 * stops - 4, steps)):  # 4 because of 4 = 2 ticks from end + 2 ticks from start
            bus.move()
            bus2.move()
            if 2 - (i % 3) == 0:
                stop += 1
            assert bus.time_to_next_stop == 2 - (i % 3), "i = {}".format(i)
            assert bus.current_stop_name == 'l' + str(stop)
            assert bus.current_stop == (i // 3) + 1, "i = {}".format(i)

            assert bus2.time_to_next_stop == 2 - (i % 3), "i = {}".format(i)
            assert bus2.current_stop_name == 'r' + str(stop)
            assert bus2.current_stop == (i // 3) + 1, "i = {}".format(i)

        if steps >= 3 * stops:
            for i in range(steps - 3 * stops + 1):
                bus2.move()
                bus.move()
            assert bus.next_stop_name == "None", "steps {} stops {} i {} ".format(steps, stops, i)
            assert bus2.next_stop_name == "None"
            assert bus.next_stop_name == "None"
            assert bus2.next_stop_name == "None"
        else:
            assert bus.next_stop_name != "None"
            assert bus2.next_stop_name != "None"
{'fraction_non_alphanumeric': 0.1322262259125803, 'fraction_numerical': 0.01973993420021933, 'mean_word_length': 2.1525925925925926, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4099913', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2068, 'n_words': 558}