From 08566e4a967b7c44343672a08985aed7f2f179ce Mon Sep 17 00:00:00 2001 From: LIN0519 Date: Fri, 1 Mar 2024 00:05:52 +0800 Subject: [PATCH] First commit --- lab1/main_test.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..6ea49d63 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -3,21 +3,36 @@ const assert = require('assert'); const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + const myClass = new MyClass(); + + assert.strictEqual(myClass.addStudent(student), 0); // first student + assert.strictEqual(myClass.addStudent(myClass), -1); // return -1 }); test("Test MyClass's getStudentById", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + const myClass = new MyClass(); + + const newStudentId = myClass.addStudent(student); + assert.strictEqual(myClass.getStudentById(newStudentId), student); + assert.strictEqual(myClass.getStudentById(100), null); // over length }); test("Test Student's setName", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + + student.setName("John"); // 使用assert.strictEqual来断言student的name属性是否被正确设置 + assert.strictEqual(student.name, "John"); + + student.setName(123); // 尝试使用非字符串值设置 + assert.strictEqual(student.name, "John"); }); test("Test Student's getName", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); // undefined + assert.strictEqual(student.getName(), ''); + + student.setName("Jane"); + assert.strictEqual(student.getName(), "Jane"); }); \ No newline at end of file