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] 312551008 #6

Merged
merged 4 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
48 changes: 40 additions & 8 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,53 @@ 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();
// if student is not an instance of Student, return -1
assert.strictEqual(myClass.addStudent({}), -1);

// normal case
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);
});
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
// if id is less than 0, return null
assert.strictEqual(myClass.getStudentById(-1), null);

// normal case
const names = ['John', 'Jane', 'Doe', 'Smith'];
names.forEach(name => {
const student = new Student();
student.setName(name);
const newStudentId = myClass.addStudent(student);
const newStudent = myClass.getStudentById(newStudentId);
assert.strictEqual(student, newStudent);
});
// if id is greater than or equal to the length of students, return null
assert.strictEqual(myClass.getStudentById(names.length), 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');
// Test if setName accepts only string
student.setName(123);
assert.strictEqual(student.getName(), 'John');
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
// Test if getName returns empty string if name is undefined
assert.strictEqual(student.getName(), '');
// Test if getName returns the name set by setName
student.setName('John');
assert.strictEqual(student.getName(), 'John');
});
Loading