Skip to content

Commit 6cc3dcb

Browse files
committed
Fix failing tests in main_test.js
1 parent 7757037 commit 6cc3dcb

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

lab1/main_test.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,38 @@ const { MyClass, Student } = require('./main');
44

55
test("Test MyClass's addStudent", () => {
66
// TODO
7-
throw new Error("Test not implemented");
7+
const myClass = new MyClass();
8+
const student = new Student("John");
9+
myClass.addStudent(student);
10+
assert.strictEqual(myClass.students.length, 1);
11+
assert.strictEqual(myClass.students[0], student);
12+
//throw new Error("Test not implemented");
813
});
914

1015
test("Test MyClass's getStudentById", () => {
1116
// TODO
12-
throw new Error("Test not implemented");
17+
const myClass = new MyClass();
18+
const student1 = new Student("John");
19+
const student2 = new Student("Alice");
20+
const student3 = new Student("Bob");
21+
myClass.addStudent(student1);
22+
myClass.addStudent(student2);
23+
myClass.addStudent(student3);
24+
const foundStudent = myClass.getStudentById(student2.id);
25+
assert.strictEqual(foundStudent, student2);
26+
//throw new Error("Test not implemented");
1327
});
1428

1529
test("Test Student's setName", () => {
1630
// TODO
17-
throw new Error("Test not implemented");
31+
const student = new Student("John");
32+
student.setName("Alice");
33+
assert.strictEqual(student.getName(), "Alice");
1834
});
1935

2036
test("Test Student's getName", () => {
2137
// TODO
22-
throw new Error("Test not implemented");
23-
});
38+
const student = new Student("John");
39+
assert.strictEqual(student.getName(), "John");
40+
//throw new Error("Test not implemented");
41+
});

0 commit comments

Comments
 (0)