Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Loading