添加单元测试
This commit is contained in:
parent
cb63a82646
commit
0c4be634de
@ -23,9 +23,6 @@ fn filter_by_string(reader: Vec<String>, filter_str: &str) ->Vec<String>{
|
||||
}
|
||||
|
||||
fn take(reader: &mut Vec<String>, start_index: u32, end_index: u32) -> Vec<String> {
|
||||
if end_index < 0 && start_index < 0{
|
||||
panic!("start_index and end_index must be positive");
|
||||
}
|
||||
if end_index == 0 && start_index == 0{
|
||||
return reader.to_owned();
|
||||
}
|
||||
@ -40,4 +37,24 @@ fn take(reader: &mut Vec<String>, start_index: u32, end_index: u32) -> Vec<Strin
|
||||
body.append(&mut reader[start_index as usize..].to_owned());
|
||||
}
|
||||
body
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test{
|
||||
#[test]
|
||||
fn test_filter_by_string(){
|
||||
let reader = vec!["a".to_string(), "b".to_string(), "c".to_string()];
|
||||
let filter_str = "a";
|
||||
let result = super::filter_by_string(reader, filter_str);
|
||||
assert_eq!(result, vec!["a".to_string()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_take(){
|
||||
let reader = vec!["a".to_string(), "b".to_string(), "c".to_string()];
|
||||
let start_index = 1;
|
||||
let end_index = 2;
|
||||
let result = super::take(&mut reader.to_owned(), start_index, end_index);
|
||||
assert_eq!(result, vec!["a".to_string(), "b".to_string()]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user