mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 14:13:28 +08:00
Initial commit.
This commit is contained in:
8
assert_demo/Cargo.toml
Normal file
8
assert_demo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "assert_demo"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
43
assert_demo/src/lib.rs
Normal file
43
assert_demo/src/lib.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
pub fn add_two(a: i32) -> i32 {
|
||||
a + 2
|
||||
}
|
||||
|
||||
pub fn nth_fibonacci(n: u64) -> u64 {
|
||||
|
||||
if n == 0 || n == 1 {
|
||||
return n;
|
||||
} else {
|
||||
return nth_fibonacci(n - 1) + nth_fibonacci(n - 2);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn add_two_and_two() {
|
||||
assert_eq! (4, add_two(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_three_and_two() {
|
||||
assert_eq! (5, add_two(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_hundred() {
|
||||
assert_eq! (102, add_two(100));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq! (2 + 2, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn expensive_test() {
|
||||
assert_ne! (100, nth_fibonacci(50));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user