use certeza::chaos::{ChaosConfig, ChaosError};
use certeza::{add, multiply, subtract, TruenoVec};
use std::time::Duration;
fn main() {
println!("=== Certeza Quality Check Demo ===\n");
println!("--- TruenoVec (verified vector) ---");
let mut vec = TruenoVec::new();
for i in 1..=5 {
vec.push(i);
}
println!("Pushed 1..5 -> len={}, capacity={}", vec.len(), vec.capacity());
println!("vec[2] = {:?}", vec.get(2));
println!("pop() = {:?}", vec.pop());
println!("After pop: len={}", vec.len());
let mut preallocated = TruenoVec::with_capacity(1000);
for i in 0..1000 {
preallocated.push(i);
}
println!(
"Pre-allocated 1000 elements: len={}, capacity={}",
preallocated.len(),
preallocated.capacity()
);
println!("\n--- Arithmetic (property-tested) ---");
println!("add(40, 2) = {}", add(40, 2));
println!("subtract(100, 58) = {}", subtract(100, 58));
println!("multiply(6, 7) = {}", multiply(6, 7));
assert_eq!(add(3, 7), add(7, 3));
assert_eq!(multiply(4, 9), multiply(9, 4));
println!("Commutativity verified for add and multiply.");
println!("\n--- Chaos Engineering (renacer presets) ---");
let gentle = ChaosConfig::gentle();
println!(
"Gentle: memory={}MB, cpu={:.0}%, timeout={}s",
gentle.memory_limit / (1024 * 1024),
gentle.cpu_limit * 100.0,
gentle.timeout.as_secs()
);
let aggressive = ChaosConfig::aggressive();
println!(
"Aggressive: memory={}MB, cpu={:.0}%, timeout={}s, signals={}",
aggressive.memory_limit / (1024 * 1024),
aggressive.cpu_limit * 100.0,
aggressive.timeout.as_secs(),
aggressive.signal_injection
);
let custom = ChaosConfig::new()
.with_memory_limit(256 * 1024 * 1024)
.with_cpu_limit(0.75)
.with_timeout(Duration::from_secs(60))
.with_signal_injection(false)
.build();
println!(
"Custom: memory={}MB, cpu={:.0}%, timeout={}s",
custom.memory_limit / (1024 * 1024),
custom.cpu_limit * 100.0,
custom.timeout.as_secs()
);
let err =
ChaosError::Timeout { elapsed: Duration::from_secs(15), limit: Duration::from_secs(10) };
println!("\nExample chaos error: {err}");
println!("\nAll checks passed.");
}