Skip to content

Commit

Permalink
Merge pull request #44 from zbtion/b122521
Browse files Browse the repository at this point in the history
[LAB1] b122521
  • Loading branch information
TaiYou-TW authored Mar 7, 2024
2 parents 2d41d26 + e449f81 commit 43567a7
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,48 @@ const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const names = ["John", "Doe", "Jane", "Doe"];
names.forEach(name => {
const student = new Student();
student.setName(name);
assert.strictEqual(myClass.addStudent(student), myClass.students.length - 1);
});
assert.strictEqual(myClass.addStudent({}), -1);
//throw new Error("Test not implemented");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const names = ["John", "Doe", "Jane", "Doe"];
names.forEach(name => {
const student = new Student();
student.setName(name);
myClass.addStudent(student);
assert.strictEqual(myClass.getStudentById(myClass.students.length - 1).getName(), name);
});
assert.strictEqual(myClass.getStudentById(-1), null);
assert.strictEqual(myClass.getStudentById(myClass.students.length), null);
//throw new Error("Test not implemented");
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
student.setName("John");
assert.strictEqual(student.getName(), "John");
student.setName(123);
assert.strictEqual(student.getName(), "John");
//throw new Error("Test not implemented");
});

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

//throw new Error("Test not implemented");
});

0 comments on commit 43567a7

Please sign in to comment.