Skip to content

Commit fcf7db7

Browse files
authored
Update main_test.js
1 parent d956dee commit fcf7db7

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

lab2/main_test.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
const test = require('node:test');
1+
const testUtil = require('node:test');
22
const assert = require('assert');
33
const fs = require('fs');
44

5-
test.mock.method(fs, 'readFile', (file, options, callback) => {
6-
callback(null, 'Aqur\nBobi\ncat');
5+
// Mock the file containing names
6+
testUtil.mock.method(fs, 'readFile', (file, options, callback) => {
7+
callback(null, 'Alice\nBob\ncat');
78
});
89

910
const { Application, MailSystem } = require('./main');
1011

11-
test('MailSystem_write()', () => {
12+
testUtil('MailSystem_write()', () => {
1213
const mailSystem = new MailSystem();
13-
assert.strictEqual(mailSystem.write('Aqur'), 'Congrats, Aqur!');
14+
assert.strictEqual(mailSystem.write('Alice'), 'Congrats, Alice!');
1415
assert.strictEqual(mailSystem.write(202), 'Congrats, 202!');
1516
assert.strictEqual(mailSystem.write(null), 'Congrats, null!');
1617
});
1718

18-
test('MailSystem_send()', () => {
19+
testUtil('MailSystem_send()', () => {
1920
const mailSystem = new MailSystem();
20-
const name = 'Aqur';
21-
test.mock.method(Math, 'random', () => 0.9);
21+
const name = 'Alice';
22+
testUtil.mock.method(Math, 'random', () => 0.9);
2223
assert.strictEqual(mailSystem.send(name, 'success'), true);
23-
test.mock.method(Math, 'random', () => 0.2);
24+
testUtil.mock.method(Math, 'random', () => 0.2);
2425
assert.strictEqual(mailSystem.send(name, 'fail'), false);
2526
});
2627

27-
test('Application_getNames()', async () => {
28+
testUtil('Application_getNames()', async () => {
2829
const app = new Application();
29-
const nameList = ['Aqur', 'Bobi', 'cat'];
30+
const nameList = ['Alice', 'Bob', 'cat'];
3031
const [names, selected] = await app.getNames();
3132
assert.deepStrictEqual(names, nameList);
3233
assert.deepStrictEqual(selected, []);
3334
});
3435

35-
test('Application_getRandomPerson()', async () => {
36+
testUtil('Application_getRandomPerson()', async () => {
3637
const app = new Application();
3738
const [names] = await app.getNames();
3839
const randomPerson = app.getRandomPerson();
3940
});
4041

41-
test('Application_selectNextPerson()', async () => {
42+
testUtil('Application_selectNextPerson()', async () => {
4243
const app = new Application();
4344
const [names] = await app.getNames();
44-
app.selected = ['Aqur'];
45+
app.selected = ['Alice'];
4546
let count = 0;
46-
test.mock.method(app, 'getRandomPerson', () => names[count++]);
47-
assert.strictEqual(app.selectNextPerson(), 'Bobi');
48-
assert.deepStrictEqual(app.selected, ['Aqur', 'Bobi']);
47+
testUtil.mock.method(app, 'getRandomPerson', () => names[count++]);
48+
assert.strictEqual(app.selectNextPerson(), 'Bob');
49+
assert.deepStrictEqual(app.selected, ['Alice', 'Bob']);
4950
assert.strictEqual(app.selectNextPerson(), 'cat');
50-
assert.deepStrictEqual(app.selected, ['Aqur', 'Bobi', 'cat']);
51+
assert.deepStrictEqual(app.selected, ['Alice', 'Bob', 'cat']);
5152
assert.strictEqual(app.selectNextPerson(), null);
5253
});
5354

54-
55-
test('Application_notifySelected()', async () => {
55+
testUtil('Application_notifySelected()', async () => {
5656
const app = new Application();
5757
const [names] = await app.getNames();
5858
app.selected = names.slice(); // Select all names initially
59-
app.mailSystem.send = test.mock.fn(app.mailSystem.send);
60-
app.mailSystem.write = test.mock.fn(app.mailSystem.write);
59+
app.mailSystem.send = testUtil.mock.fn(app.mailSystem.send);
60+
app.mailSystem.write = testUtil.mock.fn(app.mailSystem.write);
6161
app.notifySelected();
6262
assert.strictEqual(app.mailSystem.send.mock.calls.length, names.length);
6363
assert.strictEqual(app.mailSystem.write.mock.calls.length, names.length);

0 commit comments

Comments
 (0)