Skip to content

Commit

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

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
myClass = new MyClass();
student = new Student();
nonStudent = new Object();

assert.strictEqual(myClass.addStudent(student), 0);
assert.strictEqual(myClass.addStudent(nonStudent), -1);
assert.strictEqual(myClass.addStudent(student), 1);
assert.strictEqual(myClass.addStudent(nonStudent), -1);

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

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
myClass = new MyClass();

student1 = new Student();
myClass.addStudent(student1);

student2 = new Student();
myClass.addStudent(student2);

student3 = new Student();
myClass.addStudent(student3);

assert.strictEqual(myClass.getStudentById(0), student1);
assert.strictEqual(myClass.getStudentById(3), null);
assert.strictEqual(myClass.getStudentById(2), student3);
assert.strictEqual(myClass.getStudentById(1), student2);
assert.strictEqual(myClass.getStudentById(-1), null);

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

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

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

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

student1 = new Student();
assert.strictEqual(student1.getName(), '');
student1.setName(123);
assert.strictEqual(student1.getName(), '');
student1.setName(1.345);
assert.strictEqual(student1.getName(), '');
student1.setName('John');
assert.strictEqual(student1.getName(), 'John');
student1.setName(123);
assert.strictEqual(student1.getName(), 'John');
student1.setName(1.345);
assert.strictEqual(student1.getName(), 'John');

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

0 comments on commit 1dbb299

Please sign in to comment.