forked from Maxluli/RustyPropagation
cargo fmt
This commit is contained in:
+98
-20
@@ -30,7 +30,14 @@ impl Population {
|
|||||||
height: i32,
|
height: i32,
|
||||||
plague: Disease,
|
plague: Disease,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut the_humans: Vec<Human> = vec![Human{x: 0, y: 0, present_state: State::Normal}; (width * height) as usize];
|
let mut the_humans: Vec<Human> = vec![
|
||||||
|
Human {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
present_state: State::Normal
|
||||||
|
};
|
||||||
|
(width * height) as usize
|
||||||
|
];
|
||||||
for x in 0..width {
|
for x in 0..width {
|
||||||
for y in 0..height {
|
for y in 0..height {
|
||||||
let idx = human_idx(x, y, width);
|
let idx = human_idx(x, y, width);
|
||||||
@@ -388,7 +395,6 @@ mod tests {
|
|||||||
assert_eq!(population.humans[idx].y, h.y, "coordinates should match");
|
assert_eq!(population.humans[idx].y, h.y, "coordinates should match");
|
||||||
}
|
}
|
||||||
assert_eq!(population.humans.len(), (width * height) as usize);
|
assert_eq!(population.humans.len(), (width * height) as usize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -505,15 +511,51 @@ mod tests {
|
|||||||
|
|
||||||
// start with normal population
|
// start with normal population
|
||||||
population.humans = vec![
|
population.humans = vec![
|
||||||
Human{present_state: State::Normal, x: 0, y: 0},
|
Human {
|
||||||
Human{present_state: State::Normal, x: 1, y: 0},
|
present_state: State::Normal,
|
||||||
Human{present_state: State::Normal, x: 2, y: 0},
|
x: 0,
|
||||||
Human{present_state: State::Normal, x: 0, y: 1},
|
y: 0,
|
||||||
Human{present_state: State::Infected, x: 1, y: 1},
|
},
|
||||||
Human{present_state: State::Normal, x: 2, y: 1},
|
Human {
|
||||||
Human{present_state: State::Normal, x: 0, y: 2},
|
present_state: State::Normal,
|
||||||
Human{present_state: State::Normal, x: 1, y: 2},
|
x: 1,
|
||||||
Human{present_state: State::Normal, x: 2, y: 2},
|
y: 0,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 2,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Infected,
|
||||||
|
x: 1,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 2,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 0,
|
||||||
|
y: 2,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 2,
|
||||||
|
y: 2,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
stats = humans_stats(&population.humans);
|
stats = humans_stats(&population.humans);
|
||||||
println!("stats after init: {:?}", stats);
|
println!("stats after init: {:?}", stats);
|
||||||
@@ -550,15 +592,51 @@ mod tests {
|
|||||||
|
|
||||||
// start with normal population
|
// start with normal population
|
||||||
population.humans = vec![
|
population.humans = vec![
|
||||||
Human{present_state: State::Normal, x: 0, y: 0},
|
Human {
|
||||||
Human{present_state: State::Normal, x: 1, y: 0},
|
present_state: State::Normal,
|
||||||
Human{present_state: State::Normal, x: 2, y: 0},
|
x: 0,
|
||||||
Human{present_state: State::Normal, x: 0, y: 1},
|
y: 0,
|
||||||
Human{present_state: State::Infected, x: 1, y: 1},
|
},
|
||||||
Human{present_state: State::Normal, x: 2, y: 1},
|
Human {
|
||||||
Human{present_state: State::Normal, x: 0, y: 2},
|
present_state: State::Normal,
|
||||||
Human{present_state: State::Normal, x: 1, y: 2},
|
x: 1,
|
||||||
Human{present_state: State::Normal, x: 2, y: 2},
|
y: 0,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 2,
|
||||||
|
y: 0,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Infected,
|
||||||
|
x: 1,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 2,
|
||||||
|
y: 1,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 0,
|
||||||
|
y: 2,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
},
|
||||||
|
Human {
|
||||||
|
present_state: State::Normal,
|
||||||
|
x: 2,
|
||||||
|
y: 2,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
stats = humans_stats(&population.humans);
|
stats = humans_stats(&population.humans);
|
||||||
println!("stats after init: {:?}", stats);
|
println!("stats after init: {:?}", stats);
|
||||||
|
|||||||
Reference in New Issue
Block a user