@@ -4,20 +4,55 @@ const { MyClass, Student } = require('./main');
44
55test ( "Test MyClass's addStudent" , ( ) => {
66 // TODO
7- throw new Error ( "Test not implemented" ) ;
7+ var myClass = new MyClass ( ) ;
8+ var student = new Student ( ) ;
9+
10+ var res = myClass . addStudent ( ) ;
11+ assert . equal ( res , - 1 ) ;
12+
13+ res = myClass . addStudent ( student ) ;
14+ assert . equal ( res , 0 ) ;
15+ // throw new Error("Test not implemented");
816} ) ;
917
1018test ( "Test MyClass's getStudentById" , ( ) => {
1119 // TODO
12- throw new Error ( "Test not implemented" ) ;
20+ var myClass = new MyClass ( ) ;
21+ var student = new Student ( ) ;
22+
23+ myClass . addStudent ( student ) ;
24+ var res = myClass . getStudentById ( 0 ) ;
25+ assert . equal ( res , student ) ;
26+
27+ res = myClass . getStudentById ( - 1 ) ;
28+ assert . equal ( res , null ) ;
29+
30+ res = myClass . getStudentById ( 2 ) ;
31+ assert . equal ( res , null ) ;
32+
1333} ) ;
1434
1535test ( "Test Student's setName" , ( ) => {
1636 // TODO
17- throw new Error ( "Test not implemented" ) ;
37+ // throw new Error("Test not implemented");
38+ var student = new Student ( ) ;
39+ student . setName ( "Quan" ) ;
40+
41+ var res = student . name ;
42+ assert . equal ( res , "Quan" ) ;
43+
44+ student . setName ( 123 ) ;
45+ res = student . name ;
46+ assert . equal ( res , "Quan" ) ;
1847} ) ;
1948
2049test ( "Test Student's getName" , ( ) => {
21- // TODO
22- throw new Error ( "Test not implemented" ) ;
50+ var student = new Student ( ) ;
51+
52+ var res = student . getName ( ) ;
53+ assert . equal ( res , "" ) ;
54+
55+ student . setName ( "Quan" ) ;
56+ res = student . getName ( ) ;
57+ assert . equal ( res , "Quan" ) ;
2358} ) ;
0 commit comments