Skip to content

Commit 7ec4ad1

Browse files
authored
Update main_test.js
1 parent cd95aa0 commit 7ec4ad1

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

lab2/main_test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ const readFile = util.promisify(fs.readFile);
44

55
class MailSystem {
66
write(name) {
7-
// 修改 MailSystem 的 write 方法,使其返回包含名稱的特定內容
87
console.log('--write mail for ' + name + '--');
98
const context = 'Congrats, ' + name + '!';
109
return context;
1110
}
1211

1312
send(name, context) {
14-
// 修改 MailSystem 的 send 方法,模擬發送郵件並隨機返回成功或失敗
1513
console.log('--send mail to ' + name + '--');
16-
const success = Math.random() > 0.5; // 模擬郵件發送的隨機成功或失敗
14+
const success = Math.random() > 0.5;
1715
if (success) {
1816
console.log('mail sent');
1917
} else {
2018
console.log('mail failed');
2119
}
22-
return success; // 返回發送成功或失敗的結果
20+
return success;
2321
}
2422
}
2523

@@ -35,21 +33,18 @@ class Application {
3533
}
3634

3735
async getNames() {
38-
// 修改 getNames 方法,使其從文件中讀取名稱列表
3936
const data = await readFile('name_list.txt', 'utf8');
4037
const people = data.split('\n');
4138
const selected = [];
4239
return [people, selected];
4340
}
4441

4542
getRandomPerson() {
46-
// 修改 getRandomPerson 方法,隨機返回一個名稱
4743
const i = Math.floor(Math.random() * this.people.length);
4844
return this.people[i];
4945
}
5046

5147
selectNextPerson() {
52-
// 修改 selectNextPerson 方法,隨機選擇並返回一個未被選擇過的名稱
5348
console.log('--select next person--');
5449
if (this.people.length === this.selected.length) {
5550
console.log('all selected');
@@ -64,7 +59,6 @@ class Application {
6459
}
6560

6661
notifySelected() {
67-
// 修改 notifySelected 方法,通知所有已選擇的人
6862
console.log('--notify selected--');
6963
for (const x of this.selected) {
7064
const context = this.mailSystem.write(x);

0 commit comments

Comments
 (0)