trpl-zh-cn/listings/ch11-writing-automated-tests/no-listing-10-result-in-tests/src/lib.rs
2024-08-29 16:56:25 +08:00

22 lines
389 B
Rust

pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
// ANCHOR: here
#[test]
fn it_works() -> Result<(), String> {
let result = add(2, 2);
if result == 4 {
Ok(())
} else {
Err(String::from("two plus two does not equal four"))
}
}
// ANCHOR_END: here
}