Merge pull request #346 from mg-chao/20220127_translate_tests

[rust-exercise] 翻译 tests 部分
pull/351/head
Sunface 3 years ago committed by GitHub
commit 5536c6b39c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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) - [Writing Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html)

@ -1,10 +1,10 @@
// tests1.rs // 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` for hints :) // 执行 `rustlings hint tests1` 获取提示 :)
// I AM NOT DONE // I AM NOT DONE

@ -1,6 +1,6 @@
// tests2.rs // 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 // I AM NOT DONE

@ -1,8 +1,7 @@
// tests3.rs // 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 // 在第二个测试判断调用 `is_even(5)` 是否得到了预期的结果。
// we expect to get when we call `is_even(5)`. // 执行 `rustlings hint tests3` 获取提示 :)
// Execute `rustlings hint tests3` for hints :)
// I AM NOT DONE // I AM NOT DONE
@ -15,12 +14,12 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn is_true_when_even() { fn is_true_when_even() {// 偶数将返回 true
assert!(); assert!();
} }
#[test] #[test]
fn is_false_when_odd() { fn is_false_when_odd() {// 奇数将返回 false
assert!(); assert!();
} }
} }

@ -612,30 +612,28 @@ name = "tests1"
path = "exercises/tests/tests1.rs" path = "exercises/tests/tests1.rs"
mode = "test" mode = "test"
hint = """ 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. `assert!` `assert!`
Depending on the value of the argument, `assert!` will do nothing (in which case the test will `assert!` panic `assert!`
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 :)"""
[[exercises]] [[exercises]]
name = "tests2" name = "tests2"
path = "exercises/tests/tests2.rs" path = "exercises/tests/tests2.rs"
mode = "test" mode = "test"
hint = """ 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 `assert_eq!`
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!"""
[[exercises]] [[exercises]]
name = "tests3" name = "tests3"
path = "exercises/tests/tests3.rs" path = "exercises/tests/tests3.rs"
mode = "test" mode = "test"
hint = """ hint = """
You can call a function right where you're passing arguments to `assert!` -- so you could do `assert!`
something like `assert!(having_fun())`. If you want to check that you indeed get false, you `assert!(having_fun())` false
can negate the result of what you're doing using `!`, like `assert!(!having_fun())`.""" `!` `assert!(!having_fun())`"""
# TEST 3 # TEST 3

Loading…
Cancel
Save