message: test: add unit tests to seed_match.rs
diff: @@ -18,6 +18,8 @@ pub fn seed_match<L: Letter<L>>(
  let mut max_score = 0;
  let mut max_ref_pos = 0;
  + // TODO: Use stricter bounds on end_pos, using max indel length = max shift
  + // Need to add end_pos for this
  let end_pos = ref_len - kmer_len;
  for ref_pos in start_pos..end_pos {
  tmp_score = 0;
  @@ -27,7 +29,7 @@ pub fn seed_match<L: Letter<L>>(
  tmp_score += 1;
  }
  - // TODO: this speeds up seed-matching by disregarding bad seeds.
  + // this speeds up seed-matching by disregarding bad seeds.
  if tmp_score + mismatches_allowed < pos {
  break;
  }
  @@ -36,8 +38,8 @@ pub fn seed_match<L: Letter<L>>(
  max_score = tmp_score;
  max_ref_pos = ref_pos;
  - // if maximal score is reached
  - if tmp_score == kmer_len {
  + // accept semi-optimal within mismatches_allowed to speed up
  + if max_score >= kmer_len - mismatches_allowed {
  break;
  }
  }
  @@ -48,3 +50,44 @@ pub fn seed_match<L: Letter<L>>(
  score: max_score,
  }
  }
  +
  +#[cfg(test)]
  +mod tests {
  + use super::*;
  + use crate::io::nuc::{from_nuc_seq, to_nuc_seq};
  + use eyre::Report;
  + use pretty_assertions::assert_eq;
  + use rstest::{fixture, rstest};
  +
  + #[rstest]
  + fn test_simple_seed_match() -> Result<(), Report> {
  + let kmer = to_nuc_seq("ACG")?;
  + let ref_seq = to_nuc_seq("AAAAAAACGAAAAA")?;
  +
  + let mismatches_allowed = 0;
  + let start_pos = 0;
  +
  + let result = seed_match(&kmer, &ref_seq, start_pos, mismatches_allowed);
  +
  + assert_eq!(result.ref_pos, 6);
  + assert_eq!(result.score, 3);
  +
  + Ok(())
  + }
  +
  + #[rstest]
  + fn test_accept_suboptimal_match() -> Result<(), Report> {
  + let kmer = to_nuc_seq("ACG")?;
  + let ref_seq = to_nuc_seq("AACTACGAA")?;
  +
  + let mismatches_allowed = 1;
  + let start_pos = 0;
  +
  + let result = seed_match(&kmer, &ref_seq, start_pos, mismatches_allowed);
  +
  + assert_eq!(result.ref_pos, 1);
  + assert_eq!(result.score, 2);
  +
  + Ok(())
  + }
  +}
  