summaryrefslogtreecommitdiff
path: root/ex4/src/main.rs
diff options
context:
space:
mode:
authorBrad Clawsie <brad@b7j0c.org>2026-10-30 16:25:01 -0500
committerBrad Clawsie <brad@b7j0c.org>2026-10-30 16:25:01 -0500
commit89ce0dd18dcfd33490e341e2b6b97068267db3ea (patch)
tree39e68bb829e14381bdc749a353b0b58006d5cec5 /ex4/src/main.rs
parent44c896e420c4c3dedccfd847b2ede2b05baf41cf (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/src/main.rs')
-rw-r--r--ex4/src/main.rs35
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);
+ }
+}