From f25b3445483e7956c62ac3dea12db044502c7ce5 Mon Sep 17 00:00:00 2001 From: 108062204 Date: Thu, 29 Feb 2024 20:05:16 +0800 Subject: [PATCH] almost finish --- lab1/main_test.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 1cb3db74..779c2895 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -7,9 +7,10 @@ test("Test MyClass's addStudent", () => { const myClass = new MyClass(); const student = new Student(); const name="Daniel"; - student.setName(name); - assert.strictEqual(myClass.addStudent(student),1); - throw new Error("Test not implemented"); + student.name=name; + assert.strictEqual(myClass.addStudent(student),0); + assert.strictEqual(myClass.addStudent("Daniel"),-1); + //throw new Error("Test not implemented"); }); test("Test MyClass's getStudentById", () => { @@ -17,28 +18,31 @@ test("Test MyClass's getStudentById", () => { const myClass = new MyClass(); const student = new Student(); const name="Daniel"; - student.setName(name); - const newStudentId=myClass.addStudent(student); - assert.strictEqual(myClass.getStudentById(newStudentId).getName(),"Daniel"); - throw new Error("Test not implemented"); + student.name=name; + myClass.students.push(student); + assert.strictEqual(myClass.getStudentById(0).name,"Daniel"); + assert.strictEqual(myClass.getStudentById(1),null); + //throw new Error("Test not implemented"); }); test("Test Student's setName", () => { // TODO - const myClass = new MyClass(); const student = new Student(); const name="Daniel"; student.setName(name); assert.strictEqual(student.name,"Daniel"); - throw new Error("Test not implemented"); + student.setName(123); + assert.strictEqual(student.name,"Daniel"); + //throw new Error("Test not implemented"); }); test("Test Student's getName", () => { // TODO - const myClass = new MyClass(); const student = new Student(); const name="Daniel"; student.name=name; - assert.strictEqual(student.getName(),"Daniel") - throw new Error("Test not implemented"); + assert.strictEqual(student.getName(),"Daniel"); + student.name=undefined; + assert.strictEqual(student.getName(),""); + //throw new Error("Test not implemented"); }); \ No newline at end of file