def test_factory_from_days_string():
    assert dtrp0.days == [
        DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY
    ]
    assert dtrp0.time_range == TimeRange(start=time(hour=7, minute=10),
                                         end=time(hour=8))

    assert dtrp1.days == [DayOfWeek.TUESDAY, DayOfWeek.THURSDAY]
    assert dtrp1.time_range == TimeRange(start=time(hour=11, minute=15),
                                         end=time(hour=12, minute=30))

    assert dtrp2.days == [DayOfWeek.SATURDAY]
    assert dtrp2.time_range == TimeRange(start=time(hour=9),
                                         end=time(hour=11, minute=30))
def test_book_and_total_minutes_booked():
    dts = DayTimeSlots()

    assert dts.total_minutes_booked() == 0

    dtrp0 = DaysTimeRangePair.factory_from_days_string(
        "MWF",
        TimeRange(start=time(hour=8, minute=50), end=time(hour=10, minute=5)))
    dts.book(dtrp0)
    assert dts.total_minutes_booked() == 225

    dtrp1 = DaysTimeRangePair.factory_from_days_string(
        "TR",
        TimeRange(start=time(hour=11, minute=30), end=time(hour=12,
                                                           minute=20)))
    dts.book(dtrp1)
    assert dts.total_minutes_booked() == 325

    dtrp2 = DaysTimeRangePair.factory_from_days_string(
        "F", TimeRange.normalize(15, 0, 2, 30))
    dts.book(dtrp2)
    assert dts.total_minutes_booked() == 475
def test_clashes_with():
    dts = DayTimeSlots()

    dtrp0 = DaysTimeRangePair.factory_from_days_string(
        "MWF",
        TimeRange(start=time(hour=8, minute=50), end=time(hour=10, minute=5)))
    dtrp1 = DaysTimeRangePair.factory_from_days_string(
        "TR",
        TimeRange(start=time(hour=11, minute=30), end=time(hour=12,
                                                           minute=20)))
    dtrp2 = DaysTimeRangePair.factory_from_days_string(
        "F", TimeRange.normalize(15, 0, 2, 30))

    dtrp_clashes0 = DaysTimeRangePair.factory_from_days_string(
        "MWF",
        TimeRange(start=time(hour=8, minute=50), end=time(hour=10, minute=5)))
    dtrp_clashes1 = DaysTimeRangePair.factory_from_days_string(
        "TWR", TimeRange(start=time(hour=12), end=time(hour=12, minute=50)))
    dtrp_clashes2 = DaysTimeRangePair.factory_from_days_string(
        "F", TimeRange(start=time(hour=15, minute=10), end=time(hour=16)))

    dtrp_no_clash0 = DaysTimeRangePair.factory_from_days_string(
        "TR", TimeRange(start=time(hour=13), end=time(hour=14, minute=15)))
    dtrp_no_clash1 = DaysTimeRangePair.factory_from_days_string(
        "MTWRF", TimeRange(start=time(hour=7), end=time(hour=7, minute=50)))
    dtrp_no_clash2 = DaysTimeRangePair.factory_from_days_string(
        "MF",
        TimeRange(start=time(hour=11, minute=30), end=time(hour=13,
                                                           minute=30)))

    dts.book(dtrp0)
    dts.book(dtrp1)
    dts.book(dtrp2)

    assert dts.clashes_with(dtrp_clashes0.days, dtrp_clashes0.time_range)
    assert dts.clashes_with(dtrp_clashes1.days, dtrp_clashes1.time_range)
    assert dts.clashes_with(dtrp_clashes2.days, dtrp_clashes2.time_range)

    assert not dts.clashes_with(dtrp_no_clash0.days, dtrp_no_clash0.time_range)
    assert not dts.clashes_with(dtrp_no_clash1.days, dtrp_no_clash1.time_range)
    assert not dts.clashes_with(dtrp_no_clash2.days, dtrp_no_clash2.time_range)
Пример #4
0
def test_normalize():
    tr0 = TimeRange(start=time(hour=8), end=time(hour=9, minute=15))
    tr1 = TimeRange.normalize(8, 0, 1, 15)
    tr2 = TimeRange.normalize(8, 0, 0, 75)

    tr3 = TimeRange(start=time(hour=11, minute=30),
                    end=time(hour=14, minute=15))
    tr4 = TimeRange.normalize(11, 30, 2, 45)
    tr5 = TimeRange.normalize(11, 30, 1, 105)
    tr6 = TimeRange.normalize(11, 30, 0, 165)

    assert tr0 == tr1
    assert tr0 == tr2

    assert tr3 == tr4
    assert tr3 == tr5
    assert tr3 == tr6
Пример #5
0
def test_as_dummy_datetimes():
    tr0 = TimeRange(start=time(hour=8), end=time(hour=9, minute=15))
    tr1 = TimeRange(start=time(hour=11, minute=15),
                    end=time(hour=13, minute=45))

    dummy0 = tr0.as_dummy_datetimes()
    dummy1 = tr1.as_dummy_datetimes()

    assert dummy0[0].date() == dummy0[1].date()
    assert dummy1[0].date() == dummy1[1].date()
    assert dummy0[0].date() == dummy1[0].date()
    assert dummy0[0].time() == tr0[0]
    assert dummy0[1].time() == tr0[1]
    assert dummy1[0].time() == tr1[0]
    assert dummy1[1].time() == tr1[1]
Пример #6
0
def test_time_ranges_overlapping_with():
    b0 = copy(booking0)
    b0.finalize()

    b1 = copy(booking1)
    b1.finalize()

    b2 = copy(booking2)
    b2.finalize()

    b3 = copy(booking3)
    b3.finalize()

    b4 = copy(booking4)
    b4.finalize()

    days = DayOfWeek.list_from_string("MWF")
    time_range = TimeRange.normalize(7, 0, 0, 50)
    expected_blocks = []
    assert b0.time_ranges_overlapping_with(days, time_range) == expected_blocks

    days = DayOfWeek.list_from_string("TR")
    time_range = TimeRange.normalize(6, 0, 0, 50)
    assert b0.time_ranges_overlapping_with(days, time_range) == expected_blocks

    time_range = TimeRange.normalize(6, 0, 0, 150)
    expected_blocks = [TimeRange.normalize(7, 0, 0, 100)]
    assert b0.time_ranges_overlapping_with(days, time_range) == expected_blocks

    time_range = TimeRange.normalize(8, 40, 0, 75)
    assert b0.time_ranges_overlapping_with(days, time_range) == expected_blocks

    time_range = TimeRange.normalize(8, 50, 0, 75)
    expected_blocks = []
    assert b0.time_ranges_overlapping_with(days, time_range) == expected_blocks
    assert b1.time_ranges_overlapping_with(days, time_range) == expected_blocks
    assert b4.time_ranges_overlapping_with(days, time_range) == expected_blocks

    days = DayOfWeek.list_from_string("MWF")
    time_range = TimeRange.normalize(7, 0, 0, 50)
    assert b2.time_ranges_overlapping_with(days, time_range) == expected_blocks

    time_range = TimeRange.normalize(8, 0, 0, 50)
    expected_blocks = [TimeRange.normalize(8, 10, 0, 50)]
    assert b2.time_ranges_overlapping_with(days, time_range) == expected_blocks

    days = DayOfWeek.list_from_string("TR")
    time_range = TimeRange(start=time(hour=7), end=time(hour=16))
    expected_blocks = [TimeRange.normalize(7, 0, 0, 100)]
    assert b0.time_ranges_overlapping_with(days, time_range) == expected_blocks

    expected_blocks = [TimeRange.normalize(11, 0, 0, 100)]
    assert b1.time_ranges_overlapping_with(days, time_range) == expected_blocks

    expected_blocks = [TimeRange.normalize(13, 45, 0, 75)]
    assert b4.time_ranges_overlapping_with(days, time_range) == expected_blocks

    expected_blocks = [
        TimeRange.normalize(7, 0, 1, 15),
        TimeRange.normalize(11, 0, 1, 15)
    ]
    assert b3.time_ranges_overlapping_with(days, time_range) == expected_blocks

    days = DayOfWeek.list_from_string("T")
    expected_blocks = [TimeRange.normalize(7, 0, 1, 15)]
    assert b3.time_ranges_overlapping_with(days, time_range) == expected_blocks

    days = DayOfWeek.list_from_string("R")
    expected_blocks = [TimeRange.normalize(11, 0, 1, 15)]
    assert b3.time_ranges_overlapping_with(days, time_range) == expected_blocks
Пример #7
0
	{
		"room_code": "MB110",
		"room_type": "cr"
	}
'''))
classroom2 = Classroom(
    json_loads('''
	{
		"room_code": "MB120",
		"room_type": "cr"
	}
'''))

booking0 = Booking(copy(course0), professor0,
                   (DayOfWeek.list_from_string("TR"),
                    TimeRange.normalize(7, 0, 0, 100), classroom0))
booking1 = Booking(copy(course0), professor0,
                   (DayOfWeek.list_from_string("TR"),
                    TimeRange.normalize(11, 0, 0, 100), classroom0))
booking2 = Booking(copy(course1), professor1,
                   (DayOfWeek.list_from_string("MWF"),
                    TimeRange.normalize(8, 10, 0, 50), classroom0))
booking3 = Booking(copy(course1), professor1,
                   (DayOfWeek.list_from_string("T"),
                    TimeRange.normalize(7, 0, 1, 15), classroom1),
                   (DayOfWeek.list_from_string("R"),
                    TimeRange.normalize(11, 0, 1, 15), classroom1))
booking4 = Booking(copy(course1), professor0,
                   (DayOfWeek.list_from_string("TR"),
                    TimeRange.normalize(13, 45, 0, 75), classroom2))
booking5 = Booking(copy(course2), professor1,
def test_get_first_available():
    course0 = Course(
        json_loads('''
		{
			"name": "Math Lab",
			"course_code": "MA-100",
			"credit_count": 1,
			"standard_minutes_per_week": 50,
			"section_count": 1,
			"room_type": "cr",
			"lab": null
		}
	'''))

    course1 = Course(
        json_loads('''
		{
			"name": "Research Methods",
			"course_code": "IN-200",
			"credit_count": 3,
			"standard_minutes_per_week": 150,
			"section_count": 2,
			"room_type": "cr",
			"lab": null
		}
	'''))

    course2 = Course(
        json_loads('''
		{
			"name": "College Algebra",
			"course_code": "MA-101",
			"credit_count": 3,
			"standard_minutes_per_week": 150,
			"section_count": 3,
			"room_type": "cr",
			"lab": null
		}
	'''))

    course3 = Course(
        json_loads('''
		{
			"name": "Calculus 1",
			"course_code": "MA-104",
			"credit_count": 4,
			"standard_minutes_per_week": 200,
			"section_count": 2,
			"room_type": "cr",
			"lab": null
		}
	'''))

    professor = Professor(
        json_loads('''
		{
			"first_name": "Joanne",
			"middle_name": "Q.",
			"last_name": "Smith",
			"departments": ["MA", "IN"]
		}
	'''))

    classroom = Classroom(
        json_loads('''
		{
			"room_code": "MB100",
			"room_type": "cr"
		}
	'''))

    bookings = []
    no_restrictions = []

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=7),
                                         end=time(hour=7, minute=50))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=7),
                                         end=time(hour=8, minute=15))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=7),
                                         end=time(hour=7, minute=50))

    bookings.append(
        Booking(course0, professor,
                (DayOfWeek.list_from_string("M"),
                 TimeRange.normalize(7, 0, 0, 50), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=8),
                                         end=time(hour=8, minute=50))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=7),
                                         end=time(hour=8, minute=15))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=8),
                                         end=time(hour=8, minute=50))

    bookings.append(
        Booking(course1, professor,
                (DayOfWeek.list_from_string("F"),
                 TimeRange.normalize(8, 0, 2, 30), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=8),
                                         end=time(hour=8, minute=50))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=7),
                                         end=time(hour=8, minute=15))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=10, minute=40),
                                         end=time(hour=11, minute=30))

    bookings.append(
        Booking(course1, professor,
                (DayOfWeek.list_from_string("T"),
                 TimeRange.normalize(7, 0, 2, 30), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=8),
                                         end=time(hour=8, minute=50))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=9, minute=40),
                                         end=time(hour=10, minute=55))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=10, minute=40),
                                         end=time(hour=11, minute=30))

    bookings.append(
        Booking(course3, professor,
                (DayOfWeek.list_from_string("M"),
                 TimeRange.normalize(8, 0, 0, 150), classroom),
                (DayOfWeek.list_from_string("F"),
                 TimeRange.normalize(10, 40, 0, 50), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=10, minute=40),
                                         end=time(hour=11, minute=30))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=9, minute=40),
                                         end=time(hour=10, minute=55))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=11, minute=40),
                                         end=time(hour=12, minute=30))

    bookings.append(
        Booking(course3, professor,
                (DayOfWeek.list_from_string("TR"),
                 TimeRange.normalize(9, 40, 1, 40), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=10, minute=40),
                                         end=time(hour=11, minute=30))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=11, minute=30),
                                         end=time(hour=12, minute=45))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=11, minute=40),
                                         end=time(hour=12, minute=30))

    bookings.append(
        Booking(course2, professor,
                (DayOfWeek.list_from_string("MWF"),
                 TimeRange.normalize(11, 40, 0, 50), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=10, minute=40),
                                         end=time(hour=11, minute=30))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=11, minute=30),
                                         end=time(hour=12, minute=45))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=12, minute=40),
                                         end=time(hour=13, minute=30))

    bookings.append(
        Booking(course2, professor,
                (DayOfWeek.list_from_string("M"),
                 TimeRange.normalize(10, 40, 0, 50), classroom),
                (DayOfWeek.list_from_string("TR"),
                 TimeRange.normalize(11, 30, 0, 50), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=12, minute=40),
                                         end=time(hour=13, minute=30))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=12, minute=30),
                                         end=time(hour=13, minute=45))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=12, minute=40),
                                         end=time(hour=13, minute=30))

    bookings.append(
        Booking(course2, professor,
                (DayOfWeek.list_from_string("MWF"),
                 TimeRange.normalize(12, 40, 0, 50), classroom)).finalize())

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        50, bookings, no_restrictions, preferred_days_per_week=1)
    assert found_days == DayOfWeek.list_from_string("M")
    assert found_time_range == TimeRange(start=time(hour=13, minute=40),
                                         end=time(hour=14, minute=30))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=2)
    assert found_days == DayOfWeek.list_from_string("TR")
    assert found_time_range == TimeRange(start=time(hour=12, minute=30),
                                         end=time(hour=13, minute=45))

    found_days, found_time_range, _ = classroom.slots.get_first_available(
        150, bookings, no_restrictions, preferred_days_per_week=3)
    assert found_days == DayOfWeek.list_from_string("MWF")
    assert found_time_range == TimeRange(start=time(hour=13, minute=40),
                                         end=time(hour=14, minute=30))
Пример #9
0
    def get_first_available(self,
                            mins_per_week,
                            professor_bookings,
                            restricted_tuples,
                            attempt_even_distribution=False,
                            preferred_days_per_week=None):
        if not preferred_days_per_week:
            preferred_days_per_week = 3

        days_per_week = None

        if mins_per_week < preferred_days_per_week * 50:
            days_per_week = 1
        elif mins_per_week % preferred_days_per_week == 0:
            days_per_week = preferred_days_per_week
        elif mins_per_week % 2 == 0:
            days_per_week = 2
        else:
            days_per_week = 3

        desired_days_list = DayOfWeek.optimal_lists_for(days_per_week)
        if attempt_even_distribution and (len(desired_days_list) >
                                          1) and (getrandbits(1) == 1):
            temp_day = desired_days_list[0]
            desired_days_list[0] = desired_days_list[1]
            desired_days_list[1] = temp_day

        found_days = None
        found_time_range = None
        penalty = 0

        for desired_days in desired_days_list:
            days_per_week = len(desired_days)
            mins_per_day = floor(mins_per_week / days_per_week)
            desired_time_range = TimeRange.from_time_and_duration(
                allowable_start_time_of(desired_days), mins_per_day)

            existing_clashes = self.get_all_clashes_for(
                desired_days, desired_time_range, professor_bookings,
                restricted_tuples)
            while len(existing_clashes) > 0:
                latest_end = max(time_range.end
                                 for time_range in existing_clashes)
                earliest_start = TimeRange.time_translated_by(
                    latest_end, 0, MIN_MINS_BETWEEN_CLASSES)

                desired_time_range = TimeRange.from_time_and_duration(
                    earliest_start, mins_per_day)
                if desired_time_range.overlaps_with(LUNCH_PERIOD,
                                                    include_buffer=False):
                    desired_time_range = TimeRange.from_time_and_duration(
                        LUNCH_PERIOD.end, mins_per_day)
                if desired_time_range.start > LATEST_START_TIME:
                    break

                existing_clashes = self.get_all_clashes_for(
                    desired_days, desired_time_range, professor_bookings,
                    restricted_tuples)

                penalty = sum(
                    time_range.minutes_between(desired_time_range)
                    for time_range in existing_clashes) / days_per_week

            if len(existing_clashes) == 0:
                found_days = desired_days
                found_time_range = desired_time_range
                break

        if (found_days is not None) and (found_time_range is not None):
            return (found_days, found_time_range, penalty)
        else:
            return None
Пример #10
0
from src.day_of_week import DayOfWeek
from src.time_range import TimeRange
from src.constants import MIN_MINS_BETWEEN_CLASSES

EARLIEST_START_TIMES = {
    DayOfWeek.SUNDAY: time(hour=7),
    DayOfWeek.MONDAY: time(hour=7),
    DayOfWeek.TUESDAY: time(hour=8, minute=25),
    DayOfWeek.WEDNESDAY: time(hour=7),
    DayOfWeek.THURSDAY: time(hour=8, minute=25),
    DayOfWeek.FRIDAY: time(hour=7),
    DayOfWeek.SATURDAY: time(hour=7)
}
LATEST_START_TIME = time(hour=13, minute=25)
LUNCH_PERIOD = TimeRange(start=time(hour=11, minute=5), end=time(hour=12))


def allowable_start_time_of(days_of_week):
    earliest_start_time = EARLIEST_START_TIMES[days_of_week[0]]
    for i in range(1, len(days_of_week)):
        t = EARLIEST_START_TIMES[days_of_week[i]]
        if t > earliest_start_time:
            t = earliest_start_time
    return earliest_start_time


class DayTimeSlots():
    def __init__(self):
        self.schedule = DayOfWeek.get_empty_dict(list)
from datetime import time

from src.day_of_week import DayOfWeek
from src.time_range import TimeRange
from src.days_time_range_pair import DaysTimeRangePair

dtrp0 = DaysTimeRangePair.factory_from_days_string(
    "MWF", TimeRange(start=time(hour=7, minute=10), end=time(hour=8)))
dtrp1 = DaysTimeRangePair.factory_from_days_string(
    "TR",
    TimeRange(start=time(hour=11, minute=15), end=time(hour=12, minute=30)))
dtrp2 = DaysTimeRangePair.factory_from_days_string(
    "S", TimeRange.normalize(9, 0, 2, 30))

d0 = [DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY]
d1 = [DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY]
d2 = [DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY]
d3 = [DayOfWeek.SATURDAY, DayOfWeek.SUNDAY]
d4 = d3

tr0 = TimeRange.normalize(7, 30, 0, 70)
tr1 = TimeRange.normalize(12, 0, 0, 75)
tr2 = TimeRange(start=time(hour=7, minute=30), end=time(hour=12))
tr3 = TimeRange(start=time(hour=9), end=time(hour=9, minute=50))
tr4 = TimeRange(start=time(hour=12), end=time(hour=13, minute=15))


def test_factory_from_days_string():
    assert dtrp0.days == [
        DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY
    ]
Пример #12
0
def test_overlaps_with():
    tr0 = TimeRange(start=time(hour=8), end=time(hour=9, minute=15))

    tr1_start_minute = tr0.end.minute + MIN_MINS_BETWEEN_CLASSES
    tr1 = TimeRange(start=time(hour=9, minute=tr1_start_minute),
                    end=time(hour=10, minute=tr1_start_minute + 15))

    tr2_start_minute = tr1_start_minute + 5
    tr2 = TimeRange(start=time(hour=9, minute=tr2_start_minute),
                    end=time(hour=10, minute=tr2_start_minute + 15))

    tr3 = TimeRange(start=time(hour=9, minute=15),
                    end=time(hour=10, minute=30))

    tr4 = TimeRange(start=time(hour=9), end=time(hour=9, minute=50))

    tr5 = TimeRange(start=time(hour=8), end=time(hour=8, minute=50))

    tr6 = TimeRange(start=time(hour=8, minute=10), end=time(hour=9))

    tr7 = TimeRange(start=time(hour=7, minute=30), end=time(hour=9, minute=30))

    assert not tr0.overlaps_with(tr1)
    assert not tr0.overlaps_with(tr2)
    assert tr0.overlaps_with(tr3)
    assert not tr0.overlaps_with(tr3, include_buffer=False)
    assert tr0.overlaps_with(tr4)
    assert tr0.overlaps_with(tr5)
    assert tr0.overlaps_with(tr6)
    assert tr0.overlaps_with(tr7)