File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ // if2.rs
2+
3+ // Step 1: Make me compile!
4+ // Step 2: Get the bar_for_fuzz and default_to_baz tests passing!
5+ // Execute the command `rustlings hint if2` if you want a hint :)
6+
7+ // I AM NOT DONE
8+
9+ pub fn fizz_if_foo ( fizzish : & str ) -> & str {
10+ if fizzish == "fizz" {
11+ "foo"
12+ } else {
13+ 1
14+ }
15+ }
16+
17+ // No test changes needed!
18+ #[ cfg( test) ]
19+ mod tests {
20+ use super :: * ;
21+
22+ #[ test]
23+ fn foo_for_fizz ( ) {
24+ assert_eq ! ( fizz_if_foo( "fizz" ) , "foo" )
25+ }
26+
27+ #[ test]
28+ fn bar_for_fuzz ( ) {
29+ assert_eq ! ( fizz_if_foo( "fuzz" ) , "bar" )
30+ }
31+
32+ #[ test]
33+ fn default_to_baz ( ) {
34+ assert_eq ! ( fizz_if_foo( "literally anything" ) , "baz" )
35+ }
36+ }
Original file line number Diff line number Diff line change @@ -87,6 +87,15 @@ Remember in Rust that:
8787- `if`/`else` conditionals are expressions
8888- Each condition is followed by a `{}` block."""
8989
90+ [[exercises ]]
91+ name = " if2"
92+ path = " exercises/if/if2.rs"
93+ mode = " test"
94+ hint = """
95+ For that first compiler error, it's important in Rust that each conditional
96+ block return the same type! To get the tests passing, you will need a couple
97+ conditions checking different input values."""
98+
9099# FUNCTIONS
91100
92101[[exercises ]]
You can’t perform that action at this time.
0 commit comments