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] 510558017 #602

Closed
wants to merge 48 commits into from
Closed
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2233c14
fix: improve workflows
AlaRduTP Mar 13, 2024
e2b8057
fix: scripts/rebase-all.sh will fail due to too frequent remote opera…
AlaRduTP Mar 13, 2024
8336df3
feat: lab2
AlaRduTP Mar 13, 2024
0f5c5dd
feat: merge-all
AlaRduTP Mar 13, 2024
5fa8ffe
remove: create-branches.sh
AlaRduTP Mar 20, 2024
354fae7
feat: auto resolve conflicts when merging
AlaRduTP Mar 20, 2024
e49fa08
feat: improve GitHub workflows
AlaRduTP Mar 20, 2024
c895269
feat: lab3
AlaRduTP Mar 20, 2024
22a9521
feat: an easy check for changed files
AlaRduTP Mar 20, 2024
15ca1a7
doc: detailed steps of syncing fork
AlaRduTP Mar 20, 2024
dd650d8
fix: remove trailing whitespace
AlaRduTP Mar 20, 2024
cee6631
feat: add node_modules into gitignore
AlaRduTP Mar 27, 2024
ffbfbd7
feat: lab4
AlaRduTP Mar 27, 2024
5ee9d55
Add lab5
YingMuo Apr 17, 2024
86b3714
Fix github action
YingMuo Apr 17, 2024
c27f68f
Fix README.md
YingMuo Apr 17, 2024
419ed6d
fix: gh-script syntax error
AlaRduTP Apr 17, 2024
41cc403
add: lab6
YingMuo Apr 24, 2024
9777d36
feat: lab6
YingMuo Apr 24, 2024
110400a
fix: lab6
YingMuo Apr 24, 2024
eae2c35
fix: lab6
YingMuo Apr 24, 2024
2063787
Fix: lab6
YingMuo Apr 24, 2024
a2f55d5
Add: lab7
YingMuo May 1, 2024
56585b1
Fix: lab7
YingMuo May 1, 2024
7a945c9
Fix: lab7, angr not installed
YingMuo May 1, 2024
bb5fb3d
feat: add hw4
TaiYou-TW May 30, 2024
b88ef9e
fix: wrong days for hw4 leap year
TaiYou-TW May 30, 2024
3a9853d
Update lab-autograding.yml
as10968574 Jun 11, 2024
e5e7668
Update lab-autograding.yml
as10968574 Jun 13, 2024
617f910
Update lab-autograding.yml
as10968574 Jun 24, 2024
44d657c
Update main_test.js
as10968574 Jun 24, 2024
41e925c
Delete hw4 directory
as10968574 Jun 24, 2024
b22555f
Delete lab3 directory
as10968574 Jun 24, 2024
bbc3105
Delete lab4 directory
as10968574 Jun 24, 2024
359d046
Delete lab5 directory
as10968574 Jun 24, 2024
eb4b34c
Delete lab6 directory
as10968574 Jun 24, 2024
4b619b5
Delete lab7 directory
as10968574 Jun 24, 2024
eaafdad
Merge branch '510558017' into lab2
as10968574 Jun 24, 2024
768790b
Update main_test.js
as10968574 Jun 24, 2024
245bd09
Update main_test.js
as10968574 Jun 24, 2024
e6b89b4
Update main_test.js
as10968574 Jun 24, 2024
775a3ab
Update main_test.js
as10968574 Jun 24, 2024
a2cf440
Update main_test.js
as10968574 Jun 24, 2024
a2ff3da
Update main_test.js
as10968574 Jun 24, 2024
96837e8
Update main_test.js
as10968574 Jun 24, 2024
98bfae1
Update main_test.js
as10968574 Jun 24, 2024
053accb
Update main_test.js
as10968574 Jun 24, 2024
a39ebdf
Update main_test.js
as10968574 Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion lab2/main_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,68 @@
const test = require('node:test');
const assert = require('assert');
const fs = require('fs');
test.mock.method(fs, 'readFile', (file, options, callback) => {
callback(null, 'Guan\nChen\nGala');
});
const { Application, MailSystem } = require('./main');

// TODO: write your tests here
// Remember to use Stub, Mock, and Spy when necessary
// Remember to use Stub, Mock, and Spy when necessary
test("Test MailSystem's write", () => {
const myClass = new MailSystem()
assert.strictEqual( myClass.write("Guan"),"Congrats, Guan!")
});

test("Test MailSystem's send(name, context)", () => {
Math.random = () => 0.6
const mailSystem = new MailSystem()
const context = mailSystem.write("Guan")
const success = mailSystem.send("Guan",context)
assert.strictEqual(success,true)
Math.random = () => 0.5
assert.strictEqual(mailSystem.send("Chen",context),false)
});

test("Test Application's getNames", async () => {
const application = new Application
const [people, selected] = await application.getNames()
assert.deepStrictEqual(people, ["Guan", "Chen", "Gala"])
assert.deepStrictEqual(selected, [])
});

test("Test Application's getRandomPerson()", (t) => {
const application = new Application
application.people = ["Guan", "Chen", "Gala"]
Math.random = () => 0
assert.deepStrictEqual(application.getRandomPerson(), "Guan");
Math.random = () => 0.6
assert.deepStrictEqual(application.getRandomPerson(), "Chen");
Math.random = () => 0.9
assert.deepStrictEqual(application.getRandomPerson(), "Gala");
});

test("Test Application's selectNextPerson", async() => {
const application = new Application
const name_list = await application.getNames();
application.selected = ["Guan"]
let count = 0;
test.mock.method(application, 'getRandomPerson', () => {
if (count <= name_list.length) {
return name_list[0][count++];
}
});
assert.strictEqual(application.selectNextPerson(), "Chen")
assert.strictEqual(application.selectNextPerson(), "Gala")
assert.strictEqual(application.selectNextPerson(), null)
});

test("Test Application's notifySelected() ", () => {
const application = new Application
application.people = ["Guan", "Chen", "Gala"]
application.selected = ["Guan", "Chen", "Gala"]
application.mailSystem.write = test.mock.fn(application.mailSystem.write)
application.mailSystem.send = test.mock.fn(application.mailSystem.send)
application.notifySelected()
assert.strictEqual(application.mailSystem.send.mock.calls.length, application.people.length);
assert.strictEqual(application.mailSystem.write.mock.calls.length, application.people.length);
});
Loading