diff --git a/src/population.rs b/src/population.rs index 096cab1..1ae1bba 100644 --- a/src/population.rs +++ b/src/population.rs @@ -424,11 +424,19 @@ mod tests { let mut population: Population; let mut stats: Stats; let (width, height) = (100, 100); + let start_infected = 50; disease = Disease::new(infection_rate, 0, 0, String::from("Test")); - population = Population::new(50, 0, 0, width, height, disease); + population = Population::new(start_infected, 0, 0, width, height, disease); stats = humans_stats(&population.humans); println!("Population: {:?}", stats); + + // total * proba - 20% < infected < total * proba + 20% + let expected_infected = width * height * start_infected as i32 / 100; + let tolerance = ((width * height) as f32 * 0.2) as i32; + assert!(stats.infected < expected_infected + tolerance); + assert!(stats.infected > expected_infected - tolerance); + population.generate(); population.propagate(); stats = humans_stats(&population.humans);