Skip to content

Commit 3beb5ff

Browse files
authored
Merge branch '510558017' into lab6
2 parents cb140de + f930783 commit 3beb5ff

File tree

4 files changed

+67
-18
lines changed

4 files changed

+67
-18
lines changed

.github/workflows/lab-autograding.yml

+21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
os: [ubuntu-22.04]
1313
fail-fast: false
1414
steps:
15+
1516
- name: Checkout repository
1617
uses: actions/checkout@v4
1718
with:
@@ -23,6 +24,15 @@ jobs:
2324
with:
2425
node-version: '20'
2526

27+
28+
- uses: actions/checkout@v4
29+
with:
30+
ref: "${{ github.event.pull_request.merge_commit_sha }}"
31+
fetch-depth: 1
32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: latest
35+
2636
- name: Extract lab number and Check no changes other than specific files
2737
uses: actions/github-script@v5
2838
id: lab
@@ -44,17 +54,28 @@ jobs:
4454
return { number: 0 };
4555
}
4656
const labNumber = labNumberMatch[1];
57+
4758
console.log(`Lab number: ${labNumber}`);
4859
60+
console.log(`Lab number: ${labNumber}`)
61+
62+
4963
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
5064
const changedFiles = files.data.map((file) => file.filename);
5165
const allowedFileRegex = /^lab\d+\/main_test.js$/;
5266
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md", "lab7/sol.py"];
67+
5368
if (!changedFiles.every((file) => allowedFileRegex.test(file) || specialChangedFiles.includes(file))) {
5469
core.setFailed('The PR contains changes to files other than the allowed files.');
5570
}
5671
return labNumber;
5772
73+
74+
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
75+
core.setFailed('The PR contains changes to files other than the allowed files.');
76+
}
77+
return labNumber;
78+
5879
- name: Grading
5980
run: |
6081
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+
});

lab6/Answer.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Name: 楊杰峰
23
ID: 510558017
34

@@ -28,10 +29,18 @@ ID: 510558017
2829
│ trim : 12.50%/7, 0.00% ├────────────────────────┘
2930
│─────────────────────────────────────────────────────┘ [cpu000: 31%]
3031
32+
Name:
33+
ID:
34+
35+
### Fuzz Monitor
36+
```
37+
38+
3139
```
3240
3341
### Run Crash Result
3442
```
43+
3544
jf@jf-VirtualBox:~/510558017/510558017/lab6/fuzz$ ../src/bmpcomp out/crashes/id\:000000\,sig\:06\,src\:000001\,op\:flip1\,pos\:20
3645
size of Header 54
3746
AddressSanitizer:DEADLYSIGNAL
@@ -44,4 +53,5 @@ AddressSanitizer:DEADLYSIGNAL
4453
SUMMARY: AddressSanitizer: stack-overflow /home/jf/510558017/510558017/lab6/src/hw0302.c:46 in main
4554
==7016==ABORTING
4655

56+
4757
```

0 commit comments

Comments
 (0)