diff options
| author | Brad Clawsie <brad@b7j0c.org> | 2026-11-05 09:06:41 -0600 |
|---|---|---|
| committer | Brad Clawsie <brad@b7j0c.org> | 2026-11-05 09:06:41 -0600 |
| commit | 665dcfc1121c5911478e973d392023213183e6d7 (patch) | |
| tree | be5f0af0ea13a5b0943a4d7af1db324f21be9153 /ex5_8/src | |
| parent | e6922247c0380dc8a9e9faac4c9a53d3f281bb36 (diff) | |
feat: ex5_8
commit b01fcdd319af81c789c5cda7a590babb501117c9
Author: Brad Clawsie <brad@b7j0c.org>
Date: Thu Nov 5 09:06:25 2026 -0600
feat: ex5_8
Diffstat (limited to 'ex5_8/src')
| -rw-r--r-- | ex5_8/src/main.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/ex5_8/src/main.rs b/ex5_8/src/main.rs new file mode 100644 index 0000000..1820d19 --- /dev/null +++ b/ex5_8/src/main.rs @@ -0,0 +1,51 @@ +#[derive(Debug, PartialEq)] +enum E { + Err1, + Err2, + Err3(String), +} + +fn f(i: u32) -> Result<u32, E> { + if i == 0 { + return Ok(i); + } + if i == 1 { + return Err(E::Err1); + } + if i == 2 { + return Err(E::Err2); + } + if i == 3 { + return Err(E::Err3(String::from("Err3"))); + } + Ok(99) +} + +fn main() { + println!("Hello, world!"); +} + +#[cfg(test)] +mod tests { + use crate::*; + + #[test] + fn t0() { + assert_eq!(f(0 as u32), Ok(0 as u32)); + } + + #[test] + fn t1() { + assert_eq!(f(1 as u32), Err(E::Err1)); + } + + #[test] + fn t2() { + assert_eq!(f(2 as u32), Err(E::Err2)); + } + + #[test] + fn t3() { + assert_eq!(f(3 as u32), Err(E::Err3("Err3".to_string()))) + } +} |
