@@ -5,27 +5,26 @@ const { Application, MailSystem } = require('./main');
5
5
6
6
// TODO: write your tests here
7
7
// Remember to use Stub, Mock, and Spy when necessary
8
- const originalMathRandom = Math . random ;
9
- test ( "Test MailSystem's write" , ( ) => {
10
- const mailsystem = new MailSystem ( ) ;
11
- assert . strictEqual ( mailsystem . write ( "John" ) , 'Congrats, John!' ) ;
12
- } ) ;
13
- test ( "Test MailSystem's send" , ( ) => {
14
- //test('should send mail successfully', () => {
15
- const mailsystem = new MailSystem ( ) ;
16
- const name = 'John' ;
17
- Math . random = ( ) => 0.7 ;
18
- const result = mailsystem . send ( name , mailsystem . write ( name ) ) ;
19
- assert . strictEqual ( result , true ) ;
20
- Math . random = originalMathRandom ;
21
-
22
- Math . random = ( ) => 0.3 ;
23
- const result_ = mailsystem . send ( name , mailsystem . write ( name ) ) ;
24
- assert . strictEqual ( result_ , false ) ;
25
- } ) ;
8
+ // test("Test MailSystem's write", () => {
9
+ // const mailsystem = new MailSystem();
10
+ // assert.strictEqual(mailsystem.write("John"), 'Congrats, John!');
11
+ // });
12
+ // test("Test MailSystem's send",()=>{
13
+ // //test('should send mail successfully', () => {
14
+ // const mailsystem = new MailSystem();
15
+ // const name = 'John';
16
+ // Math.random = () => 0.7;
17
+ // const result = mailsystem.send(name,mailsystem.write(name));
18
+ // assert.strictEqual(result,true);
19
+ // Math.random = originalMathRandom;
20
+
21
+ // Math.random = () => 0.3;
22
+ // const result_ = mailsystem.send(name,mailsystem.write(name));
23
+ // assert.strictEqual(result_,false);
24
+ // });
26
25
27
26
const data = 'John\nJane\nDoe' ;
28
-
27
+ const originalMathRandom = Math . random ;
29
28
test ( "Test Application's getNames" , async ( ) => {
30
29
//mock fs.readFile just using test runner
31
30
fs . writeFileSync ( 'name_list.txt' , data , 'utf8' ) ;
@@ -76,36 +75,6 @@ test("Test Application's selectNextPerson", async() => {
76
75
//fs.unlink('name_list.txt', () => {});
77
76
} ) ;
78
77
79
- test ( "Test Application's selectNextPerson2" , async ( ) => {
80
- let app = new Application ( ) ;
81
- [ app . people , app . selected ] = await app . getNames ( ) ;
82
- //const originalMathRandom = Math.random;
83
- //Math.random = () => 0;
84
- Math . random = originalMathRandom ;
85
- let oneFlag = false ;
86
- Math . random = ( ) => {
87
- if ( app . selected . includes ( 'John' ) && oneFlag ) {
88
- return 0.5 ;
89
- }
90
- if ( app . selected . includes ( 'John' ) ) {
91
- oneFlag = true ;
92
- return 0 ;
93
- }
94
- else {
95
- return 0 ;
96
- }
97
- }
98
- assert . deepStrictEqual ( app . selectNextPerson ( ) , 'John' ) ;
99
- //Math.random = originalMathRandom;
100
- assert . deepStrictEqual ( app . selectNextPerson ( ) , 'Jane' ) ;
101
- //Math.random = () => 0.9;
102
- Math . random = originalMathRandom ;
103
- assert . deepStrictEqual ( app . selectNextPerson ( ) , 'Doe' ) ;
104
- assert . deepStrictEqual ( app . selectNextPerson ( ) , null ) ;
105
- assert . deepStrictEqual ( app . selectNextPerson ( ) , null ) ;
106
- assert . deepStrictEqual ( app . selectNextPerson ( ) , null ) ;
107
- //fs.unlink('name_list.txt', () => {});
108
- } ) ;
109
78
test ( "Test Application's notifySelected" , async ( t ) => {
110
79
let app = new Application ( ) ;
111
80
[ app . people , app . selected ] = await app . getNames ( ) ;
0 commit comments