mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-24 14:37:32 -05:00
if2 solution
This commit is contained in:
parent
7cdf6b7942
commit
eafb157d60
3 changed files with 41 additions and 7 deletions
|
@ -1,6 +1,4 @@
|
||||||
// Step 1: Make me compile!
|
// TODO: Fix the compiler error on this function.
|
||||||
// Step 2: Get the bar_for_fuzz and default_to_baz tests passing!
|
|
||||||
|
|
||||||
fn foo_if_fizz(fizzish: &str) -> &str {
|
fn foo_if_fizz(fizzish: &str) -> &str {
|
||||||
if fizzish == "fizz" {
|
if fizzish == "fizz" {
|
||||||
"foo"
|
"foo"
|
||||||
|
@ -13,13 +11,15 @@ fn main() {
|
||||||
// You can optionally experiment here.
|
// You can optionally experiment here.
|
||||||
}
|
}
|
||||||
|
|
||||||
// No test changes needed!
|
// TODO: Read the tests to understand the desired behavior.
|
||||||
|
// Make all tests pass without changing them.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn foo_for_fizz() {
|
fn foo_for_fizz() {
|
||||||
|
// This means that calling `foo_if_fizz` with the argument "fizz" should return "foo".
|
||||||
assert_eq!(foo_if_fizz("fizz"), "foo");
|
assert_eq!(foo_if_fizz("fizz"), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,8 +209,10 @@ name = "if2"
|
||||||
dir = "03_if"
|
dir = "03_if"
|
||||||
hint = """
|
hint = """
|
||||||
For that first compiler error, it's important in Rust that each conditional
|
For that first compiler error, it's important in Rust that each conditional
|
||||||
block returns the same type! To get the tests passing, you will need a couple
|
block returns the same type!
|
||||||
conditions checking different input values."""
|
|
||||||
|
To get the tests passing, you will need a couple conditions checking different
|
||||||
|
input values. Read the tests to find out what they expect."""
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "if3"
|
name = "if3"
|
||||||
|
|
|
@ -1 +1,33 @@
|
||||||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
fn foo_if_fizz(fizzish: &str) -> &str {
|
||||||
|
if fizzish == "fizz" {
|
||||||
|
"foo"
|
||||||
|
} else if fizzish == "fuzz" {
|
||||||
|
"bar"
|
||||||
|
} else {
|
||||||
|
"baz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// You can optionally experiment here.
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn foo_for_fizz() {
|
||||||
|
assert_eq!(foo_if_fizz("fizz"), "foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bar_for_fuzz() {
|
||||||
|
assert_eq!(foo_if_fizz("fuzz"), "bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn default_to_baz() {
|
||||||
|
assert_eq!(foo_if_fizz("literally anything"), "baz");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue