Skip to content

Commit 7e3f807

Browse files
committed
lab1 finish
1 parent 01554ce commit 7e3f807

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

lab1/main_test.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,42 @@ 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();
9+
student.setName('John');
10+
assert.strictEqual(myClass.addStudent(student), 0);
11+
assert.strictEqual(myClass.addStudent(123), -1);
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 student = new Student();
19+
student.setName('John');
20+
const newStudentId = myClass.addStudent(student);
21+
assert.strictEqual(myClass.getStudentById(newStudentId), student);
22+
assert.strictEqual(myClass.getStudentById(-1), null);
23+
assert.strictEqual(myClass.getStudentById(2), null);
24+
// throw new Error("Test not implemented");
1325
});
1426

1527
test("Test Student's setName", () => {
1628
// TODO
17-
throw new Error("Test not implemented");
29+
const myClass = new MyClass();
30+
const student = new Student();
31+
student.setName('John');
32+
assert.strictEqual(student.name, 'John');
33+
student.setName(123);
34+
// throw new Error("Test not implemented");
1835
});
1936

2037
test("Test Student's getName", () => {
2138
// TODO
22-
throw new Error("Test not implemented");
39+
const myClass = new MyClass();
40+
const student = new Student();
41+
assert.strictEqual(student.getName(), '');
42+
student.setName('John');
43+
assert.strictEqual(student.getName(), 'John');
44+
// throw new Error("Test not implemented");
2345
});

0 commit comments

Comments
 (0)