@@ -3,21 +3,35 @@ const assert = require('assert');
33const { MyClass, Student } = require ( './main' ) ;
44
55test ( "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 ) ;
811} ) ;
912
1013test ( "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 ) ;
1321} ) ;
1422
1523test ( "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 ) ;
1829} ) ;
1930
2031test ( "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' ) ;
2337} ) ;
0 commit comments