Skip to content
Merged
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
56 changes: 48 additions & 8 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,62 @@ const test = require('node:test');
const assert = require('assert');
const { MyClass, Student } = require('./main');

// const myClass = new MyClass();
// const names = ['John', 'Jane', 'Doe', 'Smith'];
// names.forEach(name => {
// const student = new Student();
// student.setName(name);
// const newStudentId = myClass.addStudent(student);
// const newStudentName = myClass.getStudentById(newStudentId).getName();
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName);
// });

Comment on lines +5 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not leave a bunch of comment code in your commit.
I will merge the PR first, but it's better to remove them next time.

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const names = ['John', 'Jane', 'Doe', 'Smith'];
for (let i = 0; i < names.length; i++) {
const student = new Student();
const validStudentId = myClass.addStudent(student);
assert.strictEqual(validStudentId, i);
}

const invalidStudentId = myClass.addStudent({});
assert.strictEqual(invalidStudentId, -1);
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const names = ['John', 'Jane', 'Doe', 'Smith'];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
const newStudentName = myClass.getStudentById(newStudentId).getName();
assert.strictEqual(newStudentName, name);
});

const nonExistingStudent = myClass.getStudentById(4);
assert.strictEqual(nonExistingStudent, null);

const nonExistingStudent_2 = myClass.getStudentById(-1);
assert.strictEqual(nonExistingStudent_2, null);
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();

student.setName('John');
assert.strictEqual(student.getName(), 'John');

student.setName(123);
assert.strictEqual(student.getName(), 'John');
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();

assert.strictEqual(student.getName(), '');

student.setName('John');
assert.strictEqual(student.getName(), 'John');
});