1
1
const test = require ( 'node:test' ) ;
2
2
const assert = require ( 'assert' ) ;
3
- const { MyClass, Student } = require ( './main' ) ;
3
+ const { MyClass, Student} = require ( './main' ) ;
4
4
5
5
test ( "Test MyClass's addStudent" , ( ) => {
6
6
// TODO
7
- throw new Error ( "Test not implemented" ) ;
7
+ const myClass = new MyClass ( )
8
+ const student = new Student ( )
9
+
10
+ const newStudentId = myClass . addStudent ( student ) ;
11
+
12
+ assert . strictEqual ( newStudentId , 0 ) ;
13
+ assert . strictEqual ( myClass . addStudent ( { } ) , - 1 ) ;
14
+
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
+ const myClass = new MyClass ( ) ;
21
+ const student = new Student ( ) ;
22
+ student . setName ( "John" ) ;
23
+
24
+ const studentId = myClass . addStudent ( student ) ;
25
+
26
+ const foundStudent = myClass . getStudentById ( studentId ) ;
27
+ assert . strictEqual ( foundStudent , student ) ;
28
+
29
+ assert . strictEqual ( myClass . getStudentById ( - 5 ) , null )
30
+ assert . strictEqual ( myClass . getStudentById ( 123 ) , null )
31
+ // throw new Error("Test not implemented");
13
32
} ) ;
14
33
15
34
test ( "Test Student's setName" , ( ) => {
16
35
// TODO
17
- throw new Error ( "Test not implemented" ) ;
36
+ const student = new Student ( ) ;
37
+
38
+ student . setName ( "Mike" ) ;
39
+ assert . strictEqual ( student . getName ( ) , "Mike" ) ;
40
+
41
+ student . setName ( 222 ) ;
42
+ assert . strictEqual ( student . getName ( ) , "Mike" ) ;
43
+ // throw new Error("Test not implemented");
18
44
} ) ;
19
45
20
46
test ( "Test Student's getName" , ( ) => {
21
47
// TODO
22
- throw new Error ( "Test not implemented" ) ;
48
+ const student = new Student ( ) ;
49
+
50
+ assert . strictEqual ( student . getName ( ) , "" ) ;
51
+
52
+ student . setName ( "John" ) ;
53
+ assert . strictEqual ( student . getName ( ) , "John" ) ;
54
+ // throw new Error("Test not implemented");
23
55
} ) ;
0 commit comments