update: translate tests

pull/346/head
mg-chao 3 years ago
parent 15905ea11a
commit 854cff1149

@ -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)

@ -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

@ -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

@ -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!();
}
}

@ -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

Loading…
Cancel
Save