Skip to content

[LAB1] 511558007 #25

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

Merged
merged 4 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 53 additions & 5 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,70 @@ const test = require('node:test');
const assert = require('assert');
const { MyClass, Student } = require('./main');

const myclass = new MyClass();
const alpha = new Student();
alpha.setName('alpha');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
// 課堂上沒有人
assert.strictEqual(myclass.students.length, 0);

// 如果添加不是來自學生
assert.strictEqual(myclass.addStudent("student"), -1);

// 從學生加入學生
myclass.addStudent(alpha);
assert.strictEqual(myclass.students.length, 1);


// throw new Error("Test not implemented");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");

// 學生不存在
assert.strictEqual(myclass.getStudentById(10), null);

// 學生存在
assert.strictEqual(myclass.getStudentById(0), alpha);

// ID 不是數字
assert.strictEqual(myclass.getStudentById("alpha"), undefined);

// id為負數
assert.strictEqual(myclass.getStudentById(-1), null);


//throw new Error("Test not implemented");
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
let beta = new Student();

// 名稱不是字串
beta.setName(123);
assert.strictEqual(beta.name, undefined);

// 名稱是字串
beta.setName("beta");
assert.strictEqual(beta.name, "beta");

//throw new Error("Test not implemented");
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
});

let gama = new Student();
// 名稱未設定
assert.strictEqual(gama.getName(), "");

// 名稱已設定
gama.setName("gama");
assert.strictEqual(gama.getName(), "gama");

//throw new Error("Test not implemented");
});
4 changes: 2 additions & 2 deletions lab2/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const test = require('node:test');
const assert = require('assert');
const { Application, MailSystem } = require('./main');

// TODO: write your tests here
// Remember to use Stub, Mock, and Spy when necessary
TODO: write your tests here
Remember to use Stub, Mock, and Spy when necessary