From 57db06ff9a91958206c11b9947052a99857299e3 Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Tue, 3 May 2022 20:49:54 +0200 Subject: [PATCH] move asserts to tests --- src/population.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/population.rs b/src/population.rs index 15b9562..eb315cf 100644 --- a/src/population.rs +++ b/src/population.rs @@ -38,12 +38,6 @@ impl Population { the_humans[idx].y = y; } } - for h in the_humans.iter() { - let idx = human_idx(h.x, h.y, width); - assert_eq!(the_humans[idx].x, h.x); - assert_eq!(the_humans[idx].y, h.y); - } - assert_eq!(the_humans.len(), (width * height) as usize); Self { start_infected_ratio: start_infected_ratio, start_immune_ratio: start_immune_ratio, @@ -373,6 +367,7 @@ mod tests { #[test] fn population_new() { let disease = Disease::new(20, 10, 5, String::from("Covid 44")); + let (width, height) = (5, 7); let population = Population::new(20, 10, 5, 5, 7, disease); assert_eq!(population.humans.len(), 5 * 7); for human in population.humans.iter() { @@ -381,6 +376,13 @@ mod tests { "all humans should be normal" ); } + for h in population.humans.iter() { + let idx = human_idx(h.x, h.y, width); + assert_eq!(population.humans[idx].x, h.x, "coordinates should match"); + assert_eq!(population.humans[idx].y, h.y, "coordinates should match"); + } + assert_eq!(population.humans.len(), (width * height) as usize); + } #[test]