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] 312553016 #29

Merged
merged 1 commit 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
55 changes: 51 additions & 4 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,67 @@ const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const bob = new Student();
bob.setName("Bob");

const alice = new Student();
alice.setName("Alice");

const notStudentId = myClass.addStudent(0);
assert.strictEqual(notStudentId, -1);


const bobStudentId = myClass.addStudent(bob);
assert.strictEqual(bobStudentId, 0);
assert.strictEqual(myClass.students.length, 1);


const aliceStudentId = myClass.addStudent(bob);
assert.strictEqual(aliceStudentId, 1);
assert.strictEqual(myClass.students.length, 2);

});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const bob = new Student();
bob.setName("Bob");

const alice = new Student();
alice.setName("Alice");

const bobStudentId = myClass.addStudent(bob);
const aliceStudentId = myClass.addStudent(alice);

const nonExistentStudent = myClass.getStudentById(99);

assert.strictEqual(myClass.getStudentById(bobStudentId).getName(), "Bob");
assert.strictEqual(myClass.getStudentById(aliceStudentId).getName(), "Alice");
assert.strictEqual(nonExistentStudent, null);
});

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

student.setName("Bob");
assert.strictEqual(student.getName(), "Bob");

student.setName(0);
assert.strictEqual(student.getName(), "Bob");

});

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

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

student.setName("Bob");

assert.strictEqual(student.getName(), "Bob");

});
Loading