diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b4..4b5e9b54 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -1,23 +1,41 @@ -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"); + const myClass = new MyClass(); + assert.strictEqual(myClass.addStudent('Not a student'), -1); + const student = new Student(); + for (let i = 0; i < 3; i++) { + const student = new Student(); + assert.strictEqual(myClass.addStudent(student), i); + } }); test("Test MyClass's getStudentById", () => { - // TODO - throw new Error("Test not implemented"); + const myClass = new MyClass(); + assert.strictEqual(myClass.getStudentById(-1), null); + for (let i = 0; i < 3; i++) { + const student = new Student(); + myClass.addStudent(student); + assert.strictEqual(myClass.getStudentById(i), student); + } + assert.strictEqual(myClass.getStudentById(3), null); }); test("Test Student's setName", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + student.setName(123); + assert.strictEqual(student.getName(), ''); + const name = "Pudding0803"; + student.setName(name); + assert.strictEqual(student.getName(), name); }); test("Test Student's getName", () => { - // TODO - throw new Error("Test not implemented"); -}); \ No newline at end of file + const student = new Student(); + assert.strictEqual(student.getName(), ''); + const name = "Pudding0803"; + student.setName(name); + assert.strictEqual(student.getName(), name); +});