1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
fn prints_and_returns_10(a: i32) -> i32 { println!("I got the value {}", a); 10 } pub fn add_two(a: i32) -> i32 { a + 2 } #[cfg(test)] mod tests { use super::*; // #[test] // fn this_test_will_pass() { // let value = prints_and_returns_10(4); // assert_eq!(10, value); // } // // #[test] // fn this_test_will_fail() { // let value = prints_and_returns_10(8); // assert_eq!(5, value); // } // #[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() { // // 需要运行一个小时的代码 // } }