diff options
| author | Brad Clawsie <brad@b7j0c.org> | 2026-10-30 16:25:01 -0500 |
|---|---|---|
| committer | Brad Clawsie <brad@b7j0c.org> | 2026-10-30 16:25:01 -0500 |
| commit | 89ce0dd18dcfd33490e341e2b6b97068267db3ea (patch) | |
| tree | 39e68bb829e14381bdc749a353b0b58006d5cec5 /ex4 | |
| parent | 44c896e420c4c3dedccfd847b2ede2b05baf41cf (diff) | |
feat: ex4
commit 9b69f37c5ba66b71830a1898e9c2a613f2b34487
Author: Brad Clawsie <brad@b7j0c.org>
Date: Fri Oct 30 16:22:08 2026 -0500
feat: ex4
Diffstat (limited to 'ex4')
| -rw-r--r-- | ex4/Cargo.lock | 7 | ||||
| -rw-r--r-- | ex4/Cargo.toml | 6 | ||||
| -rw-r--r-- | ex4/src/main.rs | 35 |
3 files changed, 48 insertions, 0 deletions
diff --git a/ex4/Cargo.lock b/ex4/Cargo.lock new file mode 100644 index 0000000..fb485de --- /dev/null +++ b/ex4/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ex4" +version = "0.1.0" diff --git a/ex4/Cargo.toml b/ex4/Cargo.toml new file mode 100644 index 0000000..0aff052 --- /dev/null +++ b/ex4/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "ex4" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/ex4/src/main.rs b/ex4/src/main.rs new file mode 100644 index 0000000..3c2e63f --- /dev/null +++ b/ex4/src/main.rs @@ -0,0 +1,35 @@ +fn velocity(start: u32, end: u32, time_elapsed: u32) -> u32 { + if time_elapsed == 0 { + panic!("time_elapsed is zero"); + } + if end < start { + panic!("end < start"); + } + end - start / time_elapsed +} + +fn main() { + println!("{}", velocity(1,2,1)); +} + +#[cfg(test)] +mod tests { + use crate::velocity; + + #[test] + #[should_panic(expected="time_elapsed is zero")] + fn t0 () { + velocity(1,2,0); + } + + #[test] + #[should_panic(expected="end < start")] + fn t1 () { + velocity(2,1,1); + } + + #[test] + fn t2 () { + assert_eq!(velocity(1,1,1), 0); + } +} |
