Skip to content

Commit

Permalink
Merge pull request #49 from ian60509/312555022
Browse files Browse the repository at this point in the history
[LAB1] 312555022
  • Loading branch information
TaiYou-TW authored Mar 7, 2024
2 parents 2d41d26 + 66ad6cd commit 00de90b
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,47 @@ const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const cls = new(MyClass)
assert.strictEqual(-1, cls.addStudent(555)) //not the type of Student instance
assert.strictEqual(0, cls.addStudent(new Student())) //add 1 student , should return 0
assert.strictEqual(1, cls.addStudent(new Student()))
assert.strictEqual(2, cls.addStudent(new Student()))
});

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

assert.strictEqual(null, cls.getStudentById(-1) );
assert.strictEqual(null, cls.getStudentById(3) )
assert.strictEqual(s, cls.getStudentById(0) )

});

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

s.setName(123456)
assert.strictEqual(undefined, s.name)

const str = "Ian"
s.setName(str)
assert.strictEqual(str, s.name)

});

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

});

0 comments on commit 00de90b

Please sign in to comment.