Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegenes committed Dec 16, 2024
1 parent 6008646 commit b20479c
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 2 deletions.
91 changes: 91 additions & 0 deletions src/core/src/encodings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ impl<'a> Iterator for Indices<'a> {
#[cfg(test)]
mod test {
use super::*;
use std::convert::TryFrom;

#[test]
fn colors_update() {
Expand Down Expand Up @@ -587,4 +588,94 @@ mod test {

assert_eq!(colors.len(), 2);
}

#[test]
fn test_dna_method() {
assert!(HashFunctions::Murmur64Dna.dna());
assert!(!HashFunctions::Murmur64Protein.dna());
assert!(!HashFunctions::Murmur64Dayhoff.dna());
}

#[test]
fn test_protein_method() {
assert!(HashFunctions::Murmur64Protein.protein());
assert!(!HashFunctions::Murmur64Dna.protein());
assert!(!HashFunctions::Murmur64Dayhoff.protein());
}

#[test]
fn test_dayhoff_method() {
assert!(HashFunctions::Murmur64Dayhoff.dayhoff());
assert!(!HashFunctions::Murmur64Dna.dayhoff());
assert!(!HashFunctions::Murmur64Protein.dayhoff());
}

#[test]
fn test_hp_method() {
assert!(HashFunctions::Murmur64Hp.hp());
assert!(!HashFunctions::Murmur64Dna.hp());
assert!(!HashFunctions::Murmur64Protein.hp());
}

#[test]
fn test_skipm1n3_method() {
assert!(HashFunctions::Murmur64Skipm1n3.skipm1n3());
assert!(!HashFunctions::Murmur64Dna.skipm1n3());
assert!(!HashFunctions::Murmur64Protein.skipm1n3());
}

#[test]
fn test_skipm2n3_method() {
assert!(HashFunctions::Murmur64Skipm2n3.skipm2n3());
assert!(!HashFunctions::Murmur64Dna.skipm2n3());
assert!(!HashFunctions::Murmur64Protein.skipm2n3());
}

#[test]
fn test_display_hashfunctions() {
assert_eq!(HashFunctions::Murmur64Dna.to_string(), "DNA");
assert_eq!(HashFunctions::Murmur64Protein.to_string(), "protein");
assert_eq!(HashFunctions::Murmur64Dayhoff.to_string(), "dayhoff");
assert_eq!(HashFunctions::Murmur64Hp.to_string(), "hp");
assert_eq!(HashFunctions::Murmur64Skipm1n3.to_string(), "skipm1n3");
assert_eq!(HashFunctions::Murmur64Skipm2n3.to_string(), "skipm2n3");
assert_eq!(
HashFunctions::Custom("custom_string".into()).to_string(),
"custom_string"
);
}

#[test]
fn test_try_from_str_valid() {
assert_eq!(
HashFunctions::try_from("dna").unwrap(),
HashFunctions::Murmur64Dna
);
assert_eq!(
HashFunctions::try_from("protein").unwrap(),
HashFunctions::Murmur64Protein
);
assert_eq!(
HashFunctions::try_from("dayhoff").unwrap(),
HashFunctions::Murmur64Dayhoff
);
assert_eq!(
HashFunctions::try_from("hp").unwrap(),
HashFunctions::Murmur64Hp
);
assert_eq!(
HashFunctions::try_from("skipm1n3").unwrap(),
HashFunctions::Murmur64Skipm1n3
);
assert_eq!(
HashFunctions::try_from("skipm2n3").unwrap(),
HashFunctions::Murmur64Skipm2n3
);
}

#[test]
#[should_panic(expected = "not implemented: unknown")]
fn test_try_from_str_invalid() {
HashFunctions::try_from("unknown").unwrap();
}
}
34 changes: 32 additions & 2 deletions src/core/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ impl TryInto<KmerMinHash> for Signature {
#[cfg(test)]
mod test {

use core::num;

Check warning on line 998 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (stable)

unused import: `core::num`

Check warning on line 998 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unused import: `core::num`

Check warning on line 998 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (macos)

unused import: `core::num`

Check warning on line 998 in src/core/src/signature.rs

View workflow job for this annotation

GitHub Actions / test (windows)

unused import: `core::num`
use std::fs::File;
use std::io::{BufReader, Read};
use std::path::PathBuf;
Expand All @@ -1003,8 +1004,7 @@ mod test {

use crate::cmd::ComputeParameters;
use crate::encodings::HashFunctions;
use crate::signature::SeqToHashes;
use crate::signature::SigsTrait;
use crate::signature::{ReadingFrame, SeqToHashes, SigsTrait};

use super::Signature;

Expand Down Expand Up @@ -1432,6 +1432,15 @@ mod test {
}
}

#[test]
fn test_readingframe_dna() {
let sequence = b"AGTCGT";
let frame = ReadingFrame::new_dna(sequence);

assert_eq!(frame.fw(), sequence.as_slice());
assert_eq!(frame.rc(), b"ACGACT".as_slice());
}

#[test]
fn test_seqtohashes_frames_dna() {
let sequence = b"AGTCGT";
Expand Down Expand Up @@ -1465,6 +1474,16 @@ mod test {
assert_eq!(frames[0].fw(), sequence.as_slice());
}

#[test]
fn test_readingframe_protein() {
let sequence = b"MVLSPADKTNVKAAW";
let hash_function = HashFunctions::Murmur64Protein;
let frame =
ReadingFrame::new_protein(sequence, hash_function.dayhoff(), hash_function.hp());

assert_eq!(frame.fw(), sequence.as_slice());
}

#[test]
#[should_panic]
fn test_seqtohashes_frames_is_protein_try_access_rc() {
Expand Down Expand Up @@ -1537,6 +1556,17 @@ mod test {
assert_eq!(frames[5].fw(), b"LDD".as_slice());
}

#[test]
#[should_panic(expected = "Skipmer frame number must be < n")]
fn test_readingframe_skipmer() {
let sequence = b"AGTCGT";
let m = 2;
let n = 3;
let num_frames = 4; // four frames but n is only 3

ReadingFrame::new_skipmer(sequence, num_frames, m, n);
}

#[test]
fn test_seqtohashes_frames_skipmer_m1n3() {
let sequence = b"AGTCGTCGAGCT";
Expand Down

0 comments on commit b20479c

Please sign in to comment.