From 89ce0dd18dcfd33490e341e2b6b97068267db3ea Mon Sep 17 00:00:00 2001 From: Brad Clawsie Date: Fri, 30 Oct 2026 16:25:01 -0500 Subject: feat: ex4 commit 9b69f37c5ba66b71830a1898e9c2a613f2b34487 Author: Brad Clawsie Date: Fri Oct 30 16:22:08 2026 -0500 feat: ex4 --- ex4/Cargo.lock | 7 +++++++ ex4/Cargo.toml | 6 ++++++ ex4/src/main.rs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 ex4/Cargo.lock create mode 100644 ex4/Cargo.toml create mode 100644 ex4/src/main.rs (limited to 'ex4') 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); + } +} -- cgit v1.2.3