|
| 1 | +import { describe, expect, it, test } from "@jest/globals"; |
| 2 | + |
| 3 | +import { Offering } from "../src/types/generatorTypes"; |
| 4 | +import { |
| 5 | + createOffering, |
| 6 | + getMinHour, |
| 7 | + getMinHourDay, |
| 8 | +} from "../src/utils/generatorHelpers"; |
| 9 | + |
| 10 | +describe("getMinHourDay function", () => { |
| 11 | + it("Back to back to back courses", async () => { |
| 12 | + const offering1: Offering = createOffering({ |
| 13 | + id: 1, |
| 14 | + course_id: 101, |
| 15 | + day: "MO", |
| 16 | + start: "09:00:00", |
| 17 | + end: "10:00:00", |
| 18 | + }); |
| 19 | + const offering2: Offering = createOffering({ |
| 20 | + id: 2, |
| 21 | + course_id: 102, |
| 22 | + day: "MO", |
| 23 | + start: "10:00:00", |
| 24 | + end: "11:00:00", |
| 25 | + }); |
| 26 | + const offering3: Offering = createOffering({ |
| 27 | + id: 3, |
| 28 | + course_id: 103, |
| 29 | + day: "MO", |
| 30 | + start: "11:00:00", |
| 31 | + end: "12:00:00", |
| 32 | + }); |
| 33 | + const schedule: Offering[] = [offering1, offering2, offering3]; |
| 34 | + |
| 35 | + const result = getMinHourDay(schedule, 0); |
| 36 | + |
| 37 | + expect(result).toBe(true); |
| 38 | + }); |
| 39 | + |
| 40 | + it("courses that has a max gap of 4 hours", async () => { |
| 41 | + const offering1: Offering = createOffering({ |
| 42 | + id: 1, |
| 43 | + course_id: 101, |
| 44 | + day: "MO", |
| 45 | + start: "09:00:00", |
| 46 | + end: "10:00:00", |
| 47 | + }); |
| 48 | + const offering2: Offering = createOffering({ |
| 49 | + id: 2, |
| 50 | + course_id: 102, |
| 51 | + day: "MO", |
| 52 | + start: "10:00:00", |
| 53 | + end: "11:00:00", |
| 54 | + }); |
| 55 | + const offering3: Offering = createOffering({ |
| 56 | + id: 3, |
| 57 | + course_id: 103, |
| 58 | + day: "MO", |
| 59 | + start: "15:00:00", |
| 60 | + end: "16:00:00", |
| 61 | + }); |
| 62 | + const schedule: Offering[] = [offering3, offering2, offering1]; |
| 63 | + |
| 64 | + const result = getMinHourDay(schedule, 3); |
| 65 | + |
| 66 | + expect(result).toBe(false); |
| 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, 23); |
| 80 | + |
| 81 | + expect(result).toBe(true); |
| 82 | + }); |
| 83 | + |
| 84 | + it("getMinHour test", async () => { |
| 85 | + const arr_day = [ |
| 86 | + "MO", |
| 87 | + "MO", |
| 88 | + "TU", |
| 89 | + "TH", |
| 90 | + "FR", |
| 91 | + "MO", |
| 92 | + "TU", |
| 93 | + "TH", |
| 94 | + "MO", |
| 95 | + "MO", |
| 96 | + ]; |
| 97 | + const arr_start = [ |
| 98 | + "09:00:00", |
| 99 | + "10:00:00", |
| 100 | + "09:00:00", |
| 101 | + "12:00:00", |
| 102 | + "13:00:00", |
| 103 | + "12:00:00", |
| 104 | + "14:00:00", |
| 105 | + "16:00:00", |
| 106 | + "13:00:00", |
| 107 | + "15:00:00", |
| 108 | + ]; |
| 109 | + const arr_end = [ |
| 110 | + "10:00:00", |
| 111 | + "11:00:00", |
| 112 | + "10:00:00", |
| 113 | + "15:00:00", |
| 114 | + "16:00:00", |
| 115 | + "13:00:00", |
| 116 | + "19:00:00", |
| 117 | + "18:00:00", |
| 118 | + "14:00:00", |
| 119 | + "18:00:00", |
| 120 | + ]; |
| 121 | + const schedule: Offering[] = []; |
| 122 | + for (let i = 0; i < 10; i++) { |
| 123 | + schedule.push( |
| 124 | + createOffering({ |
| 125 | + id: i, |
| 126 | + course_id: 100 + i, |
| 127 | + day: arr_day[i], |
| 128 | + start: arr_start[i], |
| 129 | + end: arr_end[i], |
| 130 | + }), |
| 131 | + ); |
| 132 | + } |
| 133 | + |
| 134 | + const result = getMinHour(schedule, 4); |
| 135 | + |
| 136 | + expect(result).toEqual(true); |
| 137 | + }); |
| 138 | + |
| 139 | + it("getMinHour test 2", async () => { |
| 140 | + const arr_day = [ |
| 141 | + "MO", |
| 142 | + "MO", |
| 143 | + "TU", |
| 144 | + "TH", |
| 145 | + "FR", |
| 146 | + "MO", |
| 147 | + "TU", |
| 148 | + "TH", |
| 149 | + "MO", |
| 150 | + "MO", |
| 151 | + ]; |
| 152 | + const arr_start = [ |
| 153 | + "09:00:00", |
| 154 | + "10:00:00", |
| 155 | + "09:00:00", |
| 156 | + "12:00:00", |
| 157 | + "13:00:00", |
| 158 | + "12:00:00", |
| 159 | + "14:00:00", |
| 160 | + "16:00:00", |
| 161 | + "13:00:00", |
| 162 | + "15:00:00", |
| 163 | + ]; |
| 164 | + const arr_end = [ |
| 165 | + "10:00:00", |
| 166 | + "11:00:00", |
| 167 | + "10:00:00", |
| 168 | + "15:00:00", |
| 169 | + "16:00:00", |
| 170 | + "13:00:00", |
| 171 | + "19:00:00", |
| 172 | + "18:00:00", |
| 173 | + "14:00:00", |
| 174 | + "18:00:00", |
| 175 | + ]; |
| 176 | + const schedule: Offering[] = []; |
| 177 | + for (let i = 0; i < 10; i++) { |
| 178 | + schedule.push( |
| 179 | + createOffering({ |
| 180 | + id: i, |
| 181 | + course_id: 100 + i, |
| 182 | + day: arr_day[i], |
| 183 | + start: arr_start[i], |
| 184 | + end: arr_end[i], |
| 185 | + }), |
| 186 | + ); |
| 187 | + } |
| 188 | + |
| 189 | + const result = getMinHour(schedule, 3); |
| 190 | + |
| 191 | + expect(result).toEqual(false); |
| 192 | + }); |
| 193 | +}); |
0 commit comments