forked from Maxluli/RustyPropagation
cargo fmt
This commit is contained in:
+100
-22
@@ -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);
|
||||||
@@ -116,7 +123,7 @@ impl Population {
|
|||||||
stats[0] += 1;
|
stats[0] += 1;
|
||||||
}
|
}
|
||||||
State::Infected => {
|
State::Infected => {
|
||||||
people_to_check.push(Point{ x: h.x, y: h.y });
|
people_to_check.push(Point { x: h.x, y: h.y });
|
||||||
stats[1] += 1;
|
stats[1] += 1;
|
||||||
}
|
}
|
||||||
State::Immune => {
|
State::Immune => {
|
||||||
@@ -345,7 +352,7 @@ mod tests {
|
|||||||
let mut stats: Stats;
|
let mut stats: Stats;
|
||||||
|
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
humans.push(Human{
|
humans.push(Human {
|
||||||
present_state: State::Normal,
|
present_state: State::Normal,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
@@ -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