Simple warding fix (#107)

* fix negated analyze
This commit is contained in:
Al Liu 2023-03-27 19:16:48 +08:00 committed by GitHub
parent ae16e8583b
commit f4b94c8267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -12,12 +12,12 @@ pub struct MaxViewWard {
impl<N: Node> SimulationWard<N> for MaxViewWard { impl<N: Node> SimulationWard<N> for MaxViewWard {
type SimulationState = SimulationState<N>; type SimulationState = SimulationState<N>;
fn analyze(&mut self, state: &Self::SimulationState) -> bool { fn analyze(&mut self, state: &Self::SimulationState) -> bool {
!state state
.nodes .nodes
.read() .read()
.expect("simulations: MaxViewWard panic when requiring a read lock") .expect("simulations: MaxViewWard panic when requiring a read lock")
.iter() .iter()
.any(|n| n.current_view() >= self.max_view) .all(|n| n.current_view() >= self.max_view)
} }
} }
@ -58,13 +58,13 @@ mod test {
} }
let mut ttf = MaxViewWard { max_view: 10 }; let mut ttf = MaxViewWard { max_view: 10 };
let node = 9; let node = 11;
let state = SimulationState { let state = SimulationState {
nodes: Arc::new(RwLock::new(vec![node])), nodes: Arc::new(RwLock::new(vec![node])),
}; };
assert!(ttf.analyze(&state)); assert!(ttf.analyze(&state));
state.nodes.write().unwrap().push(11); state.nodes.write().unwrap().push(9);
assert!(!ttf.analyze(&state)); assert!(!ttf.analyze(&state));
} }
} }