mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-04-19 11:18:02 +08:00
27 lines
426 B
Rust
27 lines
426 B
Rust
pub fn add_two(a: usize) -> usize {
|
|
a + 2
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn add_two_and_two() {
|
|
let result = add_two(2);
|
|
assert_eq!(result, 4);
|
|
}
|
|
|
|
#[test]
|
|
fn add_three_and_two() {
|
|
let result = add_two(3);
|
|
assert_eq!(result, 5);
|
|
}
|
|
|
|
#[test]
|
|
fn one_hundred() {
|
|
let result = add_two(100);
|
|
assert_eq!(result, 102);
|
|
}
|
|
}
|