@@ -2,22 +2,63 @@ const test = require('node:test');
2
2
const assert = require ( 'assert' ) ;
3
3
const { MyClass, Student } = require ( './main' ) ;
4
4
5
+
6
+
7
+
5
8
test ( "Test MyClass's addStudent" , ( ) => {
6
- // TODO
7
- throw new Error ( "Test not implemented" ) ;
9
+
10
+ const myClass = new MyClass ( ) ;
11
+ const sam = new Student ( ) ;
12
+ sam . setName ( 'Sam' )
13
+ const result = myClass . addStudent ( sam )
14
+ assert . strictEqual ( result , 0 )
15
+
16
+ const emptyStudent = myClass . addStudent ( 100.12 )
17
+ assert . strictEqual ( emptyStudent , - 1 )
18
+
8
19
} ) ;
9
20
10
21
test ( "Test MyClass's getStudentById" , ( ) => {
11
- // TODO
12
- throw new Error ( "Test not implemented" ) ;
22
+
23
+
24
+ const myClass = new MyClass ( ) ;
25
+ const sam = new Student ( ) ;
26
+ sam . setName ( "sam" )
27
+ myClass . addStudent ( sam )
28
+ const retrieveStudent = myClass . getStudentById ( 0 )
29
+ assert . strictEqual ( retrieveStudent , sam )
30
+
31
+ const retrieveEmpty1 = myClass . getStudentById ( - 1 )
32
+ assert . strictEqual ( retrieveEmpty1 , null )
33
+
34
+ const retrieveEmpty2 = myClass . getStudentById ( 1 )
35
+ assert . strictEqual ( retrieveEmpty2 , null )
36
+
13
37
} ) ;
14
38
15
39
test ( "Test Student's setName" , ( ) => {
16
- // TODO
17
- throw new Error ( "Test not implemented" ) ;
40
+
41
+
42
+ const student = new Student ( ) ;
43
+
44
+ student . setName ( 123 )
45
+ assert . strictEqual ( student . name , undefined )
46
+
47
+
48
+ student . setName ( "Sam" )
49
+ assert . strictEqual ( student . name , "Sam" )
50
+
18
51
} ) ;
19
52
20
53
test ( "Test Student's getName" , ( ) => {
21
- // TODO
22
- throw new Error ( "Test not implemented" ) ;
23
- } ) ;
54
+
55
+
56
+ const student = new Student ( ) ;
57
+ assert . strictEqual ( student . getName ( ) , '' )
58
+
59
+
60
+ student . setName ( "Sam" )
61
+ assert . strictEqual ( student . getName ( ) , "Sam" )
62
+
63
+
64
+ } ) ;
0 commit comments