@@ -3,21 +3,35 @@ const assert = require('assert');
3
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
+ const student = new Student ( ) ;
8
+ student . setName ( 'John' ) ;
9
+ assert . strictEqual ( myClass . addStudent ( student ) , 0 ) ;
10
+ assert . strictEqual ( myClass . addStudent ( 123 ) , - 1 ) ;
8
11
} ) ;
9
12
10
13
test ( "Test MyClass's getStudentById" , ( ) => {
11
- // TODO
12
- throw new Error ( "Test not implemented" ) ;
14
+ const myClass = new MyClass ( ) ;
15
+ const student = new Student ( ) ;
16
+ student . setName ( 'John' ) ;
17
+ const newStudentId = myClass . addStudent ( student ) ;
18
+ assert . strictEqual ( myClass . getStudentById ( newStudentId ) , student ) ;
19
+ assert . strictEqual ( myClass . getStudentById ( - 2 ) , null ) ;
20
+ assert . strictEqual ( myClass . getStudentById ( 2 ) , null ) ;
13
21
} ) ;
14
22
15
23
test ( "Test Student's setName" , ( ) => {
16
- // TODO
17
- throw new Error ( "Test not implemented" ) ;
24
+ const myClass = new MyClass ( ) ;
25
+ const student = new Student ( ) ;
26
+ student . setName ( 'John' ) ;
27
+ assert . strictEqual ( student . name , 'John' ) ;
28
+ student . setName ( 123 ) ;
18
29
} ) ;
19
30
20
31
test ( "Test Student's getName" , ( ) => {
21
- // TODO
22
- throw new Error ( "Test not implemented" ) ;
32
+ const myClass = new MyClass ( ) ;
33
+ const student = new Student ( ) ;
34
+ assert . strictEqual ( student . getName ( ) , '' ) ;
35
+ student . setName ( 'John' ) ;
36
+ assert . strictEqual ( student . getName ( ) , 'John' ) ;
23
37
} ) ;
0 commit comments