use symbolic_mgu::logic::create_dict;
use symbolic_mgu::{
get_formatter, EnumTermFactory, MguError, NodeByte, Statement, Term, WideMetavariable,
WideMetavariableFactory,
};
type WideStatement = Statement<
symbolic_mgu::SimpleType,
WideMetavariable,
NodeByte,
symbolic_mgu::EnumTerm<symbolic_mgu::SimpleType, WideMetavariable, NodeByte>,
>;
#[test]
fn stress_test_deep_proof_100_plus_variables() -> Result<(), MguError> {
let depth = 100;
let mut proof = "D1".repeat(depth);
proof.push('1');
println!(
"Testing proof with depth {}: {} characters",
depth,
proof.len()
);
let term_factory = EnumTermFactory::new();
let metavar_factory = WideMetavariableFactory();
let dict = create_dict(
&term_factory,
&metavar_factory,
NodeByte::Implies,
NodeByte::Not,
)?;
let result: WideStatement =
Statement::from_compact_proof(&proof, &metavar_factory, &term_factory, &dict)?;
let vars = result.collect_metavariables()?;
println!("Proof generated {} unique variables", vars.len());
assert!(
vars.len() > 100,
"Expected > 100 variables with depth {}, got {}",
depth,
vars.len()
);
let formatters = vec!["ascii", "utf8", "latex", "display"];
for format_name in formatters {
let formatter = get_formatter(format_name);
let output = result.get_assertion().format_with(&*formatter);
println!("\n=== {} formatter ===", format_name);
println!("Output length: {} characters", output.len());
println!(
"First 200 chars: {}",
&output.chars().take(200).collect::<String>()
);
assert!(
!output.is_empty(),
"{} formatter produced empty output",
format_name
);
assert!(
output.len() < 1_000_000,
"{} formatter produced suspiciously large output: {} chars",
format_name,
output.len()
);
}
Ok(())
}
#[test]
fn stress_test_wide_metavariable_subscripts() -> Result<(), MguError> {
let depth = 15; let mut proof = "D1".repeat(depth);
proof.push('1');
let term_factory = EnumTermFactory::new();
let metavar_factory = WideMetavariableFactory();
let dict = create_dict(
&term_factory,
&metavar_factory,
NodeByte::Implies,
NodeByte::Not,
)?;
let result: WideStatement =
Statement::from_compact_proof(&proof, &metavar_factory, &term_factory, &dict)?;
let vars = result.collect_metavariables()?;
println!("Proof (depth {}) has {} variables", depth, vars.len());
let formatter = get_formatter("utf8");
let output = result.get_assertion().format_with(&*formatter);
println!("UTF8 output: {}", output);
println!("UTF8 output length: {} chars", output.len());
let has_subscripts = output.chars().any(|c| {
matches!(
c,
'\u{2080}'
| '\u{2081}'
| '\u{2082}'
| '\u{2083}'
| '\u{2084}'
| '\u{2085}'
| '\u{2086}'
| '\u{2087}'
| '\u{2088}'
| '\u{2089}'
)
});
assert!(
has_subscripts,
"Expected subscripts with {} variables",
vars.len()
);
Ok(())
}
#[test]
fn stress_test_very_deep_nesting() -> Result<(), MguError> {
let depth = 50;
let mut proof = "D1".repeat(depth);
proof.push('1');
let term_factory = EnumTermFactory::new();
let metavar_factory = WideMetavariableFactory();
let dict = create_dict(
&term_factory,
&metavar_factory,
NodeByte::Implies,
NodeByte::Not,
)?;
let result: WideStatement =
Statement::from_compact_proof(&proof, &metavar_factory, &term_factory, &dict)?;
for format_name in &["ascii", "utf8", "utf8-color", "latex", "display"] {
let formatter = get_formatter(format_name);
let output = result.get_assertion().format_with(&*formatter);
println!("{}: {} chars", format_name, output.len());
assert!(!output.is_empty(), "{} failed on deep nesting", format_name);
}
Ok(())
}