Skip to content

Commit

Permalink
Merge pull request #308 from maqi/create_unit_tests_
Browse files Browse the repository at this point in the history
refactors MetaVote and creates unit tests for it
  • Loading branch information
pierrechevalier83 authored May 22, 2019
2 parents 8e48f31 + 39add1a commit 8c0d9d0
Show file tree
Hide file tree
Showing 8 changed files with 1,260 additions and 363 deletions.
12 changes: 4 additions & 8 deletions src/dev_utils/dot_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,18 +667,14 @@ fn parse_meta_vote() -> Parser<u8, MetaVote> {
+ parse_opt_bool()
- spaces()
+ parse_opt_bool())
.map(|(((((round, step), est), bin), aux), dec)| MetaVote {
round,
step: match step {
.map(|(((((round, step), est), bin), aux), dec)| {
let step = match step {
0 => Step::ForcedTrue,
1 => Step::ForcedFalse,
2 => Step::GenuineFlip,
_ => unreachable!(),
},
estimates: est,
bin_values: bin,
aux_value: aux,
decision: dec,
};
MetaVote::new(round, step, est, bin, aux, dec)
})
}

Expand Down
13 changes: 1 addition & 12 deletions src/dump_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,6 @@ mod detail {
fs::remove_dir(path)
}

fn as_short_string(value: Option<bool>) -> &'static str {
match value {
None => "-",
Some(true) => "t",
Some(false) => "f",
}
}

fn dump_meta_votes(
short_peer_ids: &PeerIndexMap<String>,
meta_votes: &PeerIndexMap<Vec<MetaVote>>,
Expand Down Expand Up @@ -347,10 +339,7 @@ mod detail {

let mut prefix: &str = prefix.as_str();
for mv in meta_votes {
let est = mv.estimates.as_short_string();
let bin = mv.bin_values.as_short_string();
let aux = as_short_string(mv.aux_value);
let dec = as_short_string(mv.decision);
let (est, bin, aux, dec) = mv.values.as_chars();
let line = if comment {
format!(
"{}{}/{:?} {} {} {} {} ",
Expand Down
18 changes: 0 additions & 18 deletions src/meta_voting/bool_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,11 @@ impl BoolSet {
}
}

pub fn clear(&mut self) {
*self = BoolSet::Empty
}

pub fn len(self) -> usize {
match self {
BoolSet::Empty => 0,
BoolSet::Single(_) => 1,
BoolSet::Both => 2,
}
}

pub fn from_bool(val: bool) -> Self {
BoolSet::Single(val)
}

#[cfg(feature = "dump-graphs")]
pub(crate) fn as_short_string(self) -> &'static str {
match self {
BoolSet::Empty => "-",
BoolSet::Single(true) => "t",
BoolSet::Single(false) => "f",
BoolSet::Both => "b",
}
}
}
Loading

0 comments on commit 8c0d9d0

Please sign in to comment.