Skip to content

Commit

Permalink
Merge pull request #63 from XYFC128/110550159
Browse files Browse the repository at this point in the history
[LAB1] 110550159
  • Loading branch information
TaiYou-TW authored Mar 7, 2024
2 parents 2d41d26 + 97cb214 commit 0ff5f2e
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@ 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();
assert.strictEqual(myClass.addStudent(new Student()), 0);
assert.strictEqual(myClass.addStudent(''), -1);
});

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

assert.strictEqual(myClass.getStudentById(1).getName(), 'Jane');
assert.strictEqual(myClass.getStudentById(-1), null);
assert.strictEqual(myClass.getStudentById(4), null);
});

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

const student2 = new Student();
student2.setName(123);
assert.strictEqual(student2.name, undefined);
});

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

const student2 = new Student();
assert.strictEqual(student2.getName(), '');
});

0 comments on commit 0ff5f2e

Please sign in to comment.