From 4767a1e8a6327a94536f0337fb082c4b1900b460 Mon Sep 17 00:00:00 2001 From: Ian Cai <67546536+ian60509@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:43:14 +0000 Subject: [PATCH 1/2] finish 3 --- lab1/main_test.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..06266aab 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -4,20 +4,39 @@ const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { // TODO - throw new Error("Test not implemented"); + const cls = new(MyClass) + assert.strictEqual(-1, cls.addStudent(555)) //not the type of Student instance + assert.strictEqual(0, cls.addStudent(new Student())) //add 1 student , should return 0 + assert.strictEqual(1, cls.addStudent(new Student())) + assert.strictEqual(2, cls.addStudent(new Student())) }); test("Test MyClass's getStudentById", () => { // TODO - throw new Error("Test not implemented"); + const cls = new(MyClass) + }); test("Test Student's setName", () => { // TODO - throw new Error("Test not implemented"); + const s = new Student() + assert.strictEqual(undefined, s.name) + + s.setName(123456) + assert.strictEqual(undefined, s.name) + + const str = "Ian" + s.setName(str) + assert.strictEqual(str, s.name) + }); test("Test Student's getName", () => { // TODO - throw new Error("Test not implemented"); + const s = new Student() + assert.strictEqual('', s.getName()) + const str = "Ian" + s.setName(str) + assert.strictEqual(str, s.getName()) + }); \ No newline at end of file From 66ad6cd9b9352195ab642f27186db7012d8c1c02 Mon Sep 17 00:00:00 2001 From: Ian Cai <67546536+ian60509@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:25:55 +0000 Subject: [PATCH 2/2] finish coverage 100% --- lab1/main_test.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 06266aab..63a2f271 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -13,8 +13,16 @@ test("Test MyClass's addStudent", () => { test("Test MyClass's getStudentById", () => { // TODO - const cls = new(MyClass) - + const cls = new MyClass(); + const s = new Student(); + s.setName('Ian'); + cls.addStudent(s); + cls.addStudent(new Student()); + + assert.strictEqual(null, cls.getStudentById(-1) ); + assert.strictEqual(null, cls.getStudentById(3) ) + assert.strictEqual(s, cls.getStudentById(0) ) + }); test("Test Student's setName", () => {