Skip to content

Commit

Permalink
fix unit test error
Browse files Browse the repository at this point in the history
  • Loading branch information
ming-hsien committed Mar 7, 2024
1 parent db21add commit 896753d
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,21 @@ const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
//TODO
const a = new MyClass();
assert.strictEqual(myclass.addStudent(), 0);
assert.strictEqual(myclass.addStudent(), 1);
assert.strictEqual("Return -1", -1);
throw new Error("Test not implemented");
const myclass = new MyClass();
const student = new Student();
assert.strictEqual(myclass.addStudent(""), -1);
assert.strictEqual(myclass.addStudent(student), 0);
});

test("Test MyClass's getStudentById", () => {
// TODO
const myclass = new MyClass();
assert.strictEqual(myclass.getStudentById(-1), null);
assert.strictEqual(myclass.getStudentById(myclass.students.length), null);

const student1 = new Student();
student1.setName("std1");
myclass.addStudent(student1);

const student2 = new Student();
student2.setName("std2");
myclass.addStudent(student2);

for (i = 0; i < myclass.students.length(); i++) {
assert.strictEqual(myclass.getStudentById(i), myclass.students[i]);
}
assert.strictEqual(myclass.getStudentById(-1), null);
assert.strictEqual(myclass.getStudentById(100), null);
assert.strictEqual(myclass.getStudentById(0), student1);

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

test("Test Student's setName", () => {
Expand All @@ -38,7 +27,6 @@ test("Test Student's setName", () => {
assert.strictEqual(student.name, undefined);
student.setName("std1");
assert.strictEqual(student.name, "std1");
throw new Error("Test not implemented");
});

test("Test Student's getName", () => {
Expand All @@ -47,5 +35,4 @@ test("Test Student's getName", () => {
assert.strictEqual(student.getName(), '');
student.setName("std1");
assert.strictEqual(student.getName(), "std1");
throw new Error("Test not implemented");
});

0 comments on commit 896753d

Please sign in to comment.