Skip to content

Commit

Permalink
feat: GenerateBreakpoints::is_empty and ::len (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen authored Apr 17, 2023
1 parent 214acac commit 30edbae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions forrustts-genetics/src/genetic_maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ impl Ord for Breakpoint {
pub trait GenerateBreakpoints {
fn generate_breakpoints<T: Rng>(&mut self, rng: &mut T);
fn breakpoints(&self) -> &[Breakpoint];

/// Number of generated breakpoints.
fn len(&self) -> usize {
self.breakpoints().len()
}

/// Checks if generated breakpoints are empty.
fn is_empty(&self) -> bool {
self.breakpoints().is_empty()
}
}

#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down
4 changes: 4 additions & 0 deletions forrustts-genetics/tests/test_genetic_maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ fn test_generate_bernoulli_breakpoints() {
map.generate_breakpoints(&mut rng);
assert_eq!(map.breakpoints().len(), 2);
assert!(map.breakpoints().windows(2).all(|w| { w[0] <= w[1] }));
assert_eq!(map.len(), map.breakpoints().iter().count());
assert_eq!(map.is_empty(), map.len() == 0);
}

#[test]
Expand All @@ -40,6 +42,8 @@ fn test_generate_poisson_breakpoints() {
let mut rng = rand::rngs::StdRng::seed_from_u64(0);
map.generate_breakpoints(&mut rng);
assert!(map.breakpoints().windows(2).all(|w| { w[0] <= w[1] }));
assert_eq!(map.len(), map.breakpoints().iter().count());
assert_eq!(map.is_empty(), map.len() == 0);
}

#[test]
Expand Down

0 comments on commit 30edbae

Please sign in to comment.