From 00b44d2c228326427bac5aaf6191cacf554d7904 Mon Sep 17 00:00:00 2001 From: martintl25 <martin.tl.25.cs12@nycu.edu.tw> Date: Tue, 5 Mar 2024 00:01:06 +0800 Subject: [PATCH] Update: Complete the test code in . --- 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..209096e5 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 studentInstance = new Student(); + const classInstance = new MyClass(); + assert.strictEqual(classInstance.addStudent(studentInstance), 0); + assert.strictEqual(classInstance.addStudent(1), -1); + // throw new Error("Test not implemented"); }); test("Test MyClass's getStudentById", () => { // TODO - throw new Error("Test not implemented"); + const studentInstance = new Student(); + const classInstance = new MyClass(); + classInstance.addStudent(studentInstance); + assert.strictEqual(classInstance.getStudentById(-1), null); + assert.strictEqual(classInstance.getStudentById(1), null); + assert.deepStrictEqual(classInstance.getStudentById(0), studentInstance); + // throw new Error("Test not implemented"); }); test("Test Student's setName", () => { // TODO - throw new Error("Test not implemented"); + const studentInstance = new Student(); + studentInstance.setName(1); + assert.deepStrictEqual(studentInstance.name, undefined); + studentInstance.setName('a'); + assert.strictEqual(studentInstance.name, 'a'); + // throw new Error("Test not implemented"); }); test("Test Student's getName", () => { // TODO - throw new Error("Test not implemented"); + const studentInstance = new Student(); + assert.strictEqual(studentInstance.getName(), ''); + studentInstance.setName('b'); + assert.strictEqual(studentInstance.getName(), 'b'); + // throw new Error("Test not implemented"); }); \ No newline at end of file