From 69aebc414316140b4b55870c93ce164c925aa57e Mon Sep 17 00:00:00 2001 From: HanHongChen <127834396+HanHongChen@users.noreply.github.com> Date: Thu, 29 Feb 2024 07:43:25 +0000 Subject: [PATCH 1/2] tmp --- lab1/main_test.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..1f121388 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -4,11 +4,26 @@ const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + //check fail case + assert.strictEqual(myClass.addStudent({}), -1); + //check success case + assert.strictEqual(myClass.addStudent(new Student), 0); + }); test("Test MyClass's getStudentById", () => { // TODO + const myClass = new MyClass(); + 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(); + console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName); + }); + assert.strictEqual(myClass.getStudentById()) throw new Error("Test not implemented"); }); From f35c9d049ca2562c1e31707a8e13c890d49011f6 Mon Sep 17 00:00:00 2001 From: HanHongChen <127834396+HanHongChen@users.noreply.github.com> Date: Thu, 29 Feb 2024 10:05:39 +0000 Subject: [PATCH 2/2] finished lab1 --- lab1/main_test.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 1f121388..71e859ac 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -15,24 +15,35 @@ test("Test MyClass's addStudent", () => { test("Test MyClass's getStudentById", () => { // TODO const myClass = new MyClass(); + assert.strictEqual(myClass.getStudentById(-1), null); + assert.strictEqual(myClass.getStudentById(10), null); 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(); - console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName); }); - assert.strictEqual(myClass.getStudentById()) - throw new Error("Test not implemented"); + assert.strictEqual(myClass.getStudentById(0).getName(), 'John'); + assert.strictEqual(myClass.getStudentById(1).getName(), 'Jane'); + assert.strictEqual(myClass.getStudentById(2).getName(), 'Doe'); + assert.strictEqual(myClass.getStudentById(3).getName(), 'Smith'); }); test("Test Student's setName", () => { // TODO - throw new Error("Test not implemented"); + const student = new Student(); + student.setName(123); + assert.strictEqual(student.getName(), ''); + student.setName('123'); + assert.strictEqual(student.getName(), '123'); }); test("Test Student's getName", () => { // TODO - throw new Error("Test not implemented"); + const student = new Student(); + student.setName(123); + assert.strictEqual(student.getName(), ''); + student.setName('123'); + assert.strictEqual(student.getName(), '123'); }); \ No newline at end of file