mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-05-15 09:48:45 +00:00
Make starting fireworks more fun :)
This commit is contained in:
parent
7c1d8ebf49
commit
346753b673
@ -22,13 +22,7 @@ fn add_rockets(fireworks: &mut Fireworks, rockets: usize) {
|
|||||||
|
|
||||||
// TODO: Turn this function into a method on `Fireworks`.
|
// TODO: Turn this function into a method on `Fireworks`.
|
||||||
fn start(fireworks: Fireworks) -> String {
|
fn start(fireworks: Fireworks) -> String {
|
||||||
if fireworks.rockets < 5 {
|
"🚀".repeat(fireworks.rockets)
|
||||||
String::from("small")
|
|
||||||
} else if fireworks.rockets < 20 {
|
|
||||||
String::from("medium")
|
|
||||||
} else {
|
|
||||||
String::from("big")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -41,18 +35,17 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn start_some_fireworks() {
|
fn start_some_fireworks() {
|
||||||
|
let f = Fireworks::new();
|
||||||
|
assert_eq!(f.start(), "");
|
||||||
|
|
||||||
let mut f = Fireworks::new();
|
let mut f = Fireworks::new();
|
||||||
f.add_rockets(3);
|
f.add_rockets(3);
|
||||||
assert_eq!(f.start(), "small");
|
assert_eq!(f.start(), "🚀🚀🚀");
|
||||||
|
|
||||||
let mut f = Fireworks::new();
|
let mut f = Fireworks::new();
|
||||||
f.add_rockets(15);
|
f.add_rockets(7);
|
||||||
assert_eq!(f.start(), "medium");
|
|
||||||
|
|
||||||
let mut f = Fireworks::new();
|
|
||||||
f.add_rockets(100);
|
|
||||||
// We don't use method syntax in the last test to ensure the `start`
|
// We don't use method syntax in the last test to ensure the `start`
|
||||||
// function takes ownership of the fireworks.
|
// function takes ownership of the fireworks.
|
||||||
assert_eq!(Fireworks::start(f), "big");
|
assert_eq!(Fireworks::start(f), "🚀🚀🚀🚀🚀🚀🚀");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,13 +15,7 @@ impl Fireworks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start(self) -> String {
|
fn start(self) -> String {
|
||||||
if self.rockets < 5 {
|
"🚀".repeat(self.rockets)
|
||||||
String::from("small")
|
|
||||||
} else if self.rockets < 20 {
|
|
||||||
String::from("medium")
|
|
||||||
} else {
|
|
||||||
String::from("big")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,18 +29,17 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn start_some_fireworks() {
|
fn start_some_fireworks() {
|
||||||
|
let f = Fireworks::new();
|
||||||
|
assert_eq!(f.start(), "");
|
||||||
|
|
||||||
let mut f = Fireworks::new();
|
let mut f = Fireworks::new();
|
||||||
f.add_rockets(3);
|
f.add_rockets(3);
|
||||||
assert_eq!(f.start(), "small");
|
assert_eq!(f.start(), "🚀🚀🚀");
|
||||||
|
|
||||||
let mut f = Fireworks::new();
|
let mut f = Fireworks::new();
|
||||||
f.add_rockets(15);
|
f.add_rockets(7);
|
||||||
assert_eq!(f.start(), "medium");
|
|
||||||
|
|
||||||
let mut f = Fireworks::new();
|
|
||||||
f.add_rockets(100);
|
|
||||||
// We don't use method syntax in the last test to ensure the `start`
|
// We don't use method syntax in the last test to ensure the `start`
|
||||||
// function takes ownership of the fireworks.
|
// function takes ownership of the fireworks.
|
||||||
assert_eq!(Fireworks::start(f), "big");
|
assert_eq!(Fireworks::start(f), "🚀🚀🚀🚀🚀🚀🚀");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user