@@ -2,42 +2,31 @@ const test = require('node:test');
2
2
const assert = require ( 'assert' ) ;
3
3
const { MyClass, Student } = require ( './main' ) ;
4
4
5
- test ( "Test MyClass's addStudent method " , async ( t ) => {
5
+ test ( "Test MyClass's addStudent" , async ( t ) => {
6
6
const myClass = new MyClass ( ) ;
7
7
const student = new Student ( ) ;
8
- student . setName ( "John " ) ;
8
+ student . setName ( "Test Student " ) ;
9
9
const index = myClass . addStudent ( student ) ;
10
- assert . strictEqual ( index , 0 ) ;
10
+ assert . strictEqual ( index , 0 , "addStudent should return index 0 for the first student" ) ;
11
11
} ) ;
12
12
13
- test ( "Test MyClass's getStudentById method " , async ( t ) => {
13
+ test ( "Test MyClass's getStudentById" , async ( t ) => {
14
14
const myClass = new MyClass ( ) ;
15
15
const student = new Student ( ) ;
16
- student . setName ( "Jane " ) ;
16
+ student . setName ( "Test Student " ) ;
17
17
const index = myClass . addStudent ( student ) ;
18
18
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" ) ;
20
20
} ) ;
21
21
22
- test ( "Test Student's setName and getName methods " , async ( t ) => {
22
+ test ( "Test Student's setName" , async ( t ) => {
23
23
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" ) ;
26
26
} ) ;
27
27
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 ) => {
37
29
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" ) ;
43
32
} ) ;
0 commit comments