Skip to content

Commit f9e2115

Browse files
committed
feat: add unit tests for BMI parsing and category logic
1 parent 3c22edf commit f9e2115

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/main.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn bmi_message(bmi: f64) -> &'static str {
5050
} else if bmi >= 18.5 && bmi < 25.0 {
5151
"Normal"
5252
} else if bmi >= 25.0 && bmi < 30.0 {
53-
"Overweight!"
53+
"Overweight"
5454
} else if bmi >= 30.0 && bmi < 35.0 {
5555
"Obese Class I"
5656
} else if bmi >= 35.0 && bmi < 40.0 {
@@ -75,3 +75,26 @@ fn height_input_parsing(input: String) -> f64 {
7575
.parse()
7676
.expect("Please enter a valid a valid height");
7777
}
78+
79+
#[cfg(test)]
80+
mod tests {
81+
use super::*;
82+
83+
#[test]
84+
fn weight_input_parsing_valid_number_returns_f64() {
85+
let result = weight_input_parsing(String::from("65"));
86+
assert_eq!(result, 65.0);
87+
}
88+
89+
#[test]
90+
fn height_input_parsing_valid_number_returns_f64() {
91+
let result = weight_input_parsing(String::from("1.75"));
92+
assert_eq!(result, 1.75);
93+
}
94+
95+
#[test]
96+
fn returns_message_after_evaluating_bmi_16_5(){
97+
let message = bmi_message(16.5);
98+
assert_eq!(message, "Moderate Thinness");
99+
}
100+
}

0 commit comments

Comments
 (0)