# assertion
說明 assertion 詞彙的相關意思與實務中的使用方式
<https://hackmd.io/@hacktionary/term-assertion>
## 內容大綱
[TOC]
## <ruby>名詞<rp>(</rp><rt>Noun</rt><rp>)</rp></ruby>
### 斷言
#### 例句
> But what commands do we put in the `check` rule? Well, jupiter is a pretty simple program--it prints out a message, "Hello from jupiter!", where is variable, depending on the location from which jupiter was executed. We could check to see that jupiter actually does output such a string. We'll use the `grep` utility to test our **assertion**:
> 但我們需要在 `check` 規則中放入什麼命令呢?jupitor 是個相當簡單的程式——它印出一個根據 jupitor 被執行之位置而定之可變的「Hello from jupitor!」訊息。我們可以檢查以確認 jupitor 是否真的輸出類似的字串。我們將使用 `grep` 工具以測試我們的 **斷言** 是否為真:
> ——摘錄自 [Unit testing anyone? | Chapter 2: Project management and the GNU coding standards](http://freesoftwaremagazine.com/articles/gnu_coding_standards_applied_to_autotools/)
[OpenAI 平台(gpt-4-turbo)參考翻譯與詞彙在情境中的說明](https://platform.openai.com/playground/p/5cTvrp2BKu6BuJzXwsm1ytWw?mode=chat):
> 但我們應該在 `check` 規則中輸入什麼指令呢?jupiter 是一個非常簡單的程序──它輸出一個訊息,「Hello from jupiter!」,其中包含一個依執行 jupiter 的位置而變化的變數。我們可以檢查看看 jupiter 是否真的有輸出這樣的字串。我們將使用 `grep` 工具來測試我們的**斷言**:
>
> 在這段文字中,「**斷言**」指的是在程式中設定一個預期的條件或結果,確保程序在這一點上的行為符合預期。斷言是一種常見的測試手段,用於確認程序的某部分是否如預期般正確執行。在本例中,使用 `grep` 來檢查 jupiter 程序的輸出是否包含特定的字串,即是實現斷言的方式。通过这种方式,我们可以验证程序输出是否正确,确保程序功能的准确性和可靠性。
Google Gemini(2.0 Flash) 參考翻譯與詞彙在情境中的說明:
> 翻譯:
>
> 「但我們要在 `check` 規則中放入什麼指令呢?嗯,jupiter 是一個相當簡單的程式——它會印出一則訊息,「Hello from jupiter!」,其中的變數取決於 jupiter 執行的位置。我們可以檢查 jupiter 是否確實輸出這樣的字串。我們將使用 `grep` 工具來測試我們的**斷言**。」
>
> 解釋:
>
> 在原文中,強調的詞語 "**assertion**" 指的是「斷言」。在這裡,它指的是一種聲明或主張,即「jupiter 程式應該輸出特定格式的字串」。具體來說,作者們想要確認他們的程式確實按照預期運作,因此他們提出了一個主張(斷言):程式會輸出包含 "Hello from jupiter!" 的字串。然後,他們使用 `grep` 工具來驗證這個主張是否為真。
>
> 在程式設計和測試中,「斷言」通常用於驗證程式的行為是否符合預期。如果斷言為真,則表示程式的行為符合預期;如果斷言為假,則表示程式可能存在錯誤。
## 參考資料
以下第三方資料於撰寫本詞彙條目期間被參考到:
* [斷言 - 萌典](https://www.moedict.tw/%E6%96%B7%E8%A8%80)
說明「斷言」詞彙的可能含意(採用「1. [十分](https://www.moedict.tw/#十分)[肯定](https://www.moedict.tw/#肯定)[的](https://www.moedict.tw/#的)[說](https://www.moedict.tw/#說)。」釋義)。
---
本文件為[《Hacktionary》專案](https://hackmd.io/@hacktionary/home)的衍生作品,以[《Creative Commons 姓名標示-相同方式分享》授權條款第 4.0 國際版](https://creativecommons.org/licenses/by-sa/4.0/deed.zh_TW)或其任意更近期版本釋出供大眾於授權範圍內自由使用
如參與本平台的內容實作視同為將您的內容以相同授權條款釋出
部份內容為基於合理使用(fair use)原則使用,使用方式請參閱其註明之來源與作者
<style>
/* 調大旁註文字的字元大小 */
rt{
font-size: 10pt;
}
</style>