summaryrefslogtreecommitdiff
path: root/ex4/src/main.rs
blob: 3c2e63f6d79e4ca19f52046f179d781b84d151c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
    }
}