@@ -2,22 +2,52 @@ const test = require('node:test');
2
2
const assert = require ( 'assert' ) ;
3
3
const { MyClass, Student } = require ( './main' ) ;
4
4
5
+ const myclass = new MyClass ;
6
+
5
7
test ( "Test MyClass's addStudent" , ( ) => {
6
8
// TODO
7
- throw new Error ( "Test not implemented" ) ;
9
+ assert . equal ( - 1 , myclass . addStudent ( 'Oops' ) ) ;
10
+ const student = new Student ;
11
+ const name = 'Kiwi'
12
+ student . setName ( name ) ;
13
+ assert . equal ( 0 , myclass . addStudent ( student ) ) ;
14
+ return ;
15
+ // throw new Error("Test not implemented");
8
16
} ) ;
9
17
10
18
test ( "Test MyClass's getStudentById" , ( ) => {
11
19
// TODO
12
- throw new Error ( "Test not implemented" ) ;
20
+ assert . equal ( null , myclass . getStudentById ( - 3 ) ) ;
21
+ assert . equal ( null , myclass . getStudentById ( 10 ) ) ;
22
+ const student = new Student ;
23
+ const name = 'Kiwi'
24
+ student . setName ( name ) ;
25
+ const id = myclass . addStudent ( student ) ;
26
+ assert . equal ( student , myclass . getStudentById ( id ) ) ;
27
+ return ;
28
+ // throw new Error("Test not implemented");
13
29
} ) ;
14
30
15
31
test ( "Test Student's setName" , ( ) => {
16
32
// TODO
17
- throw new Error ( "Test not implemented" ) ;
33
+ const student = new Student ;
34
+ student . setName ( 123 ) ;
35
+ assert . equal ( undefined , student . name ) ;
36
+
37
+ const name = 'Kiwi'
38
+ student . setName ( name ) ;
39
+ assert . equal ( name , student . name ) ;
40
+ return ;
41
+ // throw new Error("Test not implemented");
18
42
} ) ;
19
43
20
44
test ( "Test Student's getName" , ( ) => {
21
45
// TODO
22
- throw new Error ( "Test not implemented" ) ;
46
+ const student = new Student ;
47
+ assert . equal ( '' , student . getName ( ) ) ;
48
+ const name = 'Kiwi'
49
+ student . setName ( name ) ;
50
+ assert . equal ( name , student . getName ( ) ) ;
51
+ return ;
52
+ // throw new Error("Test not implemented");
23
53
} ) ;
0 commit comments