Skip to content

Commit 2d256f4

Browse files
authored
Merge branch '510558013' into lab7
2 parents 450f1b4 + 2b1b421 commit 2d256f4

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

lab1/main_test.js

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,70 @@ test("Test MyClass's addStudent", () => {
66
const myClass = new MyClass();
77
const student = new Student();
88
student.setName('Alice');
9-
9+
1010
const result = myClass.addStudent(student);
11-
11+
1212
assert.strictEqual(result, 0);
1313
assert.strictEqual(myClass.students.length, 1);
1414
});
1515

16-
test("Test MyClass's getStudentById", () => {
16+
test("Test MyClass's addStudent with invalid student", () => {
17+
const myClass = new MyClass();
18+
const result = myClass.addStudent({});
19+
assert.strictEqual(result, -1);
20+
assert.strictEqual(myClass.students.length, 0);
21+
});
22+
23+
test("Test MyClass's getStudentById with valid id", () => {
1724
const myClass = new MyClass();
1825
const student = new Student();
1926
student.setName('Bob');
2027
myClass.addStudent(student);
21-
28+
2229
const result = myClass.getStudentById(0);
23-
30+
2431
assert.strictEqual(result, student);
2532
});
2633

34+
test("Test MyClass's getStudentById with invalid id", () => {
35+
const myClass = new MyClass();
36+
const result = myClass.getStudentById(0);
37+
assert.strictEqual(result, null);
38+
});
39+
40+
test("Test MyClass's getStudentById with negative id", () => {
41+
const myClass = new MyClass();
42+
const result = myClass.getStudentById(-1);
43+
assert.strictEqual(result, null);
44+
});
45+
46+
test("Test MyClass's getStudentById with id beyond length", () => {
47+
const myClass = new MyClass();
48+
const result = myClass.getStudentById(1);
49+
assert.strictEqual(result, null);
50+
});
51+
2752
test("Test Student's setName", () => {
2853
const student = new Student();
2954
student.setName('John');
30-
3155
assert.strictEqual(student.name, 'John');
3256
});
3357

34-
test("Test Student's getName", () => {
58+
test("Test Student's setName with invalid input", () => {
59+
const student = new Student();
60+
student.setName(123); // Passing invalid input
61+
assert.strictEqual(student.name, undefined);
62+
});
63+
64+
test("Test Student's getName when name is set", () => {
3565
const student = new Student();
3666
student.setName('Alice');
37-
3867
const name = student.getName();
39-
4068
assert.strictEqual(name, 'Alice');
4169
});
42-
const test = require('node:test');
43-
const assert = require('assert');
44-
const { MyClass, Student } = require('./main');
45-
46-
test("Test MyClass's addStudent", () => {
47-
// TODO
48-
throw new Error("Test not implemented");
49-
});
50-
51-
test("Test MyClass's getStudentById", () => {
52-
// TODO
53-
throw new Error("Test not implemented");
54-
});
55-
56-
test("Test Student's setName", () => {
57-
// TODO
58-
throw new Error("Test not implemented");
59-
});
6070

61-
test("Test Student's getName", () => {
62-
// TODO
63-
throw new Error("Test not implemented");
71+
test("Test Student's getName when name is not set", () => {
72+
const student = new Student();
73+
const name = student.getName();
74+
assert.strictEqual(name, '');
6475
});

0 commit comments

Comments
 (0)