<commit_before>use std::ops::AddAssign;
use std::collections:: { HashMap };
use std::collections::hash_map:: { Iter };
use lcov_parser:: { FunctionData };

type FunctionName = String;
type ExecutionCount = u32;

#[derive(Debug, Clone)]
pub struct Functions {
    functions: HashMap<FunctionName, ExecutionCount>
}

impl Functions {
    pub fn new() -> Self {
        Functions {
            functions: HashMap::new()
        }
    }
    pub fn iter(&self) -> Iter<FunctionName, ExecutionCount> {
        self.functions.iter()
    }
    pub fn get(&self, key: &FunctionName) -> Option<&ExecutionCount> {
        self.functions.get(key)
    }
}

impl<'a> AddAssign<&'a FunctionData> for Functions {
    fn add_assign(&mut self, data: &'a FunctionData) {
        if !self.functions.contains_key(&data.name) {
            self.functions.insert(data.name.clone(), data.count.clone());
            return;
        }
        let mut func_count = self.functions.get_mut(&data.name).unwrap();
        *func_count += data.count;
    }
}

impl<'a> AddAssign<&'a Functions> for Functions {
    fn add_assign(&mut self, other: &'a Functions) {
        for (name, count) in other.iter() {
            if !self.functions.contains_key(name) {
                self.functions.insert(name.clone(), *count);
                continue;
            }
            let current_count = self.functions.get_mut(name).unwrap();
            *current_count += *count;
        }
    }
}


#[cfg(test)]
mod tests {
    use lcov_parser:: { FunctionData };
    use function:: { Functions };

    #[test]
    fn add_function_data() {
        let mut functions = Functions::new();
        functions += &FunctionData { name: "main".to_string(), count: 1 };
        functions += &FunctionData { name: "main".to_string(), count: 1 };

        let result = functions.clone();
        assert_eq!( result.get(&"main".to_string()), Some(&2u32) );
    }

    #[test]
    fn add_lines_data() {
        let mut functions = Functions::new();
        functions += &FunctionData { name: "main".to_string(), count: 1 };

        let ref cloned_functions = functions.clone();
        functions += cloned_functions;

        assert_eq!( functions.get(&"main".to_string()), Some(&2u32) );
    }
}<commit_msg>rename test function<commit_after>use std::ops::AddAssign;
use std::collections:: { HashMap };
use std::collections::hash_map:: { Iter };
use lcov_parser:: { FunctionData };

type FunctionName = String;
type ExecutionCount = u32;

#[derive(Debug, Clone)]
pub struct Functions {
    functions: HashMap<FunctionName, ExecutionCount>
}

impl Functions {
    pub fn new() -> Self {
        Functions {
            functions: HashMap::new()
        }
    }
    pub fn iter(&self) -> Iter<FunctionName, ExecutionCount> {
        self.functions.iter()
    }
    pub fn get(&self, key: &FunctionName) -> Option<&ExecutionCount> {
        self.functions.get(key)
    }
}

impl<'a> AddAssign<&'a FunctionData> for Functions {
    fn add_assign(&mut self, data: &'a FunctionData) {
        if !self.functions.contains_key(&data.name) {
            self.functions.insert(data.name.clone(), data.count.clone());
            return;
        }
        let mut func_count = self.functions.get_mut(&data.name).unwrap();
        *func_count += data.count;
    }
}

impl<'a> AddAssign<&'a Functions> for Functions {
    fn add_assign(&mut self, other: &'a Functions) {
        for (name, count) in other.iter() {
            if !self.functions.contains_key(name) {
                self.functions.insert(name.clone(), *count);
                continue;
            }
            let current_count = self.functions.get_mut(name).unwrap();
            *current_count += *count;
        }
    }
}


#[cfg(test)]
mod tests {
    use lcov_parser:: { FunctionData };
    use function:: { Functions };

    #[test]
    fn add_function_data() {
        let mut functions = Functions::new();
        functions += &FunctionData { name: "main".to_string(), count: 1 };
        functions += &FunctionData { name: "main".to_string(), count: 1 };

        let result = functions.clone();
        assert_eq!( result.get(&"main".to_string()), Some(&2u32) );
    }

    #[test]
    fn add_function_data() {
        let mut functions = Functions::new();
        functions += &FunctionData { name: "main".to_string(), count: 1 };

        let ref cloned_functions = functions.clone();
        functions += cloned_functions;

        assert_eq!( functions.get(&"main".to_string()), Some(&2u32) );
    }
}
{'fraction_non_alphanumeric': 0.150066401062417, 'fraction_numerical': 0.004869411243913236, 'mean_word_length': 2.6355591311343525, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4353458', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1356, 'n_words': 304}