Skip to content

[LAB6] 510558017 #524

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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6cc3dcb
Fix failing tests in main_test.js
as10748569 Mar 9, 2024
e8229fc
Fix failing tests in main_test.js
as10748569 Mar 9, 2024
51b2df1
Fix failing tests in main.js
as10748569 Mar 9, 2024
c2ce0d4
Fix failing tests in main.js
as10748569 Mar 10, 2024
24f6d06
Update main_test.js
as10748569 Mar 12, 2024
e9aad93
Update main_test.js
as10748569 Mar 12, 2024
dcd7054
Update main.js
as10748569 Mar 12, 2024
7a26e96
Update main_test.js
as10748569 Mar 13, 2024
b148ebc
Update main_test.js
as10748569 Mar 13, 2024
c5b3ba9
feat: lab2
AlaRduTP Mar 13, 2024
be2cf12
Merge branch '510558017' into 510558017
as10748569 Mar 13, 2024
ff4a4f9
Merge branch 'SQLab:main' into main
as10748569 Mar 13, 2024
e0887b7
Merge pull request #44 from as10748569/510558017
AlaRduTP Mar 17, 2024
f657825
feat: lab3
AlaRduTP Mar 20, 2024
0b0f42d
Merge branch 'SQLab:main' into main
as10748569 Mar 20, 2024
0879aa5
Update main_test.js
as10748569 Mar 27, 2024
70f40d0
Update main_test.js
as10748569 Mar 27, 2024
65dd00b
Delete lab3 directory
as10748569 Mar 27, 2024
a2661bf
Update main_test.js
as10748569 Mar 27, 2024
23a3b2a
Committing local changes
as10748569 Mar 27, 2024
bc15e10
Merge branch 'main' of github.com:as10748569/510558017 into main
as10748569 Mar 27, 2024
f29830f
Merge branch '510558017' of github.com:as10748569/510558017 into main
as10748569 Mar 27, 2024
4ea0c26
Merge branch 'SQLab:main' into main
as10748569 Apr 8, 2024
dac019e
Update main_test.js
as10748569 Apr 8, 2024
e58a89c
Update main_test.js
as10748569 Apr 8, 2024
1344a3d
Update main_test.js
as10748569 Apr 16, 2024
b7322a0
Update main_test.js
as10748569 Apr 16, 2024
aadcbfb
Merge branch 'main' of github.com:as10748569/510558017 into main
as10748569 May 1, 2024
1f97d4e
Merge branch 'SQLab:main' into main
as10748569 May 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 9 additions & 9 deletions lab1/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class Student {
}
}

// const myClass = new MyClass();
// const names = ['John', 'Jane', 'Doe', 'Smith'];
// names.forEach(name => {
// const student = new Student();
// student.setName(name);
// const newStudentId = myClass.addStudent(student);
// const newStudentName = myClass.getStudentById(newStudentId).getName();
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName);
//const myClass = new MyClass();
//const names = ['John', 'Jane', 'Doe', 'Smith'];
//names.forEach(name => {
// const student = new Student();
//student.setName(name);
// const newStudentId = myClass.addStudent(student);
//const newStudentName = myClass.getStudentById(newStudentId).getName();
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName);
// });

module.exports = { MyClass, Student };
module.exports = { MyClass, Student };
36 changes: 27 additions & 9 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,39 @@ const assert = require('assert');
const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const student = new Student();
student.setName("John");
const index = myClass.addStudent(student);
assert.strictEqual(index, 0, "addStudent should return index 0 for the first student");
const notAStudent = {};
const indexForNotAStudent = myClass.addStudent(notAStudent);
assert.strictEqual(indexForNotAStudent, -1, "addStudent should return -1 when adding a non-Student instance");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const student = new Student();
student.setName("Jane");
const index = myClass.addStudent(student);
const fetchedStudent = myClass.getStudentById(index);
assert.strictEqual(fetchedStudent.getName(), "Jane", "getStudentById should retrieve the student with the correct name");
const invalidFetchedStudent = myClass.getStudentById(-1);
assert.strictEqual(invalidFetchedStudent, null, "getStudentById should return null for an invalid id");
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
student.setName("Doe");
assert.strictEqual(student.name, "Doe", "setName should correctly set the student's name");
student.setName(123);
assert.strictEqual(student.name, "Doe", "setName should not set name when the input is not a string");
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
});
const student = new Student();
student.setName("Smith");
assert.strictEqual(student.getName(), "Smith", "getName should return the correct name");
const newStudent = new Student();
assert.strictEqual(newStudent.getName(), '', "getName should return an empty string for a student without a name");
});
64 changes: 62 additions & 2 deletions lab2/main_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,66 @@
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
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);
});
139 changes: 139 additions & 0 deletions lab2/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions lab2/node_modules/@sinonjs/commons/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions lab2/node_modules/@sinonjs/commons/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions lab2/node_modules/@sinonjs/commons/lib/called-in-order.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading