|
1 | | -import {describe, expect, it, test} from '@jest/globals'; |
2 | | - |
3 | | -import {canInsert, createOffering, Offering} from '../src/controllers/generatorController'; |
4 | | - |
5 | | -describe('canInsert function', () => { |
6 | | - const offering1: Offering = createOffering( |
7 | | - {id: 1, course_id: 101, day: 'MO', start: '09:00:00', end: '10:00:00'}); |
8 | | - const offering2: Offering = createOffering( |
9 | | - {id: 2, course_id: 102, day: 'MO', start: '10:00:00', end: '11:00:00'}); |
10 | | - const offering3: Offering = createOffering( |
11 | | - {id: 3, course_id: 103, day: 'MO', start: '11:00:00', end: '12:00:00'}); |
12 | | - |
13 | | - it('should return true if there is no overlap with existing offerings', |
14 | | - async () => { |
15 | | - const toInsert: Offering = createOffering({ |
16 | | - id: 4, |
17 | | - course_id: 104, |
18 | | - day: 'MO', |
19 | | - start: '12:00:00', |
20 | | - end: '13:00:00' |
21 | | - }); |
22 | | - const curList: Offering[] = [offering1, offering2, offering3]; |
23 | | - |
24 | | - const result = await canInsert(toInsert, curList); |
25 | | - |
26 | | - expect(result).toBe(true); // No overlap, should return true |
27 | | - }); |
28 | | - |
29 | | - it('should return false if there is an overlap with an existing offering', |
30 | | - async () => { |
31 | | - const toInsert: Offering = createOffering({ |
32 | | - id: 4, |
33 | | - course_id: 104, |
34 | | - day: 'MO', |
35 | | - start: '09:30:00', |
36 | | - end: '10:30:00' |
37 | | - }); |
38 | | - const curList: Offering[] = [offering1, offering2, offering3]; |
39 | | - |
40 | | - const result = await canInsert(toInsert, curList); |
41 | | - |
42 | | - expect(result).toBe( |
43 | | - false); // There is an overlap with offering1, should return false |
44 | | - }); |
45 | | - |
46 | | - it('should return true if the new offering starts after the last one ends', |
47 | | - async () => { |
48 | | - const toInsert: Offering = createOffering({ |
49 | | - id: 4, |
50 | | - course_id: 104, |
51 | | - day: 'MO', |
52 | | - start: '13:00:00', |
53 | | - end: '14:00:00' |
54 | | - }); |
55 | | - const curList: Offering[] = [offering1, offering2, offering3]; |
56 | | - |
57 | | - const result = await canInsert(toInsert, curList); |
58 | | - |
59 | | - expect(result).toBe(true); // No overlap, should return true |
60 | | - }); |
61 | | - |
62 | | - it('should return true if the new offering ends before the first one starts', |
63 | | - async () => { |
64 | | - const toInsert: Offering = createOffering({ |
65 | | - id: 4, |
66 | | - course_id: 104, |
67 | | - day: 'MO', |
68 | | - start: '07:00:00', |
69 | | - end: '08:00:00' |
70 | | - }); |
71 | | - const curList: Offering[] = [offering1, offering2, offering3]; |
72 | | - |
73 | | - const result = await canInsert(toInsert, curList); |
74 | | - |
75 | | - expect(result).toBe(true); // No overlap, should return true |
76 | | - }); |
77 | | - |
78 | | - it('should return false if the new offering is completely inside an existing one', |
79 | | - async () => { |
80 | | - const toInsert: Offering = createOffering({ |
81 | | - id: 4, |
82 | | - course_id: 104, |
83 | | - day: 'MO', |
84 | | - start: '09:30:00', |
85 | | - end: '09:45:00' |
86 | | - }); |
87 | | - const curList: Offering[] = [offering1, offering2, offering3]; |
88 | | - |
89 | | - const result = await canInsert(toInsert, curList); |
90 | | - |
91 | | - expect(result).toBe( |
92 | | - false); // Overlaps with offering1, should return false |
93 | | - }); |
94 | | - |
95 | | - it('should return true if the day is different (no overlap)', async () => { |
96 | | - const toInsert: Offering = createOffering( |
97 | | - {id: 4, course_id: 104, day: 'TU', start: '09:00:00', end: '10:00:00'}); |
| 1 | +import { describe, expect, it, test } from "@jest/globals"; |
| 2 | + |
| 3 | +import { |
| 4 | + canInsert, |
| 5 | + createOffering, |
| 6 | + Offering, |
| 7 | +} from "../src/controllers/generatorController"; |
| 8 | + |
| 9 | +describe("canInsert function", () => { |
| 10 | + const offering1: Offering = createOffering({ |
| 11 | + id: 1, |
| 12 | + course_id: 101, |
| 13 | + day: "MO", |
| 14 | + start: "09:00:00", |
| 15 | + end: "10:00:00", |
| 16 | + }); |
| 17 | + const offering2: Offering = createOffering({ |
| 18 | + id: 2, |
| 19 | + course_id: 102, |
| 20 | + day: "MO", |
| 21 | + start: "10:00:00", |
| 22 | + end: "11:00:00", |
| 23 | + }); |
| 24 | + const offering3: Offering = createOffering({ |
| 25 | + id: 3, |
| 26 | + course_id: 103, |
| 27 | + day: "MO", |
| 28 | + start: "11:00:00", |
| 29 | + end: "12:00:00", |
| 30 | + }); |
| 31 | + |
| 32 | + it("should return true if there is no overlap with existing offerings", async () => { |
| 33 | + const toInsert: Offering = createOffering({ |
| 34 | + id: 4, |
| 35 | + course_id: 104, |
| 36 | + day: "MO", |
| 37 | + start: "12:00:00", |
| 38 | + end: "13:00:00", |
| 39 | + }); |
| 40 | + const curList: Offering[] = [offering1, offering2, offering3]; |
| 41 | + |
| 42 | + const result = await canInsert(toInsert, curList); |
| 43 | + |
| 44 | + expect(result).toBe(true); // No overlap, should return true |
| 45 | + }); |
| 46 | + |
| 47 | + it("should return false if there is an overlap with an existing offering", async () => { |
| 48 | + const toInsert: Offering = createOffering({ |
| 49 | + id: 4, |
| 50 | + course_id: 104, |
| 51 | + day: "MO", |
| 52 | + start: "09:30:00", |
| 53 | + end: "10:30:00", |
| 54 | + }); |
| 55 | + const curList: Offering[] = [offering1, offering2, offering3]; |
| 56 | + |
| 57 | + const result = await canInsert(toInsert, curList); |
| 58 | + |
| 59 | + expect(result).toBe(false); // There is an overlap with offering1, should return false |
| 60 | + }); |
| 61 | + |
| 62 | + it("should return true if the new offering starts after the last one ends", async () => { |
| 63 | + const toInsert: Offering = createOffering({ |
| 64 | + id: 4, |
| 65 | + course_id: 104, |
| 66 | + day: "MO", |
| 67 | + start: "13:00:00", |
| 68 | + end: "14:00:00", |
| 69 | + }); |
| 70 | + const curList: Offering[] = [offering1, offering2, offering3]; |
| 71 | + |
| 72 | + const result = await canInsert(toInsert, curList); |
| 73 | + |
| 74 | + expect(result).toBe(true); // No overlap, should return true |
| 75 | + }); |
| 76 | + |
| 77 | + it("should return true if the new offering ends before the first one starts", async () => { |
| 78 | + const toInsert: Offering = createOffering({ |
| 79 | + id: 4, |
| 80 | + course_id: 104, |
| 81 | + day: "MO", |
| 82 | + start: "07:00:00", |
| 83 | + end: "08:00:00", |
| 84 | + }); |
| 85 | + const curList: Offering[] = [offering1, offering2, offering3]; |
| 86 | + |
| 87 | + const result = await canInsert(toInsert, curList); |
| 88 | + |
| 89 | + expect(result).toBe(true); // No overlap, should return true |
| 90 | + }); |
| 91 | + |
| 92 | + it("should return false if the new offering is completely inside an existing one", async () => { |
| 93 | + const toInsert: Offering = createOffering({ |
| 94 | + id: 4, |
| 95 | + course_id: 104, |
| 96 | + day: "MO", |
| 97 | + start: "09:30:00", |
| 98 | + end: "09:45:00", |
| 99 | + }); |
| 100 | + const curList: Offering[] = [offering1, offering2, offering3]; |
| 101 | + |
| 102 | + const result = await canInsert(toInsert, curList); |
| 103 | + |
| 104 | + expect(result).toBe(false); // Overlaps with offering1, should return false |
| 105 | + }); |
| 106 | + |
| 107 | + it("should return true if the day is different (no overlap)", async () => { |
| 108 | + const toInsert: Offering = createOffering({ |
| 109 | + id: 4, |
| 110 | + course_id: 104, |
| 111 | + day: "TU", |
| 112 | + start: "09:00:00", |
| 113 | + end: "10:00:00", |
| 114 | + }); |
98 | 115 | const curList: Offering[] = [offering1, offering2, offering3]; |
99 | 116 |
|
100 | 117 | const result = await canInsert(toInsert, curList); |
101 | 118 |
|
102 | | - expect(result).toBe(true); // Different day, no overlap |
| 119 | + expect(result).toBe(true); // Different day, no overlap |
103 | 120 | }); |
104 | 121 | }); |
0 commit comments