Skip to content

Commit 54ceac4

Browse files
authored
Merge pull request #70 from sss28072637/313560007
[LAB1] 313560007
2 parents c817c98 + 6b4bb7b commit 54ceac4

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

lab1/main_test.js

+37-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
const test = require('node:test');
22
const assert = require('assert');
3-
const { MyClass, Student } = require('./main');
3+
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+
10+
const newStudentId = myClass.addStudent(student);
11+
12+
assert.strictEqual(newStudentId, 0);
13+
assert.strictEqual(myClass.addStudent({}), -1);
14+
15+
// throw new Error("Test not implemented");
816
});
917

1018
test("Test MyClass's getStudentById", () => {
1119
// TODO
12-
throw new Error("Test not implemented");
20+
const myClass = new MyClass();
21+
const student = new Student();
22+
student.setName("John");
23+
24+
const studentId = myClass.addStudent(student);
25+
26+
const foundStudent = myClass.getStudentById(studentId);
27+
assert.strictEqual(foundStudent, student);
28+
29+
assert.strictEqual(myClass.getStudentById(-5), null)
30+
assert.strictEqual(myClass.getStudentById(123), null)
31+
// throw new Error("Test not implemented");
1332
});
1433

1534
test("Test Student's setName", () => {
1635
// TODO
17-
throw new Error("Test not implemented");
36+
const student = new Student();
37+
38+
student.setName("Mike");
39+
assert.strictEqual(student.getName(), "Mike");
40+
41+
student.setName(222);
42+
assert.strictEqual(student.getName(), "Mike");
43+
// throw new Error("Test not implemented");
1844
});
1945

2046
test("Test Student's getName", () => {
2147
// TODO
22-
throw new Error("Test not implemented");
48+
const student = new Student();
49+
50+
assert.strictEqual(student.getName(), "");
51+
52+
student.setName("John");
53+
assert.strictEqual(student.getName(), "John");
54+
// throw new Error("Test not implemented");
2355
});

0 commit comments

Comments
 (0)