Skip to content

Commit 7a26e96

Browse files
authored
Update main_test.js
1 parent dcd7054 commit 7a26e96

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

lab1/main_test.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,31 @@ const test = require('node:test');
22
const assert = require('assert');
33
const { MyClass, Student } = require('./main');
44

5-
test("Test MyClass's addStudent method", async (t) => {
5+
test("Test MyClass's addStudent", async (t) => {
66
const myClass = new MyClass();
77
const student = new Student();
8-
student.setName("John");
8+
student.setName("Test Student");
99
const index = myClass.addStudent(student);
10-
assert.strictEqual(index, 0);
10+
assert.strictEqual(index, 0, "addStudent should return index 0 for the first student");
1111
});
1212

13-
test("Test MyClass's getStudentById method", async (t) => {
13+
test("Test MyClass's getStudentById", async (t) => {
1414
const myClass = new MyClass();
1515
const student = new Student();
16-
student.setName("Jane");
16+
student.setName("Test Student");
1717
const index = myClass.addStudent(student);
1818
const fetchedStudent = myClass.getStudentById(index);
19-
assert.strictEqual(fetchedStudent.getName(), "Jane");
19+
assert.strictEqual(fetchedStudent.getName(), "Test Student", "getStudentById should return the correct student by id");
2020
});
2121

22-
test("Test Student's setName and getName methods", async (t) => {
22+
test("Test Student's setName", async (t) => {
2323
const student = new Student();
24-
student.setName("Doe");
25-
assert.strictEqual(student.getName(), "Doe");
24+
student.setName("Another Student");
25+
assert.strictEqual(student.getName(), "Another Student", "setName should successfully set the student's name");
2626
});
2727

28-
test("Test handling non-Student instance in addStudent", async (t) => {
29-
const myClass = new MyClass();
30-
const notAStudent = {};
31-
const index = myClass.addStudent(notAStudent);
32-
assert.strictEqual(index, -1);
33-
});
34-
35-
test("Test getStudentById with invalid id", async (t) => {
36-
const myClass = new MyClass();
28+
test("Test Student's getName", async (t) => {
3729
const student = new Student();
38-
student.setName("Smith");
39-
myClass.addStudent(student);
40-
const invalidId = -1;
41-
const fetchedStudent = myClass.getStudentById(invalidId);
42-
assert.strictEqual(fetchedStudent, null);
30+
student.setName("Another Test Student");
31+
assert.strictEqual(student.getName(), "Another Test Student", "getName should return the name of the student");
4332
});

0 commit comments

Comments
 (0)