@@ -12,21 +12,51 @@ test("Test MyClass's addStudent", () => {
12
12
assert . strictEqual ( myClass . students . length , 1 ) ;
13
13
assert . strictEqual ( myClass . students [ 0 ] , student ) ;
14
14
15
+ const newStudentId2 = myClass . addStudent ( 'not a student' ) ;
16
+ assert . strictEqual ( newStudentId2 , - 1 ) ;
17
+
15
18
// throw new Error("Test not implemented");
16
19
17
20
} ) ;
18
21
19
22
test ( "Test MyClass's getStudentById" , ( ) => {
20
23
// TODO
21
- throw new Error ( "Test not implemented" ) ;
24
+ const myClass = new MyClass ( ) ;
25
+ const student = new Student ( ) ;
26
+ myClass . addStudent ( student ) ;
27
+ const studentById = myClass . getStudentById ( 0 ) ;
28
+ assert . strictEqual ( studentById , student ) ;
29
+
30
+ const studentById2 = myClass . getStudentById ( - 1 ) ;
31
+ assert . strictEqual ( studentById2 , null ) ;
32
+ const studentById3 = myClass . getStudentById ( 1 ) ;
33
+ assert . strictEqual ( studentById3 , null ) ;
34
+
35
+ // throw new Error("Test not implemented");
22
36
} ) ;
23
37
24
38
test ( "Test Student's setName" , ( ) => {
25
39
// TODO
26
- throw new Error ( "Test not implemented" ) ;
40
+ const student = new Student ( ) ;
41
+ student . setName ( "John" ) ;
42
+ assert . strictEqual ( student . getName ( ) , "John" ) ;
43
+
44
+ const student2 = new Student ( ) ;
45
+ student2 . setName ( 123 ) ;
46
+ assert . strictEqual ( student . getName ( ) , "John" ) ;
47
+
48
+ // throw new Error("Test not implemented");
27
49
} ) ;
28
50
29
51
test ( "Test Student's getName" , ( ) => {
30
52
// TODO
31
- throw new Error ( "Test not implemented" ) ;
53
+ const student = new Student ( ) ;
54
+ student . setName ( "John" ) ;
55
+ assert . strictEqual ( student . getName ( ) , "John" ) ;
56
+
57
+ const student2 = new Student ( ) ;
58
+ student2 . setName ( 123 ) ;
59
+ assert . strictEqual ( student2 . getName ( ) , '' ) ;
60
+
61
+ // throw new Error("Test not implemented");
32
62
} ) ;
0 commit comments