File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
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 @@ -18,6 +18,6 @@ fn main() {
18
18
( ( iter * 5 ) + 2 ) / ( 4 * 16 )
19
19
} ;
20
20
21
- numbers[ iter] = number_to_add;
21
+ numbers[ iter as usize ] = number_to_add;
22
22
}
23
23
}
Original file line number Diff line number Diff line change @@ -87,6 +87,15 @@ Remember in Rust that:
87
87
- `if`/`else` conditionals are expressions
88
88
- Each condition is followed by a `{}` block."""
89
89
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
+
90
99
# FUNCTIONS
91
100
92
101
[[exercises ]]
You can’t perform that action at this time.
0 commit comments