From afad4b96019d0a6523e4b8caa291c2f7a1c93b89 Mon Sep 17 00:00:00 2001 From: TimLai666 <43640816+TimLai666@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BF=BB=E8=AD=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/17_tests/README.md | 8 ++++---- exercises/17_tests/tests1.rs | 10 +++------- exercises/17_tests/tests2.rs | 6 ++---- exercises/17_tests/tests3.rs | 7 ++----- exercises/17_tests/tests4.rs | 19 +++++++++---------- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/exercises/17_tests/README.md b/exercises/17_tests/README.md index 27c6818d..7b3a9980 100644 --- a/exercises/17_tests/README.md +++ b/exercises/17_tests/README.md @@ -1,7 +1,7 @@ -# Tests +# 測試 -Going out of order from the book to cover tests -- many of the following exercises will ask you to make tests pass! +與官方教學的順序不同,我們會先介紹測試——接下來的許多練習會要求您通過測試! -## Further information +## 進一步了解 -- [Writing Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) +- [撰寫測試](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) diff --git a/exercises/17_tests/tests1.rs b/exercises/17_tests/tests1.rs index 810277ac..95f62d93 100644 --- a/exercises/17_tests/tests1.rs +++ b/exercises/17_tests/tests1.rs @@ -1,14 +1,10 @@ // tests1.rs // -// Tests are important to ensure that your code does what you think it should -// do. Tests can be run on this file with the following command: rustlings run -// tests1 +// 測試對於確保您的程式碼執行您認為它應該執行的操作非常重要。可以使用以下命令運行此文件上的測試:rustlings run tests1 // -// This test has a problem with it -- make the test compile! Make the test pass! -// Make the test fail! +// 這個測試有問題——請先讓測試編譯通過,然後讓測試成功,再故意讓測試失敗,以熟悉測試操作。 // -// Execute `rustlings hint tests1` or use the `hint` watch subcommand for a -// hint. +// 執行 `rustlings hint tests1` 或使用 `hint` 子命令獲取提示。 // I AM NOT DONE diff --git a/exercises/17_tests/tests2.rs b/exercises/17_tests/tests2.rs index f8024e9f..d84dbad9 100644 --- a/exercises/17_tests/tests2.rs +++ b/exercises/17_tests/tests2.rs @@ -1,10 +1,8 @@ // tests2.rs // -// This test has a problem with it -- make the test compile! Make the test pass! -// Make the test fail! +// 這個測試有問題——請先讓測試編譯通過,然後讓測試成功,再故意讓測試失敗,以熟悉測試操作。 // -// Execute `rustlings hint tests2` or use the `hint` watch subcommand for a -// hint. +// 執行 `rustlings hint tests2` 或使用 `hint` 子命令獲取提示。 // I AM NOT DONE diff --git a/exercises/17_tests/tests3.rs b/exercises/17_tests/tests3.rs index 4013e384..9d65bad5 100644 --- a/exercises/17_tests/tests3.rs +++ b/exercises/17_tests/tests3.rs @@ -1,11 +1,8 @@ // tests3.rs // -// This test isn't testing our function -- make it do that in such a way that -// the test passes. Then write a second test that tests whether we get the -// result we expect to get when we call `is_even(5)`. +// 這個測試沒有測試我們的函數——讓它以一種通過測試的方式來測試函數。然後寫第二個測試,測試當我們調用 `is_even(5)` 時是否得到預期的結果。 // -// Execute `rustlings hint tests3` or use the `hint` watch subcommand for a -// hint. +// 執行 `rustlings hint tests3` 或使用 `hint` 子命令獲取提示。 // I AM NOT DONE diff --git a/exercises/17_tests/tests4.rs b/exercises/17_tests/tests4.rs index 935d0db1..9cb5883d 100644 --- a/exercises/17_tests/tests4.rs +++ b/exercises/17_tests/tests4.rs @@ -1,9 +1,8 @@ // tests4.rs // -// Make sure that we're testing for the correct conditions! +// 確保我們正在測試正確的條件! // -// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a -// hint. +// 執行 `rustlings hint tests4` 或使用 `hint` 子命令獲取提示。 // I AM NOT DONE @@ -13,10 +12,10 @@ struct Rectangle { } impl Rectangle { - // Only change the test functions themselves + // 只需更改測試函數本身 pub fn new(width: i32, height: i32) -> Self { if width <= 0 || height <= 0 { - panic!("Rectangle width and height cannot be negative!") + panic!("矩形的寬度和高度不能為負數!") } Rectangle {width, height} } @@ -28,21 +27,21 @@ mod tests { #[test] fn correct_width_and_height() { - // This test should check if the rectangle is the size that we pass into its constructor + // 這個測試應該檢查矩形的大小是否與我們傳遞給構造函數的大小相同 let rect = Rectangle::new(10, 20); - assert_eq!(???, 10); // check width - assert_eq!(???, 20); // check height + assert_eq!(???, 10); // 檢查寬度 + assert_eq!(???, 20); // 檢查高度 } #[test] fn negative_width() { - // This test should check if program panics when we try to create rectangle with negative width + // 這個測試應該檢查當我們嘗試創建寬度為負數的矩形時程式是否會恐慌 let _rect = Rectangle::new(-10, 10); } #[test] fn negative_height() { - // This test should check if program panics when we try to create rectangle with negative height + // 這個測試應該檢查當我們嘗試創建高度為負數的矩形時程式是否會恐慌 let _rect = Rectangle::new(10, -10); } }