Skip to content

Commit 2c738d5

Browse files
committed
complete lab1/ file at local
1 parent 5b5a027 commit 2c738d5

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

lab1/main_test.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,51 @@ test("Test MyClass's addStudent", () => {
1212
assert.strictEqual(myClass.students.length, 1);
1313
assert.strictEqual(myClass.students[0], student);
1414

15+
const newStudentId2 = myClass.addStudent('not a student');
16+
assert.strictEqual(newStudentId2, -1);
17+
1518
// throw new Error("Test not implemented");
1619

1720
});
1821

1922
test("Test MyClass's getStudentById", () => {
2023
// TODO
21-
throw new Error("Test not implemented");
24+
const myClass = new MyClass();
25+
const student = new Student();
26+
myClass.addStudent(student);
27+
const studentById = myClass.getStudentById(0);
28+
assert.strictEqual(studentById, student);
29+
30+
const studentById2 = myClass.getStudentById(-1);
31+
assert.strictEqual(studentById2, null);
32+
const studentById3 = myClass.getStudentById(1);
33+
assert.strictEqual(studentById3, null);
34+
35+
// throw new Error("Test not implemented");
2236
});
2337

2438
test("Test Student's setName", () => {
2539
// TODO
26-
throw new Error("Test not implemented");
40+
const student = new Student();
41+
student.setName("John");
42+
assert.strictEqual(student.getName(), "John");
43+
44+
const student2 = new Student();
45+
student2.setName(123);
46+
assert.strictEqual(student.getName(), "John");
47+
48+
// throw new Error("Test not implemented");
2749
});
2850

2951
test("Test Student's getName", () => {
3052
// TODO
31-
throw new Error("Test not implemented");
53+
const student = new Student();
54+
student.setName("John");
55+
assert.strictEqual(student.getName(), "John");
56+
57+
const student2 = new Student();
58+
student2.setName(123);
59+
assert.strictEqual(student2.getName(), '');
60+
61+
// throw new Error("Test not implemented");
3262
});

0 commit comments

Comments
 (0)