diff --git a/exercise/exercises/tests/README.md b/exercise/exercises/tests/README.md index 27c6818d..d7bcb406 100644 --- a/exercise/exercises/tests/README.md +++ b/exercise/exercises/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) diff --git a/exercise/exercises/tests/tests1.rs b/exercise/exercises/tests/tests1.rs index 50586a19..820f5abc 100644 --- a/exercise/exercises/tests/tests1.rs +++ b/exercise/exercises/tests/tests1.rs @@ -1,10 +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 -// This test has a problem with it -- make the test compile! Make the test -// pass! Make the test fail! Execute `rustlings hint tests1` for hints :) +// 关于测试还有个问题——如何成功编译测试、通过测试或者使测试失败? +// 执行 `rustlings hint tests1` 获取提示 :) // I AM NOT DONE diff --git a/exercise/exercises/tests/tests2.rs b/exercise/exercises/tests/tests2.rs index 0d981ad1..5617cb1a 100644 --- a/exercise/exercises/tests/tests2.rs +++ b/exercise/exercises/tests/tests2.rs @@ -1,6 +1,6 @@ // 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` for hints :) +// 让测试能够编译然后通过测试和使测试失败! +// 执行 `rustlings hint tests2` 获取提示 :) // I AM NOT DONE diff --git a/exercise/exercises/tests/tests3.rs b/exercise/exercises/tests/tests3.rs index 3424f940..6800ff8c 100644 --- a/exercise/exercises/tests/tests3.rs +++ b/exercise/exercises/tests/tests3.rs @@ -1,8 +1,7 @@ // 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)`. -// Execute `rustlings hint tests3` for hints :) +// 这个测试不是在测试我们的函数——想些方法让它的返回值可以通过测试。 +// 在第二个测试判断调用 `is_even(5)` 是否得到了预期的结果。 +// 执行 `rustlings hint tests3` 获取提示 :) // I AM NOT DONE @@ -15,12 +14,12 @@ mod tests { use super::*; #[test] - fn is_true_when_even() { + fn is_true_when_even() {// 偶数将返回 true assert!(); } #[test] - fn is_false_when_odd() { + fn is_false_when_odd() {// 奇数将返回 false assert!(); } } diff --git a/exercise/info.toml b/exercise/info.toml index aa5e3474..71a9a4d8 100644 --- a/exercise/info.toml +++ b/exercise/info.toml @@ -612,30 +612,28 @@ name = "tests1" path = "exercises/tests/tests1.rs" mode = "test" hint = """ -You don't even need to write any code to test -- you can just test values and run that, even -though you wouldn't do that in real life :) `assert!` is a macro that needs an argument. -Depending on the value of the argument, `assert!` will do nothing (in which case the test will -pass) or `assert!` will panic (in which case the test will fail). So try giving different values -to `assert!` and see which ones compile, which ones pass, and which ones fail :)""" +你甚至不需要写任何用于测试的代码——直接填入某个值然后运行,即使在现实中这样做没什么意义 :) +`assert!` 是需要一个参数的宏。根据参数的值,`assert!` 可能什么也不会发生(这意味将通 +过测试)或者 `assert!` 引发了 panic (测试失败)。所以试着去给 `assert!` 赋予不同的值,看 +看哪些可以编译,哪些能够通过,哪些将造成失败 :)""" [[exercises]] name = "tests2" path = "exercises/tests/tests2.rs" mode = "test" hint = """ -Like the previous exercise, you don't need to write any code to get this test to compile and -run. `assert_eq!` is a macro that takes two arguments and compares them. Try giving it two -values that are equal! Try giving it two arguments that are different! Try giving it two values -that are of different types! Try switching which argument comes first and which comes second!""" +和前面的练习一样,你无需编写任何代码就可以编译和运行这个测试。 +`assert_eq!` 是一个接受两个参数并比较两者的宏。尝试给它两个相等、两个不同的 +值和两个不同类型的值!也不妨试试调换下两个参数的位置""" [[exercises]] name = "tests3" path = "exercises/tests/tests3.rs" mode = "test" hint = """ -You can call a function right where you're passing arguments to `assert!` -- so you could do -something like `assert!(having_fun())`. If you want to check that you indeed get false, you -can negate the result of what you're doing using `!`, like `assert!(!having_fun())`.""" +你可以在 `assert!` 接受参数的位置直接调用一个函数——所以你可以做一些类似于 +`assert!(having_fun())` 的事情。如果你想检查得到的值是不是 false ,可以 +用 `!` 来取反结果,例如 `assert!(!having_fun())`。""" # TEST 3