initial commit
This commit is contained in:
44
exercises/05_ticket_v2/02_match/src/lib.rs
Normal file
44
exercises/05_ticket_v2/02_match/src/lib.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
enum Shape {
|
||||
Circle,
|
||||
Square,
|
||||
Rectangle,
|
||||
Triangle,
|
||||
Pentagon,
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
// TODO: Implement the `n_sides` method using a `match`.
|
||||
pub fn n_sides(&self) -> u8 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_circle() {
|
||||
assert_eq!(Shape::Circle.n_sides(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_square() {
|
||||
assert_eq!(Shape::Square.n_sides(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rectangle() {
|
||||
assert_eq!(Shape::Rectangle.n_sides(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_triangle() {
|
||||
assert_eq!(Shape::Triangle.n_sides(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pentagon() {
|
||||
assert_eq!(Shape::Pentagon.n_sides(), 5);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user