1
- const test = require ( ' node:test' ) ;
2
- const assert = require ( ' assert' ) ;
3
- const { MyClass, Student } = require ( ' ./main' ) ;
1
+ const test = require ( " node:test" ) ;
2
+ const assert = require ( " assert" ) ;
3
+ const { MyClass, Student } = require ( " ./main" ) ;
4
4
5
5
test ( "Test MyClass's addStudent" , ( ) => {
6
- // TODO
7
- throw new Error ( "Test not implemented" ) ;
6
+ const myClass = new MyClass ( ) ;
7
+ assert . strictEqual ( myClass . addStudent ( 'Not a student' ) , - 1 ) ;
8
+ const student = new Student ( ) ;
9
+ for ( let i = 0 ; i < 3 ; i ++ ) {
10
+ const student = new Student ( ) ;
11
+ assert . strictEqual ( myClass . addStudent ( student ) , i ) ;
12
+ }
8
13
} ) ;
9
14
10
15
test ( "Test MyClass's getStudentById" , ( ) => {
11
- // TODO
12
- throw new Error ( "Test not implemented" ) ;
16
+ const myClass = new MyClass ( ) ;
17
+ assert . strictEqual ( myClass . getStudentById ( - 1 ) , null ) ;
18
+ for ( let i = 0 ; i < 3 ; i ++ ) {
19
+ const student = new Student ( ) ;
20
+ myClass . addStudent ( student ) ;
21
+ assert . strictEqual ( myClass . getStudentById ( i ) , student ) ;
22
+ }
23
+ assert . strictEqual ( myClass . getStudentById ( 3 ) , null ) ;
13
24
} ) ;
14
25
15
26
test ( "Test Student's setName" , ( ) => {
16
- // TODO
17
- throw new Error ( "Test not implemented" ) ;
27
+ const student = new Student ( ) ;
28
+ student . setName ( 123 ) ;
29
+ assert . strictEqual ( student . getName ( ) , '' ) ;
30
+ const name = "Pudding0803" ;
31
+ student . setName ( name ) ;
32
+ assert . strictEqual ( student . getName ( ) , name ) ;
18
33
} ) ;
19
34
20
35
test ( "Test Student's getName" , ( ) => {
21
- // TODO
22
- throw new Error ( "Test not implemented" ) ;
23
- } ) ;
36
+ const student = new Student ( ) ;
37
+ assert . strictEqual ( student . getName ( ) , '' ) ;
38
+ const name = "Pudding0803" ;
39
+ student . setName ( name ) ;
40
+ assert . strictEqual ( student . getName ( ) , name ) ;
41
+ } ) ;
0 commit comments