Skip to content

Commit 3c92a7a

Browse files
authored
Update main_test.js
1 parent 31d54f4 commit 3c92a7a

File tree

1 file changed

+18
-49
lines changed

1 file changed

+18
-49
lines changed

lab2/main_test.js

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@ const { Application, MailSystem } = require('./main');
55

66
// TODO: write your tests here
77
// 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+
// });
2625

2726
const data = 'John\nJane\nDoe';
28-
27+
const originalMathRandom = Math.random;
2928
test("Test Application's getNames", async () => {
3029
//mock fs.readFile just using test runner
3130
fs.writeFileSync('name_list.txt', data, 'utf8');
@@ -76,36 +75,6 @@ test("Test Application's selectNextPerson", async() => {
7675
//fs.unlink('name_list.txt', () => {});
7776
});
7877

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-
});
10978
test("Test Application's notifySelected", async(t) => {
11079
let app = new Application();
11180
[app.people,app.selected] = await app.getNames();

0 commit comments

Comments
 (0)