-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmain_test.js
49 lines (36 loc) · 1.29 KB
/
main_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const test = require('node:test');
const assert = require('assert');
const { MyClass, Student } = require('./main');
test("Test MyClass's addStudent", () => {
const Class = new MyClass();
const student = new Student();
const id = Class.addStudent(student);
assert.strictEqual(id, 0);
assert.strictEqual(Class.addStudent({}), -1);
});
test("Test MyClass's getStudentById", () => {
const Class = new MyClass();
const student = new Student();
student.setName("John");
const id = Class.addStudent(student);
const StudentID = Class.getStudentById(id);
assert.strictEqual(StudentID.getName(), "John");
assert.strictEqual(Class.getStudentById(-1), null);
assert.strictEqual(Class.getStudentById(999), null);
});
test("Test Student's setName", () => {
const student = new Student();
student.setName(123);
assert.strictEqual(student.getName(), "");
student.setName("John");
const StudentName = student.getName();
assert.strictEqual(StudentName, "John");
});
test("Test Student's getName", () => {
const student = new Student();
// "" in default
assert.strictEqual(student.getName(), "");
student.setName("John");
const StudentName = student.getName();
assert.strictEqual(StudentName, "John");
});