Skip to content

Commit 5dda1c6

Browse files
dawangkgithub-actions[bot]
authored andcommitted
Auto-formatted the code using Prettier
1 parent d6a653f commit 5dda1c6

File tree

3 files changed

+107
-56
lines changed

3 files changed

+107
-56
lines changed

course-matrix/backend/__tests__/getFrequencyTable.test.ts

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,71 @@ import {
99
describe("getFrequencyTable", () => {
1010
test("should return a frequency map of days", () => {
1111
const offering1: Offering = createOffering({
12-
id: 1,
13-
course_id: 101,
14-
day: "MO",
15-
start: "09:00:00",
16-
end: "10:00:00",
12+
id: 1,
13+
course_id: 101,
14+
day: "MO",
15+
start: "09:00:00",
16+
end: "10:00:00",
1717
});
1818
const offering2: Offering = createOffering({
19-
id: 2,
20-
course_id: 102,
21-
day: "TU",
22-
start: "10:00:00",
23-
end: "11:00:00",
19+
id: 2,
20+
course_id: 102,
21+
day: "TU",
22+
start: "10:00:00",
23+
end: "11:00:00",
2424
});
2525
const offering3: Offering = createOffering({
26-
id: 3,
27-
course_id: 103,
28-
day: "TU",
29-
start: "11:00:00",
30-
end: "12:00:00",
26+
id: 3,
27+
course_id: 103,
28+
day: "TU",
29+
start: "11:00:00",
30+
end: "12:00:00",
3131
});
3232
const offering4: Offering = createOffering({
33-
id: 4,
34-
course_id: 104,
35-
day: "MO",
36-
start: "11:00:00",
37-
end: "12:00:00",
33+
id: 4,
34+
course_id: 104,
35+
day: "MO",
36+
start: "11:00:00",
37+
end: "12:00:00",
3838
});
3939
const offering5: Offering = createOffering({
40-
id: 5,
41-
course_id: 105,
42-
day: "WE",
43-
start: "11:00:00",
44-
end: "12:00:00",
40+
id: 5,
41+
course_id: 105,
42+
day: "WE",
43+
start: "11:00:00",
44+
end: "12:00:00",
4545
});
4646
const offering6: Offering = createOffering({
47-
id: 6,
48-
course_id: 106,
49-
day: "WE",
50-
start: "11:00:00",
51-
end: "12:00:00",
47+
id: 6,
48+
course_id: 106,
49+
day: "WE",
50+
start: "11:00:00",
51+
end: "12:00:00",
5252
});
5353
const offering7: Offering = createOffering({
54-
id: 7,
55-
course_id: 107,
56-
day: "WE",
57-
start: "11:00:00",
58-
end: "12:00:00",
54+
id: 7,
55+
course_id: 107,
56+
day: "WE",
57+
start: "11:00:00",
58+
end: "12:00:00",
5959
});
6060

61-
const result = getFrequencyTable([offering1, offering2, offering3, offering4, offering5, offering6, offering7]);
61+
const result = getFrequencyTable([
62+
offering1,
63+
offering2,
64+
offering3,
65+
offering4,
66+
offering5,
67+
offering6,
68+
offering7,
69+
]);
6270

6371
expect(result.get("MO")).toBe(2);
6472
expect(result.get("TU")).toBe(2);
6573
expect(result.get("WE")).toBe(3);
66-
expect(result.get("TH")).toBeUndefined();// Day not in data
67-
expect(result.get("FR")).toBeUndefined();// Day not in data
68-
expect(result.size).toBe(3);
74+
expect(result.get("TH")).toBeUndefined(); // Day not in data
75+
expect(result.get("FR")).toBeUndefined(); // Day not in data
76+
expect(result.size).toBe(3);
6977
});
7078

7179
test("should return an empty map for an empty array", () => {

course-matrix/backend/__tests__/isValidOffering.test.ts

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Offering,
66
isValidOffering,
77
Restriction,
8-
RestrictionType
8+
RestrictionType,
99
} from "../src/controllers/generatorController";
1010

1111
describe("isValidOffering", () => {
@@ -15,50 +15,92 @@ describe("isValidOffering", () => {
1515
day: "MO",
1616
start: "10:00:00",
1717
end: "11:00:00",
18-
});
18+
});
1919

2020
test("should allow offering if there are no restrictions", () => {
2121
expect(isValidOffering(sampleOffering, [])).toBe(true);
2222
});
2323

2424
test("should allow offering if all restrictions are disabled", () => {
2525
const restrictions: Restriction[] = [
26-
{ type: RestrictionType.RestrictBefore, days: [], startTime: "09:00:00", endTime: "", disabled: true, numDays: 0 },
26+
{
27+
type: RestrictionType.RestrictBefore,
28+
days: [],
29+
startTime: "09:00:00",
30+
endTime: "",
31+
disabled: true,
32+
numDays: 0,
33+
},
2734
];
2835
expect(isValidOffering(sampleOffering, restrictions)).toBe(true);
2936
});
3037

3138
test("should reject offering if it starts before restriction start time", () => {
3239
const restrictions: Restriction[] = [
33-
{ type: RestrictionType.RestrictBefore, days: [], startTime: "10:30:00", endTime: "", disabled: false, numDays: 0 },
40+
{
41+
type: RestrictionType.RestrictBefore,
42+
days: [],
43+
startTime: "10:30:00",
44+
endTime: "",
45+
disabled: false,
46+
numDays: 0,
47+
},
3448
];
3549
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
3650
});
3751

3852
test("should reject offering if it ends after restriction end time", () => {
3953
const restrictions: Restriction[] = [
40-
{ type: RestrictionType.RestrictAfter, days: [], startTime: "", endTime: "10:30:00", disabled: false, numDays: 0 },
54+
{
55+
type: RestrictionType.RestrictAfter,
56+
days: [],
57+
startTime: "",
58+
endTime: "10:30:00",
59+
disabled: false,
60+
numDays: 0,
61+
},
4162
];
4263
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
4364
});
4465

4566
test("should reject offering if it is within restricted time range", () => {
4667
const restrictions: Restriction[] = [
47-
{ type: RestrictionType.RestrictBetween, days: [], startTime: "09:00:00", endTime: "12:00:00", disabled: false, numDays: 0 },
68+
{
69+
type: RestrictionType.RestrictBetween,
70+
days: [],
71+
startTime: "09:00:00",
72+
endTime: "12:00:00",
73+
disabled: false,
74+
numDays: 0,
75+
},
4876
];
4977
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
5078
});
5179

5280
test("should reject offering if the day is restricted", () => {
5381
const restrictions: Restriction[] = [
54-
{ type: RestrictionType.RestrictDay, days: ["MO"], startTime: "", endTime: "", disabled: false, numDays: 0 },
82+
{
83+
type: RestrictionType.RestrictDay,
84+
days: ["MO"],
85+
startTime: "",
86+
endTime: "",
87+
disabled: false,
88+
numDays: 0,
89+
},
5590
];
5691
expect(isValidOffering(sampleOffering, restrictions)).toBe(false);
5792
});
5893

5994
test("should allow offering if the day is not restricted", () => {
6095
const restrictions: Restriction[] = [
61-
{ type: RestrictionType.RestrictDay, days: ["TU"], startTime: "", endTime: "", disabled: false, numDays: 0 },
96+
{
97+
type: RestrictionType.RestrictDay,
98+
days: ["TU"],
99+
startTime: "",
100+
endTime: "",
101+
disabled: false,
102+
numDays: 0,
103+
},
62104
];
63105
expect(isValidOffering(sampleOffering, restrictions)).toBe(true);
64106
});

course-matrix/backend/src/controllers/generatorController.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const filterValidOfferings = (
103103
f: (x: Offering) => boolean,
104104
): Offering[] => {
105105
return offerings.filter(f);
106-
}
106+
};
107107

108108
// Function to check if an offering satisfies the restrictions
109109
export function isValidOffering(
@@ -125,7 +125,7 @@ export function isValidOffering(
125125

126126
case RestrictionType.RestrictBetween:
127127
if (
128-
offering.start < restriction.endTime &&
128+
offering.start < restriction.endTime &&
129129
restriction.startTime < offering.end
130130
) {
131131
return false;
@@ -181,8 +181,8 @@ export function getFrequencyTable(arr: Offering[]): Map<string, number> {
181181
const freqMap = new Map<string, number>();
182182

183183
for (const item of arr) {
184-
const count = freqMap.get(item.day) || 0;
185-
freqMap.set(item.day, count + 1);
184+
const count = freqMap.get(item.day) || 0;
185+
freqMap.set(item.day, count + 1);
186186
}
187187
return freqMap;
188188
}
@@ -194,7 +194,7 @@ export async function getValidSchedules(
194194
curList: Offering[],
195195
cur: number,
196196
len: number,
197-
maxdays: number
197+
maxdays: number,
198198
) {
199199
// Base case: if all courses have been considered
200200
if (cur == len) {
@@ -203,7 +203,7 @@ export async function getValidSchedules(
203203
// If the number of unique days is within the allowed limit, add the current schedule to the list
204204
if (freq.size <= maxdays) {
205205
validSchedules.push([...curList]); // Push a copy of the current list
206-
}
206+
}
207207
return;
208208
}
209209

@@ -221,7 +221,7 @@ export async function getValidSchedules(
221221
curList,
222222
cur + 1,
223223
len,
224-
maxdays
224+
maxdays,
225225
);
226226

227227
// Backtrack: remove the last offering if no valid schedule was found
@@ -271,7 +271,7 @@ export default {
271271
[],
272272
0,
273273
validCourseOfferingsList.length,
274-
maxdays
274+
maxdays,
275275
);
276276

277277
// Return error if no valid schedules are found
@@ -283,7 +283,8 @@ export default {
283283
return res.status(200).json({ validSchedules });
284284
} catch (error) {
285285
// Catch any error and return the error message
286-
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
286+
const errorMessage =
287+
error instanceof Error ? error.message : "An unknown error occurred";
287288
return res.status(500).send({ error: errorMessage });
288289
}
289290
}),

0 commit comments

Comments
 (0)