mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
if1 solution
This commit is contained in:
parent
3bb71c6b0c
commit
c8ad6c3960
|
@ -200,9 +200,9 @@ Some similar examples from other languages:
|
|||
- In Python this would be: `a if a > b else b`
|
||||
|
||||
Remember in Rust that:
|
||||
- the `if` condition does not need to be surrounded by parentheses
|
||||
- The `if` condition does not need to be surrounded by parentheses
|
||||
- `if`/`else` conditionals are expressions
|
||||
- Each condition is followed by a `{}` block."""
|
||||
- Each condition is followed by a `{}` block"""
|
||||
|
||||
[[exercises]]
|
||||
name = "if2"
|
||||
|
|
|
@ -1 +1,32 @@
|
|||
// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
|
||||
fn bigger(a: i32, b: i32) -> i32 {
|
||||
if a > b {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
}
|
||||
|
||||
// Don't mind this for now :)
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn ten_is_bigger_than_eight() {
|
||||
assert_eq!(10, bigger(10, 8));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fortytwo_is_bigger_than_thirtytwo() {
|
||||
assert_eq!(42, bigger(32, 42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn equal_numbers() {
|
||||
assert_eq!(42, bigger(42, 42));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue