Skip to content

Commit e9dae5e

Browse files
authored
Merge pull request #120 from sheng099/b132016
[LAB1] b132016
2 parents ba59f55 + 2b61616 commit e9dae5e

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

lab1/main_test.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,45 @@ const assert = require('assert');
33
const { MyClass, Student } = require('./main');
44

55
test("Test MyClass's addStudent", () => {
6-
// TODO
7-
throw new Error("Test not implemented");
6+
const myClass = new MyClass();
7+
const student = new Student("Aker");
8+
const student_same = new Student("Aker");
9+
const student_invalid = "Aker";
10+
// Check if invalid student is not added to the classroom
11+
assert.strictEqual(myClass.addStudent(student_invalid), -1);
12+
const id = myClass.addStudent(student);
13+
// Check if first student is added to the classroom
14+
assert.strictEqual(id, 0);
15+
assert.strictEqual(myClass.students.length, 1);
16+
const id_same = myClass.addStudent(student_same);
817
});
918

1019
test("Test MyClass's getStudentById", () => {
11-
// TODO
12-
throw new Error("Test not implemented");
20+
const myClass = new MyClass();
21+
const student = new Student("Aker");
22+
const id = myClass.addStudent(student);
23+
// Check if the student is retrieved by id
24+
assert.strictEqual(myClass.getStudentById(id), student);
25+
assert.strictEqual(myClass.getStudentById(-1), null);
26+
assert.strictEqual(myClass.getStudentById(1), null);
1327
});
1428

1529
test("Test Student's setName", () => {
16-
// TODO
17-
throw new Error("Test not implemented");
30+
const student = new Student("Aker");
31+
student.setName(123);
32+
assert.strictEqual(student.name, undefined);
33+
student.setName(null);
34+
assert.strictEqual(student.name, undefined);
35+
student.setName("");
36+
assert.strictEqual(student.name, "");
37+
student.setName("Aker");
38+
assert.strictEqual(student.name, "Aker");
1839
});
1940

2041
test("Test Student's getName", () => {
21-
// TODO
22-
throw new Error("Test not implemented");
23-
});
42+
const student = new Student("Aker");
43+
student.setName(undefined);
44+
assert.strictEqual(student.getName(), "");
45+
student.setName("Aker");
46+
assert.strictEqual(student.getName(), "Aker");
47+
});

0 commit comments

Comments
 (0)