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