diff options
Diffstat (limited to 'ex4/src/main.rs')
| -rw-r--r-- | ex4/src/main.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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); + } +} |
