summaryrefslogtreecommitdiff
path: root/ex5_2/src/main.rs
blob: 14def70af108b769b53164f2646ac1905e5a329a (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
36
37
enum Shape {
    Circle,
    Square,
    Rectangle,
    Triangle,
    Pentagon,
}

impl Shape {
    fn n_sides(&self) -> u8 {
        match self {
            Self::Circle => 1,
            Self::Square => 4,
            Self::Rectangle => 4,
            Self::Triangle => 3,
            Self::Pentagon => 5,
        }
    }
}

fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn t0 () {
        assert_eq!(Shape::Circle.n_sides(), 1);
        assert_eq!(Shape::Square.n_sides(), 4);
        assert_eq!(Shape::Rectangle.n_sides(), 4);
        assert_eq!(Shape::Triangle.n_sides(), 3);
        assert_eq!(Shape::Pentagon.n_sides(), 5);
    }
}