forked from Maxluli/RustyPropagation
check infection rate first
This commit is contained in:
+9
-1
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user