Skip to content

Commit

Permalink
remove unnecessary function from util (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen authored Apr 15, 2021
1 parent 0ee9f86 commit fcca8bb
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/edge_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl PartialEq for EdgeTableRow {
&& self.child == other.child
&& crate::util::f64_partial_cmp_equal(&self.left, &other.left)
&& crate::util::f64_partial_cmp_equal(&self.right, &other.right)
&& crate::util::metadata_like_are_equal(&self.metadata, &other.metadata)
&& self.metadata == other.metadata
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mutation_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ impl PartialEq for MutationTableRow {
&& self.node == other.node
&& self.parent == other.parent
&& crate::util::f64_partial_cmp_equal(&self.time, &other.time)
&& crate::util::metadata_like_are_equal(&self.derived_state, &other.derived_state)
&& crate::util::metadata_like_are_equal(&self.metadata, &other.metadata)
&& self.derived_state == other.derived_state
&& self.metadata == other.metadata
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ impl PartialEq for NodeTableRow {
self.flags == other.flags
&& self.population == other.population
&& self.individual == other.individual
&& crate::util::metadata_like_are_equal(&self.metadata, &other.metadata)
&& crate::util::f64_partial_cmp_equal(&self.time, &other.time)
&& self.metadata == other.metadata
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/population_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct PopulationTableRow {

impl PartialEq for PopulationTableRow {
fn eq(&self, other: &Self) -> bool {
crate::util::metadata_like_are_equal(&self.metadata, &other.metadata)
self.metadata == other.metadata
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/site_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct SiteTableRow {
impl PartialEq for SiteTableRow {
fn eq(&self, other: &Self) -> bool {
crate::util::f64_partial_cmp_equal(&self.position, &other.position)
&& crate::util::metadata_like_are_equal(&self.ancestral_state, &other.ancestral_state)
&& crate::util::metadata_like_are_equal(&self.metadata, &other.metadata)
&& self.ancestral_state == other.ancestral_state
&& self.metadata == other.metadata
}
}

Expand Down
50 changes: 0 additions & 50 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
pub(crate) fn metadata_like_are_equal(a: &Option<Vec<u8>>, b: &Option<Vec<u8>>) -> bool {
match a {
Some(x) => match b {
Some(y) => x == y,
None => false,
},
None => match b.is_none() {
true => true,
false => false,
},
}
}

pub(crate) fn f64_partial_cmp_equal(a: &f64, b: &f64) -> bool {
match a.partial_cmp(b) {
Some(std::cmp::Ordering::Equal) => true,
Expand All @@ -19,40 +6,3 @@ pub(crate) fn f64_partial_cmp_equal(a: &f64, b: &f64) -> bool {
None => false,
}
}

#[cfg(test)]
mod test {
use super::metadata_like_are_equal;

#[test]
fn compare_some_to_none() {
let v: Vec<u8> = vec![1, 2, 3];
assert!(!metadata_like_are_equal(&Some(v), &None));
}

#[test]
fn compare_none_to_some() {
let v: Vec<u8> = vec![1, 2, 3];
assert!(!metadata_like_are_equal(&None, &Some(v)));
}

#[test]
fn compare_none_to_none() {
assert!(metadata_like_are_equal(&None, &None));
}

#[test]
fn compare_some_to_some_are_equal() {
let v: Vec<u8> = vec![1, 2, 3];
let vc = v.clone();
assert!(metadata_like_are_equal(&Some(v), &Some(vc)));
}

#[test]
fn compare_some_to_some_are_not_equal() {
let v: Vec<u8> = vec![1, 2, 3];
let mut vc = v.clone();
vc.push(11);
assert!(!metadata_like_are_equal(&Some(v), &Some(vc)));
}
}

0 comments on commit fcca8bb

Please sign in to comment.