-
Notifications
You must be signed in to change notification settings - Fork 63
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
[LAB1] 312552058 #69
[LAB1] 312552058 #69
Conversation
const test = require('node:test'); //從名為 'node:test' 的模組中引入某些東西,並將其指派給名為 test 的變數 | ||
const assert = require('assert'); | ||
const { MyClass, Student } = require('./main'); | ||
const { MyClass, Student } = require('./main'); //從 require('./main') 返回的物件中,選擇性地取出了兩個成員,分別是 MyClass 和 Student | ||
|
||
test("Test MyClass's addStudent", () => { | ||
// TODO | ||
throw new Error("Test not implemented"); | ||
test("Test MyClass's addStudent", () => { //第一個參數是測試案例的描述或名稱,第二個參數是一個回調函式,其中包含了實際的測試程式碼。() => { ... } 定義了一個不接受任何參數的匿名箭頭函式,其主體包含在花括號 {} 中。這樣的函式可以在需要函式的地方被調用或傳遞,並且它的主體程式碼會在函式被呼叫時執行。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those comments written on your own? If yes, don't leave long comments in your code describing languages' built-in features. It will reduce readability and maintainability.
const invalidstudentIndex = myClass.addStudent(invalidstudent); | ||
assert.strictEqual(invalidstudentIndex, -1); | ||
|
||
//throw new Error("Test not implemented"); //當程式碼執行到 throw 語句時,它將立即停止執行,並拋出一個錯誤 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the comment here.
|
||
const student = new Student(); // 創建 Student 的一個實例 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the comment here
assert.strictEqual(student.getName(), 'Annie'); | ||
//throw new Error("Test not implemented"); | ||
|
||
const invalidName = 123; // 數字不是有效的名字 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an acceptable example because it describes the test case we want to execute.
However, it's better to leave comments in English.
Description
Add tests in main_test.js and reach 100% coverage.