use syn::Block;
pub fn calculate_cognitive(block: &Block) -> u32 {
crate::complexity::calculate_cognitive_for_block(block)
}
pub fn calculate_cognitive_penalty(nesting_level: u32) -> u32 {
match nesting_level {
0 => 0,
1 => 1,
2 => 2,
3 => 4,
_ => 8, }
}
pub fn combine_cognitive(complexities: Vec<u32>) -> u32 {
complexities.into_iter().sum()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_penalty_levels() {
assert_eq!(calculate_cognitive_penalty(0), 0);
assert_eq!(calculate_cognitive_penalty(1), 1);
assert_eq!(calculate_cognitive_penalty(2), 2);
assert_eq!(calculate_cognitive_penalty(3), 4);
assert_eq!(calculate_cognitive_penalty(4), 8);
assert_eq!(calculate_cognitive_penalty(100), 8);
}
#[test]
fn test_combine_empty() {
assert_eq!(combine_cognitive(vec![]), 0);
}
#[test]
fn test_combine_values() {
assert_eq!(combine_cognitive(vec![1, 2, 3]), 6);
}
}