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