|
| 1 | +import {describe, expect, it, test} from '@jest/globals'; |
| 2 | + |
| 3 | +import {Offering} from '../src/types/generatorTypes'; |
| 4 | +import {createOffering, getMinHour, getMinHourDay} from '../src/utils/generatorHelpers'; |
| 5 | + |
| 6 | +describe('getMinHourDay function', () => { |
| 7 | + it('Back to back to back courses', async () => { |
| 8 | + const offering1: Offering = createOffering({ |
| 9 | + id: 1, |
| 10 | + course_id: 101, |
| 11 | + day: 'MO', |
| 12 | + start: '09:00:00', |
| 13 | + end: '10:00:00', |
| 14 | + }); |
| 15 | + const offering2: Offering = createOffering({ |
| 16 | + id: 2, |
| 17 | + course_id: 102, |
| 18 | + day: 'MO', |
| 19 | + start: '10:00:00', |
| 20 | + end: '11:00:00', |
| 21 | + }); |
| 22 | + const offering3: Offering = createOffering({ |
| 23 | + id: 3, |
| 24 | + course_id: 103, |
| 25 | + day: 'MO', |
| 26 | + start: '11:00:00', |
| 27 | + end: '12:00:00', |
| 28 | + }); |
| 29 | + const schedule: Offering[] = [offering1, offering2, offering3]; |
| 30 | + |
| 31 | + const result = getMinHourDay(schedule); |
| 32 | + |
| 33 | + expect(result).toBe(0); // No overlap, should return true |
| 34 | + }); |
| 35 | + |
| 36 | + it('courses that has a max gap of 4 hours', async () => { |
| 37 | + const offering1: Offering = createOffering({ |
| 38 | + id: 1, |
| 39 | + course_id: 101, |
| 40 | + day: 'MO', |
| 41 | + start: '09:00:00', |
| 42 | + end: '10:00:00', |
| 43 | + }); |
| 44 | + const offering2: Offering = createOffering({ |
| 45 | + id: 2, |
| 46 | + course_id: 102, |
| 47 | + day: 'MO', |
| 48 | + start: '10:00:00', |
| 49 | + end: '11:00:00', |
| 50 | + }); |
| 51 | + const offering3: Offering = createOffering({ |
| 52 | + id: 3, |
| 53 | + course_id: 103, |
| 54 | + day: 'MO', |
| 55 | + start: '15:00:00', |
| 56 | + end: '16:00:00', |
| 57 | + }); |
| 58 | + const schedule: Offering[] = [ |
| 59 | + offering3, |
| 60 | + offering2, |
| 61 | + offering1, |
| 62 | + ]; |
| 63 | + |
| 64 | + const result = getMinHourDay(schedule); |
| 65 | + |
| 66 | + expect(result).toBe(4); |
| 67 | + }); |
| 68 | + |
| 69 | + it('only 1 offering in list, return 0', async () => { |
| 70 | + const offering1: Offering = createOffering({ |
| 71 | + id: 1, |
| 72 | + course_id: 101, |
| 73 | + day: 'MO', |
| 74 | + start: '09:00:00', |
| 75 | + end: '10:00:00', |
| 76 | + }); |
| 77 | + const schedule: Offering[] = [offering1]; |
| 78 | + |
| 79 | + const result = getMinHourDay(schedule); |
| 80 | + |
| 81 | + expect(result).toBe(0); |
| 82 | + }); |
| 83 | + |
| 84 | + |
| 85 | + it('getMinHour test', async () => { |
| 86 | + const arr_day = |
| 87 | + ['MO', 'MO', 'TU', 'TH', 'FR', 'MO', 'TU', 'TH', 'MO', 'MO']; |
| 88 | + const arr_start = [ |
| 89 | + '09:00:00', '10:00:00', '09:00:00', '12:00:00', '13:00:00', '12:00:00', |
| 90 | + '14:00:00', '16:00:00', '13:00:00', '15:00:00' |
| 91 | + ]; |
| 92 | + const arr_end = [ |
| 93 | + '10:00:00', '11:00:00', '10:00:00', '15:00:00', '16:00:00', '13:00:00', |
| 94 | + '19:00:00', '18:00:00', '14:00:00', '18:00:00' |
| 95 | + ]; |
| 96 | + const schedule: Offering[] = []; |
| 97 | + for (let i = 0; i < 10; i++) { |
| 98 | + schedule.push(createOffering({ |
| 99 | + id: i, |
| 100 | + course_id: 100 + i, |
| 101 | + day: arr_day[i], |
| 102 | + start: arr_start[i], |
| 103 | + end: arr_end[i] |
| 104 | + })) |
| 105 | + } |
| 106 | + |
| 107 | + const result = getMinHour(schedule); |
| 108 | + |
| 109 | + expect(result).toEqual(4); |
| 110 | + }); |
| 111 | +}); |
0 commit comments