Skip to content

Commit

Permalink
312553018 lab1 coverage 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
Alextien40816291 committed Feb 29, 2024
1 parent 4f22b9d commit e5673ea
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,51 @@ 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('Alex');

assert.strictEqual(myClass.addStudent(student), 0);
assert.strictEqual(myClass.students.length, 1);
assert.strictEqual(myClass.students[0], student);
// throw new Error("Test not implemented");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const student1 = new Student();
student1.setName("Alex");
const student2 = new Student();
student2.setName("Albert");
myClass.addStudent(student1);
myClass.addStudent(student2);

const retrieved_student1 = myClass.getStudentById(0);
const retrieved_student2 = myClass.getStudentById(1);
assert.strictEqual(retrieved_student1.getName(), "Alex");
assert.strictEqual(retrieved_student2.getName(), "Albert");
// throw new Error("Test not implemented");
});

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

student.setName("Alex");

assert.strictEqual(student.getName(), "Alex");
// throw new Error("Test not implemented");
});

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

student.setName("Alex");

const name = student.getName();

assert.strictEqual(name, "Alex");
// throw new Error("Test not implemented");
});

0 comments on commit e5673ea

Please sign in to comment.