Skip to content

Commit 2799fff

Browse files
committed
complete lab2
1 parent c52b1bc commit 2799fff

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lab2/main_test.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,34 @@ const path = require('path');
99

1010
test('MailSystem should return the correct message context.', () => {
1111
const mailSystem = new MailSystem();
12-
const recipient = 'Justin';
12+
const message = mailSystem.write('Justin');
1313

14-
const message = mailSystem.write(recipient);
1514
assert.strictEqual(message, 'Congrats, Justin!');
1615
});
1716

18-
test('MailSystem should send mail corrctly', (t) => {
17+
test('MailSystem should send mail corrctly', () => {
1918
const mailSystem = new MailSystem();
2019

21-
// SUCCESS
22-
t.mock.method(Math,'random', () => 1);
20+
// SUCCESSFUL CASE
21+
test.mock.method(Math,'random', () => 1);
2322
let isMailSent = mailSystem.send('Alice', "Hello Message");
24-
assert.strictEqual(isMailSent, true);
23+
assert.strictEqual(isMailSent, true, 'Mail should be sent successfully when Math.random() returns 1');
2524

26-
// FAIL
27-
t.mock.method(Math, 'random', () => 0.5);
25+
// FAIL CASE
26+
test.mock.method(Math, 'random', () => 0.5);
2827
isMailSent = mailSystem.send('Alice', "Hello Message");
29-
assert.strictEqual(isMailSent, false);
28+
assert.strictEqual(isMailSent, false, 'Mail should fail to send when Math.random() returns a value less than 0.5');
3029
});
3130

3231
test('Application should read names from file correctly', async()=>{
33-
const nameList = 'Alice\nBob\nCharlie';
34-
const filePath = path.join('name_list.txt');
32+
const nameList = 'Alice\nBob\nCharlie\nSam';
33+
const filePath = path.resolve('name_list.txt');
3534
fs.writeFileSync(filePath, nameList);
3635

3736
const app = new Application();
3837
const [names, selected] = await app.getNames(filePath);
3938

40-
assert.deepStrictEqual(names, ['Alice', 'Bob', 'Charlie']);
39+
assert.deepStrictEqual(names, ['Alice', 'Bob', 'Charlie', 'Sam']);
4140
assert.deepStrictEqual(selected, []);
4241
});
4342

0 commit comments

Comments
 (0)