Skip to content

Commit

Permalink
Merge pull request #23 from HanHongChen/312551178
Browse files Browse the repository at this point in the history
[LAB1] 312551178
  • Loading branch information
TaiYou-TW authored Mar 7, 2024
2 parents 2d41d26 + 8cf5003 commit 60d8afe
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,46 @@ const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
//check fail case
assert.strictEqual(myClass.addStudent({}), -1);
//check success case
assert.strictEqual(myClass.addStudent(new Student), 0);

});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
assert.strictEqual(myClass.getStudentById(-1), null);
assert.strictEqual(myClass.getStudentById(10), null);
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(myClass.getStudentById(0).getName(), 'John');
assert.strictEqual(myClass.getStudentById(1).getName(), 'Jane');
assert.strictEqual(myClass.getStudentById(2).getName(), 'Doe');
assert.strictEqual(myClass.getStudentById(3).getName(), 'Smith');
});

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

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

0 comments on commit 60d8afe

Please sign in to comment.