Guest User

Untitled

a guest
Jun 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. fn bmi(weight: u32, height: f32) -> &'static str {
  2. let bmi: f64 = (weight as f64) / (height as f64).powf(2.0);
  3. let result: &'static str =
  4. if bmi <= 18.5 { "Underweight" } else
  5. if bmi <= 25.0 { "Normal" } else
  6. if bmi <= 30.0 { "Overweight" } else
  7. if bmi > 30.0 { "Obese" } else
  8. { "default" };
  9.  
  10. return result
  11. }
  12.  
  13. #[test]
  14. fn basic_unit_test() {
  15. assert_eq!(bmi(80, 1.80), "Normal");
  16. }
Add Comment
Please, Sign In to add comment