mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Compare commits
4 commits
1bae2dcb00
...
64b2f18d92
Author | SHA1 | Date | |
---|---|---|---|
64b2f18d92 | |||
2894f3c45c | |||
b540c6df25 | |||
9a25309c1c |
|
@ -1,7 +1,7 @@
|
||||||
// TODO: Fix the compiler error on this function.
|
// TODO: Fix the compiler error on this function.
|
||||||
fn foo_if_fizz(fizzish: &str) -> &str {
|
fn picky_eater(food: &str) -> &str {
|
||||||
if fizzish == "fizz" {
|
if food == "strawberry" {
|
||||||
"foo"
|
"Yummy!"
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,20 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn foo_for_fizz() {
|
fn yummy_food() {
|
||||||
// This means that calling `foo_if_fizz` with the argument "fizz" should return "foo".
|
// This means that calling `picky_eater` with the argument "food" should return "Yummy!".
|
||||||
assert_eq!(foo_if_fizz("fizz"), "foo");
|
assert_eq!(picky_eater("strawberry"), "Yummy!");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bar_for_fuzz() {
|
fn neutral_food() {
|
||||||
assert_eq!(foo_if_fizz("fuzz"), "bar");
|
assert_eq!(picky_eater("potato"), "I guess I can eat that.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_to_baz() {
|
fn default_disliked_food() {
|
||||||
assert_eq!(foo_if_fizz("literally anything"), "baz");
|
assert_eq!(picky_eater("broccoli"), "No thanks!");
|
||||||
|
assert_eq!(picky_eater("gummy bears"), "No thanks!");
|
||||||
|
assert_eq!(picky_eater("literally anything"), "No thanks!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,11 @@ struct Point {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Message {
|
enum Message {
|
||||||
// TODO: Implement the message variant types based on their usage below.
|
Resize { width: u64, height: u64 },
|
||||||
|
Move(Point),
|
||||||
|
Echo(String),
|
||||||
|
ChangeColor(u8, u8, u8),
|
||||||
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
fn foo_if_fizz(fizzish: &str) -> &str {
|
fn picky_eater(food: &str) -> &str {
|
||||||
if fizzish == "fizz" {
|
if food == "strawberry" {
|
||||||
"foo"
|
"Yummy!"
|
||||||
} else if fizzish == "fuzz" {
|
} else if food == "potato" {
|
||||||
"bar"
|
"I guess I can eat that."
|
||||||
} else {
|
} else {
|
||||||
"baz"
|
"No thanks!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,17 +17,19 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn foo_for_fizz() {
|
fn yummy_food() {
|
||||||
assert_eq!(foo_if_fizz("fizz"), "foo");
|
assert_eq!(picky_eater("strawberry"), "Yummy!");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bar_for_fuzz() {
|
fn neutral_food() {
|
||||||
assert_eq!(foo_if_fizz("fuzz"), "bar");
|
assert_eq!(picky_eater("potato"), "I guess I can eat that.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_to_baz() {
|
fn default_disliked_food() {
|
||||||
assert_eq!(foo_if_fizz("literally anything"), "baz");
|
assert_eq!(picky_eater("broccoli"), "No thanks!");
|
||||||
|
assert_eq!(picky_eater("gummy bears"), "No thanks!");
|
||||||
|
assert_eq!(picky_eater("literally anything"), "No thanks!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue