@@ -4,20 +4,46 @@ const { MyClass, Student } = require('./main');
44
55test ( "Test MyClass's addStudent" , ( ) => {
66 // TODO
7- throw new Error ( "Test not implemented" ) ;
7+ const myClass = new MyClass ( ) ;
8+ //check fail case
9+ assert . strictEqual ( myClass . addStudent ( { } ) , - 1 ) ;
10+ //check success case
11+ assert . strictEqual ( myClass . addStudent ( new Student ) , 0 ) ;
12+
813} ) ;
914
1015test ( "Test MyClass's getStudentById" , ( ) => {
1116 // TODO
12- throw new Error ( "Test not implemented" ) ;
17+ const myClass = new MyClass ( ) ;
18+ assert . strictEqual ( myClass . getStudentById ( - 1 ) , null ) ;
19+ assert . strictEqual ( myClass . getStudentById ( 10 ) , null ) ;
20+ const names = [ 'John' , 'Jane' , 'Doe' , 'Smith' ] ;
21+ names . forEach ( name => {
22+ const student = new Student ( ) ;
23+ student . setName ( name ) ;
24+ const newStudentId = myClass . addStudent ( student ) ;
25+ const newStudentName = myClass . getStudentById ( newStudentId ) . getName ( ) ;
26+ } ) ;
27+ assert . strictEqual ( myClass . getStudentById ( 0 ) . getName ( ) , 'John' ) ;
28+ assert . strictEqual ( myClass . getStudentById ( 1 ) . getName ( ) , 'Jane' ) ;
29+ assert . strictEqual ( myClass . getStudentById ( 2 ) . getName ( ) , 'Doe' ) ;
30+ assert . strictEqual ( myClass . getStudentById ( 3 ) . getName ( ) , 'Smith' ) ;
1331} ) ;
1432
1533test ( "Test Student's setName" , ( ) => {
1634 // TODO
17- throw new Error ( "Test not implemented" ) ;
35+ const student = new Student ( ) ;
36+ student . setName ( 123 ) ;
37+ assert . strictEqual ( student . getName ( ) , '' ) ;
38+ student . setName ( '123' ) ;
39+ assert . strictEqual ( student . getName ( ) , '123' ) ;
1840} ) ;
1941
2042test ( "Test Student's getName" , ( ) => {
2143 // TODO
22- throw new Error ( "Test not implemented" ) ;
44+ const student = new Student ( ) ;
45+ student . setName ( 123 ) ;
46+ assert . strictEqual ( student . getName ( ) , '' ) ;
47+ student . setName ( '123' ) ;
48+ assert . strictEqual ( student . getName ( ) , '123' ) ;
2349} ) ;
0 commit comments