diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 78b908d9..fa079b42 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,8 @@ ## Description + + + --- @@ -7,9 +10,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 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. 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