if1 solution

This commit is contained in:
mo8it 2024-05-22 15:04:21 +02:00
parent 3bb71c6b0c
commit c8ad6c3960
2 changed files with 34 additions and 3 deletions

View file

@ -200,9 +200,9 @@ Some similar examples from other languages:
- In Python this would be: `a if a > b else b` - In Python this would be: `a if a > b else b`
Remember in Rust that: 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 - `if`/`else` conditionals are expressions
- Each condition is followed by a `{}` block.""" - Each condition is followed by a `{}` block"""
[[exercises]] [[exercises]]
name = "if2" name = "if2"

View file

@ -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));
}
}