Skip to content

Commit b1047d3

Browse files
authored
Merge branch '510558017' into lab7
2 parents 3e3e824 + f930783 commit b1047d3

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

.github/workflows/lab-autograding.yml

+15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ jobs:
2323
with:
2424
node-version: '20'
2525

26+
27+
- uses: actions/checkout@v4
28+
with:
29+
ref: "${{ github.event.pull_request.merge_commit_sha }}"
30+
fetch-depth: 1
31+
- uses: actions/setup-node@v4
32+
with:
33+
node-version: latest
2634
- name: Extract lab number and Check no changes other than specific files
2735
uses: actions/github-script@v5
2836
id: lab
@@ -46,6 +54,8 @@ jobs:
4654
const labNumber = labNumberMatch[1];
4755
console.log(`Lab number: ${labNumber}`);
4856
57+
console.log(`Lab number: ${labNumber}`)
58+
4959
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
5060
const changedFiles = files.data.map((file) => file.filename);
5161
const allowedFileRegex = /^lab\d+\/main_test.js$/;
@@ -55,6 +65,11 @@ jobs:
5565
}
5666
return labNumber;
5767
68+
69+
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
70+
core.setFailed('The PR contains changes to files other than the allowed files.');
71+
}
72+
return labNumber;
5873
- name: Grading
5974
run: |
6075
cd lab${{ steps.lab.outputs.result }}

lab1/main.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ class Student {
4242
}
4343
}
4444

45-
// const myClass = new MyClass();
46-
// const names = ['John', 'Jane', 'Doe', 'Smith'];
47-
// names.forEach(name => {
48-
// const student = new Student();
49-
// student.setName(name);
50-
// const newStudentId = myClass.addStudent(student);
51-
// const newStudentName = myClass.getStudentById(newStudentId).getName();
52-
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName);
45+
//const myClass = new MyClass();
46+
//const names = ['John', 'Jane', 'Doe', 'Smith'];
47+
//names.forEach(name => {
48+
// const student = new Student();
49+
//student.setName(name);
50+
// const newStudentId = myClass.addStudent(student);
51+
//const newStudentName = myClass.getStudentById(newStudentId).getName();
52+
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName);
5353
// });
5454

55-
module.exports = { MyClass, Student };
55+
module.exports = { MyClass, Student };

lab1/main_test.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,39 @@ const assert = require('assert');
33
const { MyClass, Student } = require('./main');
44

55
test("Test MyClass's addStudent", () => {
6-
// TODO
7-
throw new Error("Test not implemented");
6+
const myClass = new MyClass();
7+
const student = new Student();
8+
student.setName("John");
9+
const index = myClass.addStudent(student);
10+
assert.strictEqual(index, 0, "addStudent should return index 0 for the first student");
11+
const notAStudent = {};
12+
const indexForNotAStudent = myClass.addStudent(notAStudent);
13+
assert.strictEqual(indexForNotAStudent, -1, "addStudent should return -1 when adding a non-Student instance");
814
});
915

1016
test("Test MyClass's getStudentById", () => {
11-
// TODO
12-
throw new Error("Test not implemented");
17+
const myClass = new MyClass();
18+
const student = new Student();
19+
student.setName("Jane");
20+
const index = myClass.addStudent(student);
21+
const fetchedStudent = myClass.getStudentById(index);
22+
assert.strictEqual(fetchedStudent.getName(), "Jane", "getStudentById should retrieve the student with the correct name");
23+
const invalidFetchedStudent = myClass.getStudentById(-1);
24+
assert.strictEqual(invalidFetchedStudent, null, "getStudentById should return null for an invalid id");
1325
});
1426

1527
test("Test Student's setName", () => {
16-
// TODO
17-
throw new Error("Test not implemented");
28+
const student = new Student();
29+
student.setName("Doe");
30+
assert.strictEqual(student.name, "Doe", "setName should correctly set the student's name");
31+
student.setName(123);
32+
assert.strictEqual(student.name, "Doe", "setName should not set name when the input is not a string");
1833
});
1934

2035
test("Test Student's getName", () => {
21-
// TODO
22-
throw new Error("Test not implemented");
23-
});
36+
const student = new Student();
37+
student.setName("Smith");
38+
assert.strictEqual(student.getName(), "Smith", "getName should return the correct name");
39+
const newStudent = new Student();
40+
assert.strictEqual(newStudent.getName(), '', "getName should return an empty string for a student without a name");
41+
});

0 commit comments

Comments
 (0)