From 7e3f807e9c171529044e254eae9d009e0082b59b Mon Sep 17 00:00:00 2001 From: Deron5566 Date: Thu, 29 Feb 2024 16:42:03 +0800 Subject: [PATCH 1/3] lab1 finish --- lab1/main_test.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..8433371c 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -4,20 +4,42 @@ const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const student = new Student(); + student.setName('John'); + assert.strictEqual(myClass.addStudent(student), 0); + assert.strictEqual(myClass.addStudent(123), -1); + // throw new Error("Test not implemented"); }); test("Test MyClass's getStudentById", () => { // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const student = new Student(); + student.setName('John'); + const newStudentId = myClass.addStudent(student); + assert.strictEqual(myClass.getStudentById(newStudentId), student); + assert.strictEqual(myClass.getStudentById(-1), null); + assert.strictEqual(myClass.getStudentById(2), null); + // throw new Error("Test not implemented"); }); test("Test Student's setName", () => { // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const student = new Student(); + student.setName('John'); + assert.strictEqual(student.name, 'John'); + student.setName(123); + // throw new Error("Test not implemented"); }); test("Test Student's getName", () => { // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const student = new Student(); + assert.strictEqual(student.getName(), ''); + student.setName('John'); + assert.strictEqual(student.getName(), 'John'); + // throw new Error("Test not implemented"); }); \ No newline at end of file From fbea7e8c3908f46fbcce3b8a750157294427acac Mon Sep 17 00:00:00 2001 From: Deron5566 Date: Thu, 29 Feb 2024 18:10:21 +0800 Subject: [PATCH 2/3] update test cases in main_test.js --- lab1/main_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 8433371c..f4780162 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -19,7 +19,7 @@ test("Test MyClass's getStudentById", () => { student.setName('John'); const newStudentId = myClass.addStudent(student); assert.strictEqual(myClass.getStudentById(newStudentId), student); - assert.strictEqual(myClass.getStudentById(-1), null); + assert.strictEqual(myClass.getStudentById(-2), null); assert.strictEqual(myClass.getStudentById(2), null); // throw new Error("Test not implemented"); }); From f351ec257acf650c4ca76aeec8c4bb5db8690c99 Mon Sep 17 00:00:00 2001 From: Deron5566 Date: Thu, 7 Mar 2024 20:15:54 +0800 Subject: [PATCH 3/3] Remove unnecessary comment and stub code --- lab1/main_test.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index f4780162..9d32cb55 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -3,17 +3,14 @@ const assert = require('assert'); const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { - // TODO const myClass = new MyClass(); const student = new Student(); student.setName('John'); assert.strictEqual(myClass.addStudent(student), 0); assert.strictEqual(myClass.addStudent(123), -1); - // throw new Error("Test not implemented"); }); test("Test MyClass's getStudentById", () => { - // TODO const myClass = new MyClass(); const student = new Student(); student.setName('John'); @@ -21,25 +18,20 @@ test("Test MyClass's getStudentById", () => { assert.strictEqual(myClass.getStudentById(newStudentId), student); assert.strictEqual(myClass.getStudentById(-2), null); assert.strictEqual(myClass.getStudentById(2), null); - // throw new Error("Test not implemented"); }); test("Test Student's setName", () => { - // TODO const myClass = new MyClass(); const student = new Student(); student.setName('John'); assert.strictEqual(student.name, 'John'); student.setName(123); - // throw new Error("Test not implemented"); }); test("Test Student's getName", () => { - // TODO const myClass = new MyClass(); const student = new Student(); assert.strictEqual(student.getName(), ''); student.setName('John'); assert.strictEqual(student.getName(), 'John'); - // throw new Error("Test not implemented"); }); \ No newline at end of file