Skip to content

Commit

Permalink
Adding tests for validate_telomere function
Browse files Browse the repository at this point in the history
  • Loading branch information
dasunpubudumal committed Sep 23, 2024
1 parent 56de690 commit dcafddd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/yaml_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,13 @@ pub mod yaml_validator_mod {

#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Telomere {
teloseq: String,
pub teloseq: String,
}

impl Telomere {
/// Validate whether the telomere motif is ALPHABETICAL
/// No upper bound as motifs can be large.
fn validate_telomere(&self) -> String {
pub fn validate_telomere(&self) -> String {
if self.teloseq.chars().all(char::is_alphabetic)
&& self.teloseq.chars().collect::<Vec<_>>().len() > 3
{
Expand Down
27 changes: 26 additions & 1 deletion tests/yaml_validator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fasta_manipulation::yaml_validator_mod::{
get_file_list, validate_paths, AssemReads, CRAMtags, HicReads, TreeValYaml, YamlResults,
get_file_list, validate_paths, AssemReads, CRAMtags, HicReads, Telomere, TreeValYaml,
YamlResults,
};
use std::path::PathBuf;

Expand Down Expand Up @@ -281,3 +282,27 @@ fn validate_longread_invalid_paths() {
assem_read.validate_longread()
);
}

#[test]
fn check_validate_telomere_pass() {
let telomere = Telomere {
teloseq: "AGGGTT".to_string(),
};
assert_eq!("PASS : AGGGTT", telomere.validate_telomere());
}

#[test]
fn check_validate_telomere_fail_non_alphabetic() {
let telomere = Telomere {
teloseq: "TTGGAA1".to_string(),
};
assert_eq!("FAIL : TTGGAA1", telomere.validate_telomere());
}

#[test]
fn check_validate_telomere_fail_character_length() {
let telomere = Telomere {
teloseq: "TTG".to_string(),
};
assert_eq!("FAIL : TTG", telomere.validate_telomere());
}

0 comments on commit dcafddd

Please sign in to comment.