diff options
| author | Brad Clawsie <brad@b7j0c.org> | 2026-11-05 09:56:04 -0600 |
|---|---|---|
| committer | Brad Clawsie <brad@b7j0c.org> | 2026-11-05 13:18:47 -0600 |
| commit | 15d9096d2452e09756eee0d82a23dd9b7b9ffb9d (patch) | |
| tree | 9c7047b018343aef975e9710a957f3eed234586f /ex5_8 | |
| parent | 0962a0b7416a828a1ebb00337f22b6679f34e233 (diff) | |
| parent | 665dcfc1121c5911478e973d392023213183e6d7 (diff) | |
ex5
Diffstat (limited to 'ex5_8')
| -rw-r--r-- | ex5_8/Cargo.lock | 7 | ||||
| -rw-r--r-- | ex5_8/Cargo.toml | 6 | ||||
| -rw-r--r-- | ex5_8/src/main.rs | 51 |
3 files changed, 64 insertions, 0 deletions
diff --git a/ex5_8/Cargo.lock b/ex5_8/Cargo.lock new file mode 100644 index 0000000..79101dc --- /dev/null +++ b/ex5_8/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ex5_8" +version = "0.1.0" diff --git a/ex5_8/Cargo.toml b/ex5_8/Cargo.toml new file mode 100644 index 0000000..588d06e --- /dev/null +++ b/ex5_8/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "ex5_8" +version = "0.1.0" +edition = "2024" + +[dependencies] 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()))) + } +} |
