initial commit
This commit is contained in:
4
exercises/05_ticket_v2/04_if_let/Cargo.toml
Normal file
4
exercises/05_ticket_v2/04_if_let/Cargo.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "if_let"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
39
exercises/05_ticket_v2/04_if_let/src/lib.rs
Normal file
39
exercises/05_ticket_v2/04_if_let/src/lib.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
enum Shape {
|
||||
Circle { radius: f64 },
|
||||
Square { border: f64 },
|
||||
Rectangle { width: f64, height: f64 },
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
// TODO: Implement the `radius` method using
|
||||
// either an `if let` or a `let/else`.
|
||||
pub fn radius(&self) -> f64 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_circle() {
|
||||
let _ = Shape::Circle { radius: 1.0 }.radius();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_square() {
|
||||
let _ = Shape::Square { border: 1.0 }.radius();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_rectangle() {
|
||||
let _ = Shape::Rectangle {
|
||||
width: 1.0,
|
||||
height: 2.0,
|
||||
}
|
||||
.radius();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user