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

[LAB1] 312552058 #69

Merged
merged 3 commits into from
Mar 7, 2024
Merged

[LAB1] 312552058 #69

merged 3 commits into from
Mar 7, 2024

Conversation

annieronna
Copy link

@annieronna annieronna commented Mar 5, 2024

Description

Add tests in main_test.js and reach 100% coverage.

  • A clear title (name your pr "[LAB{lab_number}] {your_student_id}")
  • A meaningful message for PR, as well as its commits
  • From your specific branch (not main or other's branch) merging to your branch
  • Excluding any irrelevant files, such as binaries, text files, or dot files
  • Passing tests/CI

@TaiYou-TW TaiYou-TW added the lab1 label Mar 5, 2024
@TaiYou-TW TaiYou-TW added lab1 and removed lab1 labels Mar 5, 2024
@TaiYou-TW TaiYou-TW merged commit 15b457d into SQLab:312552058 Mar 7, 2024
1 check passed
Comment on lines +1 to +5
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", () => { //第一個參數是測試案例的描述或名稱,第二個參數是一個回調函式,其中包含了實際的測試程式碼。() => { ... } 定義了一個不接受任何參數的匿名箭頭函式,其主體包含在花括號 {} 中。這樣的函式可以在需要函式的地方被調用或傳遞,並且它的主體程式碼會在函式被呼叫時執行。
Copy link
Contributor

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 語句時,它將立即停止執行,並拋出一個錯誤
Copy link
Contributor

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 的一個實例
Copy link
Contributor

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; // 數字不是有效的名字
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants