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