1
1
const test = require ( 'node:test' ) ;
2
2
const assert = require ( 'assert' ) ;
3
3
const { MyClass, Student } = require ( './main' ) ;
4
+ const exp = require ( 'constants' ) ;
4
5
5
6
test ( "Test MyClass's addStudent" , ( ) => {
6
7
// TODO
7
- throw new Error ( "Test not implemented" ) ;
8
+ const myClass = new MyClass ( ) ;
9
+ const student = new Student ( ) ;
10
+ const newStudentId = myClass . addStudent ( student ) ;
11
+ assert . strictEqual ( newStudentId , 0 ) ;
12
+ assert . strictEqual ( myClass . students . length , 1 ) ;
13
+ assert . strictEqual ( myClass . students [ 0 ] , student ) ;
14
+
15
+ const newStudentId2 = myClass . addStudent ( 'not a student' ) ;
16
+ assert . strictEqual ( newStudentId2 , - 1 ) ;
17
+
18
+ // throw new Error("Test not implemented");
19
+
8
20
} ) ;
9
21
10
22
test ( "Test MyClass's getStudentById" , ( ) => {
11
23
// TODO
12
- 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");
13
36
} ) ;
14
37
15
38
test ( "Test Student's setName" , ( ) => {
16
39
// TODO
17
- 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");
18
49
} ) ;
19
50
20
51
test ( "Test Student's getName" , ( ) => {
21
52
// TODO
22
- 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");
23
62
} ) ;
0 commit comments