From 20ca92f8fe881c55c4a73a733ad4675d487649c3 Mon Sep 17 00:00:00 2001 From: Mushroom-MSL1L Date: Fri, 1 Mar 2024 17:36:32 +0800 Subject: [PATCH] test : lab1 main testing 1. test all MyClass member functions 2. test all Student member functions 3. coverage of main up to 100% --- lab1/main_test.js | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..0adfea1d 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -4,20 +4,47 @@ const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const student = new Student(); + + assert.strictEqual(myClass.addStudent("variable that is not Student"), -1); + assert.strictEqual(myClass.addStudent(student), myClass.students.length-1); + + // throw new Error("Test not implemented"); }); test("Test MyClass's getStudentById", () => { // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + const student = new Student(); + myClass.addStudent(student); + + assert.strictEqual(myClass.getStudentById(myClass.students.length), null); + assert.strictEqual(myClass.getStudentById(myClass.students.length - 1), student); + assert.strictEqual(myClass.getStudentById(0), student); + assert.strictEqual(myClass.getStudentById(-1), null); + + // throw new Error("Test not implemented"); }); test("Test Student's setName", () => { // TODO - throw new Error("Test not implemented"); + const student = new Student(); + assert.strictEqual(student.setName(123), undefined); + + // throw new Error("Test not implemented"); }); test("Test Student's getName", () => { // TODO - throw new Error("Test not implemented"); -}); \ No newline at end of file + const student = new Student(); + student.setName("John"); + assert.strictEqual(student.getName(), "John"); + + const student2 = new Student(); + student2.setName(123); + assert.strictEqual(student2.getName(), ''); + + // throw new Error("Test not implemented"); +}); +