use pattern_core::Pattern;
#[test]
fn test_element_counts_no_trailing_zeros() {
let atomic = Pattern::point("atom".to_string());
let analysis = atomic.analyze_structure();
assert_eq!(
analysis.element_counts,
Vec::<usize>::new(),
"Atomic pattern should have empty element_counts"
);
let tree = Pattern::pattern(
"root".to_string(),
vec![
Pattern::point("child1".to_string()),
Pattern::point("child2".to_string()),
Pattern::point("child3".to_string()),
],
);
let analysis = tree.analyze_structure();
assert_eq!(
analysis.element_counts,
vec![3],
"2-level tree should have [3], not [3, 0]"
);
let nested = Pattern::pattern(
"root".to_string(),
vec![Pattern::pattern(
"node".to_string(),
vec![Pattern::point("leaf".to_string())],
)],
);
let analysis = nested.analyze_structure();
assert_eq!(
analysis.element_counts,
vec![1, 1],
"3-level linear tree should have [1, 1], not [1, 1, 0]"
);
}
#[test]
fn test_balanced_pattern_2_levels() {
let child1 = Pattern::pattern(
"child1".to_string(),
vec![
Pattern::point("leaf1".to_string()),
Pattern::point("leaf2".to_string()),
],
);
let child2 = Pattern::pattern(
"child2".to_string(),
vec![
Pattern::point("leaf3".to_string()),
Pattern::point("leaf4".to_string()),
],
);
let root = Pattern::pattern("root".to_string(), vec![child1, child2]);
let analysis = root.analyze_structure();
println!("Element counts: {:?}", analysis.element_counts);
println!("Nesting patterns: {:?}", analysis.nesting_patterns);
assert!(
analysis.nesting_patterns.contains(&"balanced".to_string()),
"2-level pattern with consistent counts should be identified as balanced. Got: {:?}",
analysis.nesting_patterns
);
}