use generalized_suffix_tree::suffix_tree::*; #[test] fn create_tree() { let _tree: KGST = KGST::new('$'); } #[test] fn insert(){ let mut tree: KGST = KGST::new('$'); let item_string:Vec = "MKAILVVLLYTFTTADADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLENRHNGKLCKLRGVAPLHLGKCNIAGWILGNPECESLSTAGSWSYIVETSNPDNGTCYPGDFINYEELREQLSSVSSFEKFEIFPKTSSWPNHDTNRGVTAACPHDGAKSFYRNLLWLVKKEKENSYPMINKSYTNNKGKEVLVLWAIHHPATSADQQSLYQNANAYVFVGSSKYSKKFEPEIAARPKVRDQAGRMKYYWTLVEPGDKITFEATGNLVVPIYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFNHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDTCMESVKNGTYDYPKYSEEAKLNREEIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".chars().collect(); let item_id:String = "World".to_string(); tree.insert(item_id.clone(), item_string.clone(),&0); for string_idx in 0..item_string.len()-1{ let suffix_match = tree.suffix_match(&item_string[string_idx..]); assert!(suffix_match.get(&item_id).expect("suffix not found!").contains(&string_idx)); } } #[test] fn insert_set(){ let mut tree: KGST = KGST::new('$'); let string_set: Vec> = vec![ "MKAILVVLLYTFTTADADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLENRHNGKLCKLRGVAPLHLGKCNIAGWILGNPECESLSTAGSWSYIVETSNPDNGTCYPGDFINYEELREQLSSVSSFEKFEIFPKTSSWPNHDTNRGVTAACPHDGAKSFYRNLLWLVKKEKENSYPMINKSYTNNKGKEVLVLWAIHHPATSADQQSLYQNANAYVFVGSSKYSKKFEPEIAARPKVRDQAGRMKYYWTLVEPGDKITFEATGNLVVPIYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFNHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDTCMESVKNGTYDYPKYSEEAKLNREEIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), "MKAILVVLLYTFTTANADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLEDKHNGKLCKLRGVAPLHLGKCNIAGWILGNPECESLSTARSWSYIVETSNSDNGTCYPGDFINYEELREQLSSVSSFERFEIFPKTSSWPNHDSNKGVTAACPHAGAKSFYKNLVWLVKKEKENSYPKLNKTYINDKGKEVLVLWGIHHPPTTADQQSLYQNADAYVFVGTSRYSKKFKPEIAKRPKVRDQEGRMNYYWTLVEPGDKITFEATGNLVVPRYAFTMERNAGSGIIISDTPVHDCNTTCQTPEGAINTSLPFQNVHPITIGKCPKYVKSTKLRLATGLRNVPSIQSRGLFGAIAGFIEGGWTGMVDGWYGYHHQNEQGSGYAADLKSTQNAIDEITNKVNSVIEKMNTQFTAVGKEFNHLEKRIENLNKKVDDGFLDIWTYNAXLLVLLENERTLDYHDSNVKNLYEKVRTQLKNNAKEIGNGCFEFYHKCDNTCMESVKNGTYDYPKYSEEAKLNREKIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), "MKAIIVVVLLYTFTTANADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLKNRHNGKLCKLRGVAPLHLGKCNIAGWLLGNPECEPLSTASSWAYIVETSNSDNGTCYPGDFINYEELTEHLSSVSSFERFEIFPKTNSWPNHDTNKGVTAACPHAGTNSFYRNGIWLVKKENIYPKKSKSYKNKKKKEVLVLWAIHHPSTSADQQSLYQNADAYVFVGSSRYSRKFEPEIATRPKVRDQAGRMNYYWTLVEPGDKITFEATGNLVAPRYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFSHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDMCMESVKNGTYDYPKYSEEAKLNREEIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), "MKAIIVVYLLHLQTATYADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLENRHNGKLCKLRGVAPLHLGKCNIAGWLLGNPECESLSTASSWSYIVETSNSDNGTCYPGDFINYEELREQLSSVSSFERFEIFPKTSSWPNHDTNRGVTAACPHAGTNSFYRNLVWLVKKGNSYPKINKSYINNKEKEVLVLWAIHHPSTSADQQSLYQNADAYVFVGSSRYSKKFEPEIATRPKVRDQAGRMNYYWTLVEPGDKITFEATGNLVAPRYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFSHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDMCMESVKNGTYDYPKYSEEAKLNREGIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), ]; for item_idx in 0..string_set.len(){ tree.insert(item_idx.to_string(), string_set[item_idx].clone(), &0); } for item_idx in 0..string_set.len(){ for string_idx in 0..string_set[item_idx].len()-1{ let suffix_match = tree.suffix_match(&string_set[item_idx][string_idx..]); assert!(suffix_match.get(&item_idx.to_string()).expect("suffix not found!").contains(&string_idx)); } } } #[test] fn serialize_deserialize_tree(){ let mut tree: KGST = KGST::new('$'); let item_string:Vec = "GATTACAGATTACAXYZGATTACAGATTACA".chars().collect(); let item_id:String = "World".to_string(); tree.insert(item_id.clone(), item_string.clone(), &0); let serialized = serde_json::to_string(&tree).unwrap(); let tree_2: KGST = serde_json::from_str(&serialized).unwrap(); assert_eq!(tree.get_nodes(), tree_2.get_nodes()); } #[test] fn insert_trunc(){ let mut tree: KGST = KGST::new('$'); let item_string:Vec = "MKAILVVLLYTFTTADADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLENRHNGKLCKLRGVAPLHLGKCNIAGWILGNPECESLSTAGSWSYIVETSNPDNGTCYPGDFINYEELREQLSSVSSFEKFEIFPKTSSWPNHDTNRGVTAACPHDGAKSFYRNLLWLVKKEKENSYPMINKSYTNNKGKEVLVLWAIHHPATSADQQSLYQNANAYVFVGSSKYSKKFEPEIAARPKVRDQAGRMKYYWTLVEPGDKITFEATGNLVVPIYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFNHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDTCMESVKNGTYDYPKYSEEAKLNREEIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".chars().collect(); let item_id:String = "World".to_string(); let max_depth: usize = 3; tree.insert(item_id.clone(), item_string.clone(), &max_depth); for i in 0..item_string.len()-max_depth{ let substring_match = tree.substring_match(&item_string[i..i+max_depth]); assert!(substring_match.get(&item_id).expect("substring not found!").contains(&i)); } for i in 0..item_string.len()-max_depth{ let substring_match = tree.substring_match(&item_string[i..i+max_depth+1]); assert_eq!(substring_match.get(&item_id), None); } } #[test] fn insert_set_trunc(){ let mut tree: KGST = KGST::new('$'); let string_set: Vec> = vec![ "MKAILVVLLYTFTTADADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLENRHNGKLCKLRGVAPLHLGKCNIAGWILGNPECESLSTAGSWSYIVETSNPDNGTCYPGDFINYEELREQLSSVSSFEKFEIFPKTSSWPNHDTNRGVTAACPHDGAKSFYRNLLWLVKKEKENSYPMINKSYTNNKGKEVLVLWAIHHPATSADQQSLYQNANAYVFVGSSKYSKKFEPEIAARPKVRDQAGRMKYYWTLVEPGDKITFEATGNLVVPIYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFNHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDTCMESVKNGTYDYPKYSEEAKLNREEIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), "MKAILVVLLYTFTTANADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLEDKHNGKLCKLRGVAPLHLGKCNIAGWILGNPECESLSTARSWSYIVETSNSDNGTCYPGDFINYEELREQLSSVSSFERFEIFPKTSSWPNHDSNKGVTAACPHAGAKSFYKNLVWLVKKEKENSYPKLNKTYINDKGKEVLVLWGIHHPPTTADQQSLYQNADAYVFVGTSRYSKKFKPEIAKRPKVRDQEGRMNYYWTLVEPGDKITFEATGNLVVPRYAFTMERNAGSGIIISDTPVHDCNTTCQTPEGAINTSLPFQNVHPITIGKCPKYVKSTKLRLATGLRNVPSIQSRGLFGAIAGFIEGGWTGMVDGWYGYHHQNEQGSGYAADLKSTQNAIDEITNKVNSVIEKMNTQFTAVGKEFNHLEKRIENLNKKVDDGFLDIWTYNAXLLVLLENERTLDYHDSNVKNLYEKVRTQLKNNAKEIGNGCFEFYHKCDNTCMESVKNGTYDYPKYSEEAKLNREKIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), "MKAIIVVVLLYTFTTANADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLKNRHNGKLCKLRGVAPLHLGKCNIAGWLLGNPECEPLSTASSWAYIVETSNSDNGTCYPGDFINYEELTEHLSSVSSFERFEIFPKTNSWPNHDTNKGVTAACPHAGTNSFYRNGIWLVKKENIYPKKSKSYKNKKKKEVLVLWAIHHPSTSADQQSLYQNADAYVFVGSSRYSRKFEPEIATRPKVRDQAGRMNYYWTLVEPGDKITFEATGNLVAPRYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFSHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDMCMESVKNGTYDYPKYSEEAKLNREEIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), "MKAIIVVYLLHLQTATYADTLCIGYHANNSTDTVDTVLEKNVTVTHSVNLLENRHNGKLCKLRGVAPLHLGKCNIAGWLLGNPECESLSTASSWSYIVETSNSDNGTCYPGDFINYEELREQLSSVSSFERFEIFPKTSSWPNHDTNRGVTAACPHAGTNSFYRNLVWLVKKGNSYPKINKSYINNKEKEVLVLWAIHHPSTSADQQSLYQNADAYVFVGSSRYSKKFEPEIATRPKVRDQAGRMNYYWTLVEPGDKITFEATGNLVAPRYAFALKRNSGSGIIISDTSVHDCDTTCQTPNGAINTSLPFQNIHPVTIGECPKYVKSTKLRMATGLRNIPSIQSRGLFGAIAGFIEGGWTGMIDGWYGYHHQNEQGSGYAADLKSTQNAIDGITNKVNSVIEKMNTQFTAVGKEFSHLERRIENLNKKVDDGFLDIWTYNAELLVLLENERTLDYHDSNVKNLYEKVRSQLKNNAKEIGNGCFEFYHKCDDMCMESVKNGTYDYPKYSEEAKLNREGIDGVKLESTRIYQILAIYSTVASSLVLVVSLGAISFWMCSNGSLQCRICI".to_string().chars().collect(), ]; let max_depth: usize = 3; for item_idx in 0..string_set.len(){ tree.insert(item_idx.to_string(), string_set[item_idx].clone(), &max_depth); } for item_idx in 0..string_set.len(){ for string_idx in 0..string_set[item_idx].len()-max_depth{ let substring_match = tree.substring_match(&string_set[item_idx][string_idx..string_idx+max_depth]); assert!(substring_match.get(&item_idx.to_string()).expect("suffix not found!").contains(&string_idx)); } for string_idx in 0..string_set[item_idx].len()-max_depth{ let substring_match = tree.substring_match(&string_set[item_idx][string_idx..string_idx+max_depth+1]); assert_eq!(substring_match.get(&item_idx.to_string()), None); } } } // #[test] // fn insert_set_var_trunc(){ // let mut tree: KGST = KGST::new('$'); // let string_set: Vec> = vec!["GATTACAGATTACAXYZGATTACAGATTACA".to_string().chars().collect(), "CXYZTTATAGCXYZCGTACAGACCGAA".to_string().chars().collect()]; // let id_set:Vec = vec!["first".to_string(),"second".to_string()]; // let max_depth: Vec = vec![3, 5]; // for i in 0..string_set.len(){ // tree.insert(id_set[i].clone(), string_set[i].clone(), &max_depth[i]); // } // for item_idx in 0..string_set.len(){ // for string_idx in 0..string_set[item_idx].len()-max_depth[item_idx]{ // let substring_match = tree.substring_match(&string_set[item_idx][string_idx..string_idx+max_depth[item_idx]]); // assert!(substring_match.get(&id_set[item_idx]).expect("Substring not found!").contains(&string_idx)); // } // } // let mut tree: KGST = KGST::new('$'); // let string_set: Vec> = vec!["GATTACAGATTACAXYZGATTACAGATTACA".to_string().chars().collect(), "CXYZTTATAGCXYZCGTACAGACCGAA".to_string().chars().collect()]; // let id_set:Vec = vec!["first".to_string(),"second".to_string()]; // let max_depth: Vec = vec![5, 3]; // for i in 0..string_set.len(){ // tree.insert(id_set[i].clone(), string_set[i].clone(), &max_depth[i]); // } // for item_idx in 0..string_set.len(){ // for string_idx in 0..string_set[item_idx].len()-max_depth[item_idx]{ // let substring_match = tree.substring_match(&string_set[item_idx][string_idx..string_idx+max_depth[item_idx]]); // assert!(substring_match.get(&id_set[item_idx]).expect("Substring not found!").contains(&string_idx)); // } // } // }