Commit 0d2afd1a authored by NOEL Philippe's avatar NOEL Philippe

add some tests in selection_atom and doc

parent 9dafb9c1
......@@ -60,17 +60,21 @@ fn parse_options_char(opt: &[&str]) -> Option<[char; 2]> {
None
}
/// Parse the selection and return enum and options for atom/residue/chain/backbone
///
pub fn parse_select(pattern: &str) -> Option<Vec<Select>> {
// The pattern is first split with "and" keyworkd into multiple sub-pattern (selection)
// sub-pattern are then compared with "resid", "chain" and "backbone" keyworkds
//
// Return None if there is a probleme in the pattern parsing
pub fn parse_select(select: &str) -> Option<Vec<Select>> {
if select == "" {
if pattern == "" {
return None; //selection empty
}
let mut lst_selection: Vec<Select> = Vec::new(); //vector to return
let sel: Vec<&str> = select.split("and").collect();
let mut lst_selection: Vec<Select> = Vec::new(); //vector to return containing sub_patterns
let sel: Vec<&str> = pattern.split("and").collect();
for pattern in sel {
let sub_pattern: Vec<&str> = pattern.split_whitespace().collect();
......@@ -99,55 +103,48 @@ pub fn parse_select(select: &str) -> Option<Vec<Select>> {
}
pub fn atom_match(sel: &Vec<Select>, chain: char, res_id: u64, back: bool) -> bool {
let mut is_selected = false;
pub fn atom_match(sel: &Vec<Select>, chain: char, res_id: u64, is_back: bool) -> bool {
// For each pattern in sel, the pattern is compare to the caracteristics of the atom
// if at any moment, the caracteristics are not ok, the function return false
// In the end, it return true (consider everythings is ok)
for pattern in sel {
match pattern {
Select::Chain(x, y) => {
if chain >= *x && chain <= *y {
is_selected = true
} else {
if ! (chain >= *x && chain <= *y) {
return false
}
},
Select::Backbone => {
if back {
is_selected = true
} else {
if ! (is_back) {
return false
}
},
Select::Resid(x, y) => {
if res_id as usize >= *x && res_id as usize <= *y {
is_selected = true
} else {
if ! (res_id as usize >= *x && res_id as usize <= *y) {
return false
}
},
}
}
is_selected
true
}
#[test]
fn test_atom_search_chain() {
fn test_atom_search() {
let mut s = Vec::new();
s.push(Select::Chain('B', 'C'));
assert!(atom_match(&s, 'C', 15, true));
//assert!(!atom_match(&Select::Chain('A', 'B'), 'C', 15, true));
//assert!(atom_match(&Select::Chain('1', '4'), '2', 15, true));
//assert!(atom_match(&Select::Chain('A', '9'), '2', 15));
//assert!(atom_match(&Select::Chain('A', 'a'), 'Z', 15, true));
//assert!(!atom_match(&Select::Chain('A', 'a'), 'd', 15, true));
}
#[test]
fn test_atom_search_resid() {
//assert!(atom_match(&Select::Resid(1, 105), 'A', 15, true));
//assert!(!atom_match(&Select::Resid(1, 105), 'A', 0, true));
//assert!(atom_match(&Select::Resid(1, 105), 'A', 105, true));
assert!(true);
s.push(Select::Resid(14, 155));
assert!(atom_match(&s, 'C', 15, true));
assert!(!atom_match(&s, 'C', 13, true));
s.push(Select::Backbone);
assert!(atom_match(&s, 'C', 15, true));
assert!(!atom_match(&s, 'C', 15, false));
}
#[test]
......@@ -157,14 +154,10 @@ fn test_parse_select() {
println!("{:?}", v);
assert_eq!(Select::Resid(5, 96), v[0]);
/* let v = parse_select("resid 5 to 96 and chain B").unwrap();
println!("{:?}", v);
let v = parse_select("resid 5 to 96 and chain B").unwrap();
assert_eq!(Select::Resid(5, 96), v[0]);
assert_eq!(Select::Chain('B', 'B'), v[1]); */
//let v = parse_select("");
//assert_eq!(None, v);
assert_eq!(Select::Chain('B', 'B'), v[1]);
//let v = parse_select("Select all the protein");
//assert_eq!(None, v);
let v = parse_select("Select all the protein");
assert_eq!(None, v);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment