Skip to content

Commit 57dd5c7

Browse files
committed
Merge branch '312553027'
2 parents 0430ce4 + 2c738d5 commit 57dd5c7

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

lab1/main_test.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,62 @@
11
const test = require('node:test');
22
const assert = require('assert');
33
const { MyClass, Student } = require('./main');
4+
const exp = require('constants');
45

56
test("Test MyClass's addStudent", () => {
67
// TODO
7-
throw new Error("Test not implemented");
8+
const myClass = new MyClass();
9+
const student = new Student();
10+
const newStudentId = myClass.addStudent(student);
11+
assert.strictEqual(newStudentId, 0);
12+
assert.strictEqual(myClass.students.length, 1);
13+
assert.strictEqual(myClass.students[0], student);
14+
15+
const newStudentId2 = myClass.addStudent('not a student');
16+
assert.strictEqual(newStudentId2, -1);
17+
18+
// throw new Error("Test not implemented");
19+
820
});
921

1022
test("Test MyClass's getStudentById", () => {
1123
// TODO
12-
throw new Error("Test not implemented");
24+
const myClass = new MyClass();
25+
const student = new Student();
26+
myClass.addStudent(student);
27+
const studentById = myClass.getStudentById(0);
28+
assert.strictEqual(studentById, student);
29+
30+
const studentById2 = myClass.getStudentById(-1);
31+
assert.strictEqual(studentById2, null);
32+
const studentById3 = myClass.getStudentById(1);
33+
assert.strictEqual(studentById3, null);
34+
35+
// throw new Error("Test not implemented");
1336
});
1437

1538
test("Test Student's setName", () => {
1639
// TODO
17-
throw new Error("Test not implemented");
40+
const student = new Student();
41+
student.setName("John");
42+
assert.strictEqual(student.getName(), "John");
43+
44+
const student2 = new Student();
45+
student2.setName(123);
46+
assert.strictEqual(student.getName(), "John");
47+
48+
// throw new Error("Test not implemented");
1849
});
1950

2051
test("Test Student's getName", () => {
2152
// TODO
22-
throw new Error("Test not implemented");
53+
const student = new Student();
54+
student.setName("John");
55+
assert.strictEqual(student.getName(), "John");
56+
57+
const student2 = new Student();
58+
student2.setName(123);
59+
assert.strictEqual(student2.getName(), '');
60+
61+
// throw new Error("Test not implemented");
2362
});

0 commit comments

Comments
 (0)