Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LAB2] 312551148 #99

Merged
merged 17 commits into from
Mar 20, 2024
Prev Previous commit
Next Next commit
fix Error: ENOENT: no such file or directory: open name_list.txt
ming-hsien committed Mar 9, 2024
commit 3d6146898905545e4fcc94c7a2b663e0ccb16ff3
1 change: 1 addition & 0 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ test("Test Student's setName", () => {
assert.strictEqual(student.name, undefined);
student.setName(name);
assert.strictEqual(student.name, name);

});

test("Test Student's getName", () => {
35 changes: 20 additions & 15 deletions lab2/main_test.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const fs = require('fs');
const util = require('util');
const writeFile = util.promisify(fs.writeFile);
const { Application, MailSystem } = require('./main');
const path = require('node:path');

// TODO: write your tests here
// Remember to use Stub, Mock, and Spy when necessary
@@ -16,6 +17,7 @@ test("Test MailSystem's write", () => {

test("Test MailSystem's send", () => {
const ms = new MailSystem();

Math.random = () => 0.4;
let context = ms.send("Jerry", "Test Message");
assert.strictEqual(context, false);
@@ -25,27 +27,28 @@ test("Test MailSystem's send", () => {
assert.strictEqual(context, true);
});

test("Test Application's getNames", async() => {
const app = new Application();

const fn_ = "name_list.txt";
test("Test Application's getNames", async () => {
const fn_ = path.join(process.cwd(), 'name_list.txt');
const data_ = "JJ\nEE\nRR\nYY";
await writeFile(fn_, data_, "utf-8");

const app = new Application();

let ctx = new Array([],[]);
ctx = await app.getNames();
assert.deepStrictEqual(ctx[0], ["JJ", "EE", "RR", "YY"]);
assert.deepStrictEqual(ctx[1], []);

fs.unlinkSync(fn_);
});

test("Test Application's getRandomPerson", async() => {
const app = new Application();

const fn_ = "name_list.txt";
test("Test Application's getRandomPerson", async () => {
const fn_ = path.join(process.cwd(), 'name_list.txt');
const data_ = "JJ\nEE\nRR\nYY";
await writeFile(fn_, data_, "utf-8");

const app = new Application();

let ctx = new Array([],[]);
ctx = await app.getNames();
assert.deepStrictEqual(ctx[0], ["JJ", "EE", "RR", "YY"]);
@@ -58,16 +61,17 @@ test("Test Application's getRandomPerson", async() => {
Math.random = () => 0.99;
rdmPeople = app.getRandomPerson();
assert.strictEqual(rdmPeople, "YY");

fs.unlinkSync(fn_);
});

test("Test Application's selectNextPerson", async() => {
const app = new Application();

const fn_ = "name_list.txt";
test("Test Application's selectNextPerson", async () => {
const fn_ = path.join(process.cwd(), 'name_list.txt');
const data_ = "JJ\nEE";
await writeFile(fn_, data_, "utf-8");

const app = new Application();

let ctx = new Array([],[]);
ctx = await app.getNames();
assert.deepStrictEqual(ctx[0], ["JJ", "EE"]);
@@ -90,13 +94,14 @@ test("Test Application's selectNextPerson", async() => {
fs.unlinkSync(fn_);
});

test("Test Application's notifySelected", async() => {
const app = new Application();
test("Test Application's notifySelected", async () => {

const fn_ = "name_list.txt";
const fn_ = 'name_list.txt';
const data_ = "JJ\nEE";
await writeFile(fn_, data_, "utf-8");

const app = new Application();

let ctx = new Array([],[]);
ctx = await app.getNames();
assert.deepStrictEqual(ctx[0], ["JJ", "EE"]);