Skip to content

Commit

Permalink
working and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Dec 14, 2023
1 parent 5c1806a commit 2cc5015
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 9 deletions.
8 changes: 4 additions & 4 deletions benches/random_intervals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ impl Intervals {
fn new(name: String, n_intervals: usize, interval_len: u64) -> Self {
Intervals {
i: 0,
name: name,
name,
n_intervals,
curr_max: 1.0,
rng: rand::thread_rng(),
interval_len: interval_len,
interval_len,
saved_chrom: String::from("chr1"),
}
}
}

impl PositionedIterator for Intervals {
fn name(&self) -> String {
String::from(format!("{}:{}", self.name, self.i))
format!("{}:{}", self.name, self.i)
}

fn next_position(&mut self, _q: Option<&Position>) -> Option<io::Result<Position>> {
Expand All @@ -44,7 +44,7 @@ impl PositionedIterator for Intervals {
let start = ((1.0 - self.curr_max) * (MAX_POSITION as f64)) as u64;
Some(Ok(Position::Interval(Interval {
chrom: self.saved_chrom.clone(),
start: start,
start,
stop: start + self.interval_len,
..Default::default()
})))
Expand Down
4 changes: 2 additions & 2 deletions src/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ mod tests {
name,
ivs: ivs
.into_iter()
.map(|i| Position::Interval(i))
.map(Position::Interval)
.collect::<Vec<Position>>(),
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ mod tests {
}
}

b_ivs.ivs.sort_by(|a, b| a.start().cmp(&b.start()));
b_ivs.ivs.sort_by_key(|a| a.start());

let a_ivs: Box<dyn PositionedIterator> = Box::new(a_ivs);

Expand Down
62 changes: 61 additions & 1 deletion src/intersections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::position::Position;
#[allow(unused_imports)]
use crate::string::String;
use bitflags::bitflags;
use std::ops::Deref;
use std::sync::Arc;

bitflags! {
Expand Down Expand Up @@ -294,6 +293,67 @@ mod tests {
assert_eq!(rf.b[1].start(), 8);
assert_eq!(rf.b[1].stop(), 12);
}
// TODO: test Not

#[test]
fn test_a_pieces() {
let intersections = make_example("a: 1-10\nb: 3-6, 8-12");
let r = intersections.report(
IntersectionMode::PerPiece,
IntersectionMode::Default,
IntersectionPart::Whole,
IntersectionPart::Whole,
OverlapAmount::Bases(1),
OverlapAmount::Bases(1),
);
assert_eq!(r.len(), 2);
let rf = &r[0];
// test that a is 1-10
assert_eq!(rf.a.as_ref().unwrap().start(), 1);
assert_eq!(rf.a.as_ref().unwrap().stop(), 10);
// test that b is 3-6
assert_eq!(rf.b.len(), 1);
assert_eq!(rf.b[0].start(), 3);
assert_eq!(rf.b[0].stop(), 6);

let rf = &r[1];
assert_eq!(rf.a.as_ref().unwrap().start(), 1);
assert_eq!(rf.a.as_ref().unwrap().stop(), 10);
assert_eq!(rf.b.len(), 1);
assert_eq!(rf.b[0].start(), 8);
assert_eq!(rf.b[0].stop(), 12);
}

#[test]
fn test_a_pieces_ab_part() {
let intersections = make_example("a: 1-10\nb: 3-6, 8-12");
let r = intersections.report(
IntersectionMode::PerPiece,
IntersectionMode::Default,
IntersectionPart::Part,
IntersectionPart::Part,
OverlapAmount::Bases(1),
OverlapAmount::Bases(1),
);
// a: 3-6, b: 3-6
// a: 8-10, b: 8-10
assert_eq!(r.len(), 2);
let rf = &r[0];
// test that a is 3-6
assert_eq!(rf.a.as_ref().unwrap().start(), 3);
assert_eq!(rf.a.as_ref().unwrap().stop(), 6);
// test that b is 3-6
assert_eq!(rf.b.len(), 1);
assert_eq!(rf.b[0].start(), 3);
assert_eq!(rf.b[0].stop(), 6);

let rf = &r[1];
assert_eq!(rf.a.as_ref().unwrap().start(), 8);
assert_eq!(rf.a.as_ref().unwrap().stop(), 10);
assert_eq!(rf.b.len(), 1);
assert_eq!(rf.b[0].start(), 8);
assert_eq!(rf.b[0].stop(), 10);
}

#[test]
fn test_b_part() {
Expand Down
4 changes: 2 additions & 2 deletions src/sniff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ where
P: AsRef<Path>,
{
let file = std::fs::File::open(&path)?;
let r = open_reader(file, path);
r

open_reader(file, path)
}

pub fn open_reader<R, P>(reader: R, path: P) -> std::io::Result<Box<dyn PositionedIterator>>
Expand Down

0 comments on commit 2cc5015

Please sign in to comment.