Skip to content

[LAB1] 510558017 #17

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

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions lab1/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class Student {
}
}

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

module.exports = { MyClass, Student };
module.exports = { MyClass, Student };
36 changes: 27 additions & 9 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,39 @@ 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();
const student = new Student();
student.setName("John");
const index = myClass.addStudent(student);
assert.strictEqual(index, 0, "addStudent should return index 0 for the first student");
const notAStudent = {};
const indexForNotAStudent = myClass.addStudent(notAStudent);
assert.strictEqual(indexForNotAStudent, -1, "addStudent should return -1 when adding a non-Student instance");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const student = new Student();
student.setName("Jane");
const index = myClass.addStudent(student);
const fetchedStudent = myClass.getStudentById(index);
assert.strictEqual(fetchedStudent.getName(), "Jane", "getStudentById should retrieve the student with the correct name");
const invalidFetchedStudent = myClass.getStudentById(-1);
assert.strictEqual(invalidFetchedStudent, null, "getStudentById should return null for an invalid id");
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
student.setName("Doe");
assert.strictEqual(student.name, "Doe", "setName should correctly set the student's name");
student.setName(123);
assert.strictEqual(student.name, "Doe", "setName should not set name when the input is not a string");
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
});
const student = new Student();
student.setName("Smith");
assert.strictEqual(student.getName(), "Smith", "getName should return the correct name");
const newStudent = new Student();
assert.strictEqual(newStudent.getName(), '', "getName should return an empty string for a student without a name");
});