Hi all, my first post and I'm a beginner so hope this is the appropriate place to post.
I'm doing the rustlings exercise if1.rs which asks to complete a provided function to return the "bigger" of two i32 values. I can't find a way to cover the a==b case.
Here's the code (read the comment I inserted to help clarify).
// if1.rs
// I AM NOT DONE
pub fn bigger(a: i32, b: i32) -> i32 {
// Complete this function to return the bigger number!
// Do not use:
// - another function call
// - additional variables
// Execute `rustlings hint if1` for hints
// MY COMMENT: The "if a > b { return a } b" code below is inserted by me.
// All the rest is the rustlings-provided code.
// My code works as far as compiling and not returning a smaller value
// but isn't technically a correct solution. If a == b it returns b
// but really should return some indication that there was no
// "bigger" number. I tried if{}else if{} to return a>b or b>a but when a==b
// case falls through how would I return some indicator or error message?
// As provided the function can only return an i32.
if a > b {
return a
}
b
}
// 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));
}
}