1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-18 07:07:35 +02:00

Rework health statistics exercise (#909)

* exercises: health-statistics: weight -> height

weight may be a sensitive topic for some readers; use height instead as this isn't important to the content of the course

* exercises: health-statistics: add health report

this lets us see a non-setter use case for &mut self

it also makes the 'statistics' side of this exercise more explicit as we count doctor visits

* exercises: health-statistics: normalize variable names
This commit is contained in:
Frances Wingerter
2023-07-11 22:01:49 +00:00
committed by GitHub
parent 446ca40584
commit 2f5dcbafc3
2 changed files with 49 additions and 6 deletions

View File

@ -17,9 +17,9 @@ fn main() {
}
#[test]
fn test_weight() {
fn test_height() {
let bob = User::new(String::from("Bob"), 32, 155.2);
assert_eq!(bob.weight(), 155.2);
assert_eq!(bob.height(), 155.2);
}
#[test]
@ -29,4 +29,25 @@ fn test_set_age() {
bob.set_age(33);
assert_eq!(bob.age(), 33);
}
#[test]
fn test_visit() {
let mut bob = User::new(String::from("Bob"), 32, 155.2);
assert_eq!(bob.doctor_visits(), 0);
let report = bob.visit_doctor(Measurements {
height: 156.1,
blood_pressure: (120, 80),
});
assert_eq!(report.patient_name, "Bob");
assert_eq!(report.visit_count, 1);
assert_eq!(report.blood_pressure_change, None);
let report = bob.visit_doctor(Measurements {
height: 156.1,
blood_pressure: (115, 76),
});
assert_eq!(report.visit_count, 2);
assert_eq!(report.blood_pressure_change, Some((-5, -4)));
}
```