check infection rate first

This commit is contained in:
2022-05-03 15:53:59 +02:00
parent 1d49b31272
commit d0ae725d55
+9 -1
View File
@@ -424,11 +424,19 @@ mod tests {
let mut population: Population; let mut population: Population;
let mut stats: Stats; let mut stats: Stats;
let (width, height) = (100, 100); let (width, height) = (100, 100);
let start_infected = 50;
disease = Disease::new(infection_rate, 0, 0, String::from("Test")); 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); stats = humans_stats(&population.humans);
println!("Population: {:?}", stats); 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.generate();
population.propagate(); population.propagate();
stats = humans_stats(&population.humans); stats = humans_stats(&population.humans);