Skip to content

Commit a89392e

Browse files
authored
Merge pull request #21 from Deron5566/312555020
[LAB1] 312555020
2 parents 2d41d26 + 050fe3c commit a89392e

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

lab1/main_test.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,35 @@ 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();
8+
student.setName('John');
9+
assert.strictEqual(myClass.addStudent(student), 0);
10+
assert.strictEqual(myClass.addStudent(123), -1);
811
});
912

1013
test("Test MyClass's getStudentById", () => {
11-
// TODO
12-
throw new Error("Test not implemented");
14+
const myClass = new MyClass();
15+
const student = new Student();
16+
student.setName('John');
17+
const newStudentId = myClass.addStudent(student);
18+
assert.strictEqual(myClass.getStudentById(newStudentId), student);
19+
assert.strictEqual(myClass.getStudentById(-2), null);
20+
assert.strictEqual(myClass.getStudentById(2), null);
1321
});
1422

1523
test("Test Student's setName", () => {
16-
// TODO
17-
throw new Error("Test not implemented");
24+
const myClass = new MyClass();
25+
const student = new Student();
26+
student.setName('John');
27+
assert.strictEqual(student.name, 'John');
28+
student.setName(123);
1829
});
1930

2031
test("Test Student's getName", () => {
21-
// TODO
22-
throw new Error("Test not implemented");
32+
const myClass = new MyClass();
33+
const student = new Student();
34+
assert.strictEqual(student.getName(), '');
35+
student.setName('John');
36+
assert.strictEqual(student.getName(), 'John');
2337
});

0 commit comments

Comments
 (0)