From ad9bfacedd895976554216f6ad0d127e5bd62d6d Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 14:18:44 +0800 Subject: [PATCH 1/4] doc: add title's description and branch warning in pr template --- .github/pull_request_template.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 78b908d9..1d79d8c9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,9 +7,9 @@ -- [ ] A clear title +- [ ] A clear title (name your pr "[LAB{lab_number}] {your_student_id}") - [ ] A meaningful message for PR, as well as its commits -- [ ] From your specific branch (***not master***) merging to your branch +- [ ] From your specific branch (***not main or other's branch***) merging to your branch - [ ] Excluding any irrelevant files, such as binaries, text files, or dot files - [ ] Passing tests/CI - [ ] Add proper label for this PR From a5a9797bd7bc598c63163a29fca374837fd0ccc7 Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 14:19:05 +0800 Subject: [PATCH 2/4] feat: remove badge requirement in lab1 --- lab1/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lab1/README.md b/lab1/README.md index f205b0b9..779166ca 100644 --- a/lab1/README.md +++ b/lab1/README.md @@ -6,8 +6,7 @@ In this lab, you will write unit tests for functions implemented in `main.js`. Y ## Requirement -1. Write test cases in `main_test.js` and achieve 100% code coverage. (90%) -2. Add a badge and make it show `passing` in `README.md` in the root folder. (10%) +1. Write test cases in `main_test.js` and achieve 100% code coverage. (100%) You can run `validate.sh` in your local to test if you satisfy the requirements. From 01554ce0d9f96bc7afbc80cb7cdfadb0610910df Mon Sep 17 00:00:00 2001 From: Sun Date: Thu, 29 Feb 2024 14:21:46 +0800 Subject: [PATCH 3/4] doc: add sample's link in pr template --- .github/pull_request_template.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 1d79d8c9..fa079b42 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,8 @@ ## Description + + + --- From 2d1189d8c98827c15d3453b22aa8b50557a7b378 Mon Sep 17 00:00:00 2001 From: CTHua Date: Thu, 29 Feb 2024 15:12:10 +0800 Subject: [PATCH 4/4] feat: done --- lab1/main_test.js | 48 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..92823652 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -3,21 +3,53 @@ const assert = require('assert'); const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { - // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + // if student is not an instance of Student, return -1 + assert.strictEqual(myClass.addStudent({}), -1); + + // normal case + const names = ['John', 'Jane', 'Doe', 'Smith']; + names.forEach(name => { + const student = new Student(); + student.setName(name); + const newStudentId = myClass.addStudent(student); + const newStudentName = myClass.getStudentById(newStudentId).getName(); + assert.strictEqual(newStudentName, name); + }); }); test("Test MyClass's getStudentById", () => { - // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + // if id is less than 0, return null + assert.strictEqual(myClass.getStudentById(-1), null); + + // normal case + const names = ['John', 'Jane', 'Doe', 'Smith']; + names.forEach(name => { + const student = new Student(); + student.setName(name); + const newStudentId = myClass.addStudent(student); + const newStudent = myClass.getStudentById(newStudentId); + assert.strictEqual(student, newStudent); + }); + // if id is greater than or equal to the length of students, return null + assert.strictEqual(myClass.getStudentById(names.length), null); }); test("Test Student's setName", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + student.setName('John'); + assert.strictEqual(student.getName(), 'John'); + // Test if setName accepts only string + student.setName(123); + assert.strictEqual(student.getName(), 'John'); }); test("Test Student's getName", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + // Test if getName returns empty string if name is undefined + assert.strictEqual(student.getName(), ''); + // Test if getName returns the name set by setName + student.setName('John'); + assert.strictEqual(student.getName(), 'John'); }); \ No newline at end of file