From d71d11c0229c5fb396d4c0c0a65b75f57f9b1e50 Mon Sep 17 00:00:00 2001 From: chris-chi-chen <81693866+chris-chi-chen@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:09:46 +0800 Subject: [PATCH] Update main_test.js complete all --- lab1/main_test.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..f5fb3481 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -1,23 +1,35 @@ -const test = require('node:test'); -const assert = require('assert'); -const { MyClass, Student } = require('./main'); +const test = require("node:test"); +const assert = require("assert"); +const { MyClass, Student } = require("./main"); test("Test MyClass's addStudent", () => { - // TODO - throw new Error("Test not implemented"); + let test_class = new MyClass(); + let test_student = new Student(); + assert.strictEqual( + test_class.addStudent(test_student), + test_class.students.length - 1 + ); + assert.strictEqual(test_class.addStudent(123), -1); }); test("Test MyClass's getStudentById", () => { - // TODO - throw new Error("Test not implemented"); + let test_class = new MyClass(); + assert.strictEqual(test_class.getStudentById(1), null); + test_class.addStudent(new Student()); + assert.strictEqual(test_class.getStudentById(0), test_class.students[0]); }); test("Test Student's setName", () => { - // TODO - throw new Error("Test not implemented"); + let test_student = new Student(); + test_student.setName(123); + assert.strictEqual(test_student.name, undefined); + test_student.setName("Tony"); + assert.strictEqual(test_student.name, "Tony"); }); test("Test Student's getName", () => { - // TODO - throw new Error("Test not implemented"); -}); \ No newline at end of file + let test_student = new Student(); + assert.strictEqual(test_student.getName(), ""); + test_student.setName("Tony"); + assert.strictEqual(test_student.getName(), "Tony"); +});