diff --git a/src/core/src/encodings.rs b/src/core/src/encodings.rs index 56077c80e1..06af5d03c1 100644 --- a/src/core/src/encodings.rs +++ b/src/core/src/encodings.rs @@ -520,6 +520,7 @@ impl<'a> Iterator for Indices<'a> { #[cfg(test)] mod test { use super::*; + use std::convert::TryFrom; #[test] fn colors_update() { @@ -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(); + } } diff --git a/src/core/src/signature.rs b/src/core/src/signature.rs index 5cc60ca299..7fdb9b7f2d 100644 --- a/src/core/src/signature.rs +++ b/src/core/src/signature.rs @@ -995,6 +995,7 @@ impl TryInto for Signature { #[cfg(test)] mod test { + use core::num; use std::fs::File; use std::io::{BufReader, Read}; use std::path::PathBuf; @@ -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; @@ -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"; @@ -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() { @@ -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";