Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LAB1] 312551074 #28

Merged
merged 2 commits into from
Mar 7, 2024
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
41 changes: 37 additions & 4 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,53 @@ const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClassTest1 = new MyClass();
const studentTest1 = new Student();

// valid student
assert.strictEqual(myClassTest1.addStudent(studentTest1), 0);

// invalid student
assert.strictEqual(myClassTest1.addStudent(123), -1);
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClassTest2 = new MyClass();
const studentTest2 = new Student();
myClassTest2.addStudent(studentTest2);

// valid id
assert.strictEqual(myClassTest2.getStudentById(0), studentTest2);

// invalid id
assert.strictEqual(myClassTest2.getStudentById(-1), null);
assert.strictEqual(myClassTest2.getStudentById(myClassTest2.students.length), null);
});

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

//invalid name
myStudentTest3.setName(312551074);
assert.strictEqual(myStudentTest3.name, undefined);

// valid name
const nameTest3 = 'James';
myStudentTest3.setName(nameTest3);
assert.strictEqual(myStudentTest3.name, nameTest3);
});

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

// undefined name
assert.strictEqual(myStudentTest4.getName(), '');

// valid name
const nameTest4 = 'James';
myStudentTest4.setName(nameTest4);
assert.strictEqual(myStudentTest4.getName(), nameTest4);
});
Loading