use debtmap::priority::complexity_patterns::{ComplexityMetrics, ComplexityPattern};
#[test]
fn chaotic_pattern_uses_token_entropy_not_effective_complexity() {
let metrics = ComplexityMetrics {
cyclomatic: 15,
cognitive: 50,
nesting: 3,
entropy_score: Some(0.6), state_signals: None,
coordinator_signals: None,
validation_signals: None,
};
let pattern = ComplexityPattern::detect(&metrics);
if let ComplexityPattern::ChaoticStructure { entropy, .. } = pattern {
assert!(
(entropy - 0.6).abs() < 0.01,
"Pattern should use provided entropy value, got {}",
entropy
);
} else {
panic!("Expected ChaoticStructure pattern for entropy 0.6");
}
}
#[test]
fn below_threshold_not_chaotic() {
let metrics = ComplexityMetrics {
cyclomatic: 15,
cognitive: 50,
nesting: 3,
entropy_score: Some(0.44), state_signals: None,
coordinator_signals: None,
validation_signals: None,
};
let pattern = ComplexityPattern::detect(&metrics);
assert!(
!matches!(pattern, ComplexityPattern::ChaoticStructure { .. }),
"entropy 0.44 should not trigger chaotic pattern"
);
}
#[test]
fn at_threshold_is_chaotic() {
let metrics = ComplexityMetrics {
cyclomatic: 15,
cognitive: 50,
nesting: 3,
entropy_score: Some(0.45), state_signals: None,
coordinator_signals: None,
validation_signals: None,
};
let pattern = ComplexityPattern::detect(&metrics);
assert!(
matches!(pattern, ComplexityPattern::ChaoticStructure { .. }),
"entropy 0.45 should trigger chaotic pattern"
);
}
#[test]
fn chaotic_pattern_takes_precedence() {
let metrics = ComplexityMetrics {
cyclomatic: 12,
cognitive: 50, nesting: 5, entropy_score: Some(0.6), state_signals: None,
coordinator_signals: None,
validation_signals: None,
};
let pattern = ComplexityPattern::detect(&metrics);
assert!(
matches!(pattern, ComplexityPattern::ChaoticStructure { .. }),
"chaotic pattern should take precedence over high nesting"
);
}
#[test]
fn none_entropy_allows_other_patterns() {
let metrics = ComplexityMetrics {
cyclomatic: 12,
cognitive: 50, nesting: 5, entropy_score: None, state_signals: None,
coordinator_signals: None,
validation_signals: None,
};
let pattern = ComplexityPattern::detect(&metrics);
assert!(
matches!(pattern, ComplexityPattern::HighNesting { .. }),
"should detect high nesting when entropy is None"
);
}