From fe8f505233354df73cd8252b4efaf133ff464948 Mon Sep 17 00:00:00 2001 From: tibvdm Date: Mon, 8 Apr 2024 14:17:13 +0200 Subject: [PATCH] extra protein testing --- sa-mappings/src/proteins.rs | 54 +++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/sa-mappings/src/proteins.rs b/sa-mappings/src/proteins.rs index 786e700..a79dd3d 100644 --- a/sa-mappings/src/proteins.rs +++ b/sa-mappings/src/proteins.rs @@ -23,7 +23,6 @@ pub static SEPARATION_CHARACTER: u8 = b'-'; pub static TERMINATION_CHARACTER: u8 = b'$'; /// A struct that represents a protein and its linked information -#[derive(Debug)] pub struct Protein { /// The id of the protein pub uniprot_id: String, @@ -39,7 +38,6 @@ pub struct Protein { } /// A struct that represents a collection of proteins -#[derive(Debug)] pub struct Proteins { /// The input string containing all proteins input_string: Vec, @@ -208,6 +206,58 @@ mod tests { taxonomy_file } + #[test] + fn test_new_protein() { + let protein = Protein { + uniprot_id: "P12345".to_string(), + sequence: (0, 3), + taxon_id: 1, + functional_annotations: vec![0xD1, 0x11] + }; + + assert_eq!(protein.uniprot_id, "P12345"); + assert_eq!(protein.sequence, (0, 3)); + assert_eq!(protein.taxon_id, 1); + assert_eq!(protein.functional_annotations, vec![0xD1, 0x11]); + } + + #[test] + fn test_new_proteins() { + let proteins = Proteins { + input_string: "MLPGLALLLLAAWTARALEV-PTDGNAGLLAEPQIAMFCGRLNMHMNVQNG" + .as_bytes() + .to_vec(), + proteins: vec![ + Protein { + uniprot_id: "P12345".to_string(), + sequence: (0, 3), + taxon_id: 1, + functional_annotations: vec![0xD1, 0x11] + }, + Protein { + uniprot_id: "P54321".to_string(), + sequence: (4, 3), + taxon_id: 2, + functional_annotations: vec![0xD1, 0x11] + }, + ] + }; + + assert_eq!( + proteins.input_string, + "MLPGLALLLLAAWTARALEV-PTDGNAGLLAEPQIAMFCGRLNMHMNVQNG".as_bytes() + ); + assert_eq!(proteins.proteins.len(), 2); + assert_eq!(proteins.proteins[0].uniprot_id, "P12345"); + assert_eq!(proteins.proteins[0].sequence, (0, 3)); + assert_eq!(proteins.proteins[0].taxon_id, 1); + assert_eq!(proteins.proteins[0].functional_annotations, vec![0xD1, 0x11]); + assert_eq!(proteins.proteins[1].uniprot_id, "P54321"); + assert_eq!(proteins.proteins[1].sequence, (4, 3)); + assert_eq!(proteins.proteins[1].taxon_id, 2); + assert_eq!(proteins.proteins[1].functional_annotations, vec![0xD1, 0x11]); + } + #[test] fn test_get_sequence() { // Create a temporary directory for this test