@@ -4,20 +4,51 @@ 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+ const student = new Student ( ) ;
9+
10+ const studentId = myClass . addStudent ( student ) ;
11+ // const name = ['John'];
12+ assert . strictEqual ( studentId , 0 ) ;
13+
14+ assert . strictEqual ( myClass . addStudent ( { } ) , - 1 ) ;
15+ // throw new Error("Test not implemented");
816} ) ;
917
1018test ( "Test MyClass's getStudentById" , ( ) => {
1119 // TODO
12- throw new Error ( "Test not implemented" ) ;
20+ const myClass = new MyClass ( ) ;
21+ const student = new Student ( ) ;
22+ student . setName ( "John" ) ;
23+ const studentId = myClass . addStudent ( student ) ;
24+
25+ const retrievedStudent = myClass . getStudentById ( studentId ) ;
26+ assert . strictEqual ( retrievedStudent , student ) ;
27+
28+ assert . strictEqual ( myClass . getStudentById ( - 1 ) , null ) ;
29+ assert . strictEqual ( myClass . getStudentById ( 100 ) , null ) ;
30+ // throw new Error("Test not implemented");
1331} ) ;
1432
1533test ( "Test Student's setName" , ( ) => {
1634 // TODO
17- throw new Error ( "Test not implemented" ) ;
35+ const student = new Student ( ) ;
36+
37+ student . setName ( "Alice" ) ;
38+ assert . strictEqual ( student . getName ( ) , "Alice" ) ;
39+
40+ student . setName ( 123 ) ;
41+ assert . strictEqual ( student . getName ( ) , "Alice" ) ;
42+ // throw new Error("Test not implemented");
1843} ) ;
1944
2045test ( "Test Student's getName" , ( ) => {
2146 // TODO
22- throw new Error ( "Test not implemented" ) ;
47+ const student = new Student ( ) ;
48+
49+ assert . strictEqual ( student . getName ( ) , "" ) ;
50+
51+ student . setName ( "Bob" ) ;
52+ assert . strictEqual ( student . getName ( ) , "Bob" ) ;
53+ // throw new Error("Test not implemented");
2354} ) ;
0 commit comments