forked from Maxluli/RustyPropagation
add tests
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
// use crate::prelude::*;
|
// use crate::prelude::*;
|
||||||
|
|
||||||
// #[derive(Copy, Clone, PartialEq)]
|
// #[derive(Copy, Clone, PartialEq)]
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
Normal,
|
Normal,
|
||||||
Infected,
|
Infected,
|
||||||
|
|||||||
@@ -21,6 +21,16 @@ pub fn human_idx(x: i32, y: i32, width: i32) -> usize {
|
|||||||
((y * width) + x)as usize
|
((y * width) + x)as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn popuplation_gen() {
|
||||||
|
let disease = Disease::new(20,10,5,String::from("Covid 44"));
|
||||||
|
let population = Population::new(20,10,5,5,7,disease);
|
||||||
|
assert_eq!(population.humans.len(), 5 * 7);
|
||||||
|
for human in population.humans.iter() {
|
||||||
|
assert_eq!(human.present_state, State::Normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Population{
|
impl Population{
|
||||||
pub fn new(start_infected_ratio:u32,start_immune_ratio:u32,start_dead_ratio:u32,width:i32,height:i32,plague:Disease)->Self{
|
pub fn new(start_infected_ratio:u32,start_immune_ratio:u32,start_dead_ratio:u32,width:i32,height:i32,plague:Disease)->Self{
|
||||||
let mut the_humans: Vec<Human> = Vec::with_capacity((width*height) as usize);
|
let mut the_humans: Vec<Human> = Vec::with_capacity((width*height) as usize);
|
||||||
|
|||||||
Reference in New Issue
Block a user