diff --git a/lab1/main_test.js b/lab1/main_test.js index 74a716b..a6d33a6 100644 --- a/lab1/main_test.js +++ b/lab1/main_test.js @@ -3,21 +3,47 @@ const assert = require('assert'); const { MyClass, Student } = require('./main'); test("Test MyClass's addStudent", () => { - // TODO - throw new Error("Test not implemented"); + const Class = new MyClass(); + const student = new Student(); + const id = Class.addStudent(student); + assert.strictEqual(id, 0); + assert.strictEqual(Class.addStudent({}), -1); }); test("Test MyClass's getStudentById", () => { - // TODO - throw new Error("Test not implemented"); + const Class = new MyClass(); + const student = new Student(); + student.setName("John"); + + const id = Class.addStudent(student); + const StudentID = Class.getStudentById(id); + + assert.strictEqual(StudentID.getName(), "John"); + assert.strictEqual(Class.getStudentById(-1), null); + assert.strictEqual(Class.getStudentById(999), null); + }); test("Test Student's setName", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + student.setName(123); + assert.strictEqual(student.getName(), ""); + + student.setName("John"); + const StudentName = student.getName(); + + + assert.strictEqual(StudentName, "John"); + }); test("Test Student's getName", () => { - // TODO - throw new Error("Test not implemented"); + const student = new Student(); + + // "" in default + assert.strictEqual(student.getName(), ""); + + student.setName("John"); + const StudentName = student.getName(); + assert.strictEqual(StudentName, "John"); }); \ No newline at end of file