use strange_loop::*;
use strange_loop::nano_agent::*;
use strange_loop::nano_agent::agents::*;
use std::time::Duration;
use std::thread;
#[test]
fn test_nano_agent_framework() {
println!("ð§ Testing nano-agent framework with multiple agents...");
let config = SchedulerConfig {
topology: SchedulerTopology::Mesh,
run_duration_ns: 10_000_000, tick_duration_ns: 100_000, max_agents: 10,
bus_capacity: 1000,
enable_tracing: true,
};
let mut scheduler = NanoScheduler::new(config);
scheduler.add_agent(Box::new(SensorAgent::new(10)));
scheduler.add_agent(Box::new(SensorAgent::new(20)));
scheduler.add_agent(Box::new(DebounceAgent::new(3)));
scheduler.add_agent(Box::new(TemporalPredictorAgent::new()));
assert_eq!(scheduler.agent_count(), 4);
let metrics = scheduler.run();
println!("â
Nano-agent framework: {} agents, {} total ticks",
scheduler.agent_count(), metrics.total_ticks);
assert!(metrics.total_ticks > 0);
assert_eq!(metrics.agent_count, 4);
}
#[cfg(feature = "quantum")]
#[test]
fn test_quantum_classical_hybrid() {
println!("ð Testing quantum-classical hybrid computing...");
use strange_loop::quantum_container::QuantumContainer;
use strange_loop::types::QuantumAmplitude;
let mut quantum = QuantumContainer::new(3);
let amplitude = QuantumAmplitude::new(1.0 / (8.0_f64).sqrt(), 0.0);
for i in 0..8 {
quantum.set_superposition_state(i, amplitude);
}
let mut measurements = Vec::new();
for _ in 0..100 {
measurements.push(quantum.measure());
}
let unique_states: std::collections::HashSet<_> = measurements.iter().collect();
println!("â
Quantum system: {} unique states measured from {} trials",
unique_states.len(), measurements.len());
assert!(unique_states.len() >= 2);
quantum.store_classical("test_key".to_string(), 42.0);
let stored = quantum.get_classical("test_key");
assert_eq!(stored, Some(42.0));
println!("â
Quantum-classical hybrid validated");
}
#[cfg(feature = "consciousness")]
#[test]
fn test_temporal_consciousness() {
println!("ð§ Testing temporal consciousness evolution...");
use strange_loop::temporal_consciousness::TemporalConsciousness;
use strange_loop::consciousness::ConsciousnessConfig;
let config = ConsciousnessConfig {
max_iterations: 100,
convergence_threshold: 1e-3,
integration_steps: 10,
memory_decay: 0.95,
plasticity_rate: 0.01,
enable_time_dilation: true,
temporal_horizon_ns: 1_000_000, novelty_sensitivity: 0.1,
feedback_strength: 0.2,
};
let mut consciousness = TemporalConsciousness::new(config).unwrap();
let result = consciousness.evolve();
println!("â
Consciousness evolution: {:?}", result);
let patterns = consciousness.get_temporal_patterns();
println!("â
Temporal patterns detected: {} patterns", patterns.len());
assert!(result.is_ok());
assert!(!patterns.is_empty());
println!("â
Temporal consciousness validated");
}
#[test]
fn test_strange_attractor_dynamics() {
println!("ðŠïļ Testing strange attractor dynamics...");
use strange_loop::strange_attractor::{StrangeAttractor, AttractorType, AttractorConfig};
let config = AttractorConfig {
attractor_type: AttractorType::Lorenz,
dt: 0.01,
max_history: 1000,
chaos_threshold: 1e-6,
};
let mut attractor = StrangeAttractor::new(config);
let mut trajectory = Vec::new();
for _ in 0..100 {
trajectory.push(attractor.step().unwrap());
}
println!("â
Strange attractor: {} trajectory points generated", trajectory.len());
let lyapunov = attractor.lyapunov_exponent(10);
println!("â
Lyapunov exponent: {:.6}", lyapunov);
let mut attractor2 = attractor.clone();
let perturbation = Vector3D::new(1e-10, 1e-10, 1e-10);
attractor2.perturb(perturbation);
let state1 = attractor.step().unwrap();
let state2 = attractor2.step().unwrap();
let divergence = state1.distance(&state2);
println!("â
Chaos sensitivity: divergence = {:.2e}", divergence);
assert!(trajectory.len() == 100);
assert!(lyapunov.is_finite());
println!("â
Strange attractor dynamics validated");
}
#[test]
fn test_retrocausal_feedback() {
println!("⊠Testing retrocausal feedback loops...");
use strange_loop::retrocausal::RetrocausalLoop;
let mut retro = RetrocausalLoop::new(0.1);
retro.add_constraint(1000, Box::new(|x| x > 0.5), 0.8);
retro.add_constraint(2000, Box::new(|x| x < 0.3), 0.6);
let influenced = retro.apply_feedback(0.4, 500);
println!("â
Retrocausal influence: {:.3} -> {:.3}", 0.4, influenced);
let violations = retro.check_violations(1500);
println!("â
Violations detected: {}", violations);
assert!((influenced - 0.4).abs() < 1.0);
println!("â
Retrocausal feedback validated");
}
#[test]
fn test_self_modifying_behavior() {
println!("ð§Ž Testing self-modifying behavior...");
use strange_loop::self_modifying::SelfModifyingLoop;
let mut evolving = SelfModifyingLoop::new(0.1);
let initial_output = evolving.execute(1.0);
println!("â
Initial output: {:.6}", initial_output);
for generation in 0..50 {
let output = evolving.execute(1.0);
let target = 1.618033988749; let fitness = 1.0 / (1.0 + (output - target).abs());
evolving.evolve(fitness);
if generation % 10 == 0 {
let metrics = evolving.get_metrics();
println!("Generation {}: fitness = {:.6}, output = {:.6}",
generation, metrics.current_fitness, output);
}
}
let final_metrics = evolving.get_metrics();
println!("â
Evolution complete: final fitness = {:.6}", final_metrics.current_fitness);
assert!(final_metrics.current_fitness >= 0.1);
assert_eq!(final_metrics.generation, 50);
println!("â
Self-modifying behavior validated");
}
#[test]
fn test_temporal_prediction() {
println!("â° Testing temporal prediction capabilities...");
let mut predictor = TemporalLeadPredictor::new(1_000_000, 100);
let mut predictions = Vec::new();
for i in 0..20 {
let state = vec![i as f64, (i * 2) as f64, (i * i) as f64];
let prediction = predictor.predict_future(state);
predictions.push(prediction);
}
println!("â
Temporal predictions: {} predictions generated", predictions.len());
let last_prediction = &predictions[predictions.len()-1];
assert_eq!(last_prediction.len(), 3);
for &value in last_prediction {
assert!(value.is_finite());
}
println!("â
Temporal prediction validated");
}
#[test]
fn test_performance_benchmarks() {
println!("⥠Running performance benchmarks...");
let start = std::time::Instant::now();
let config = SchedulerConfig {
topology: SchedulerTopology::Mesh,
run_duration_ns: 1_000_000, tick_duration_ns: 10_000, max_agents: 5,
bus_capacity: 500,
enable_tracing: false,
};
let mut scheduler = NanoScheduler::new(config);
scheduler.add_agent(Box::new(SensorAgent::new(5)));
scheduler.add_agent(Box::new(DebounceAgent::new(2)));
let metrics = scheduler.run();
let elapsed = start.elapsed();
let ticks_per_second = (metrics.total_ticks as f64) / elapsed.as_secs_f64();
println!("â
Nano-agent throughput: {:.0} ticks/second", ticks_per_second);
assert!(ticks_per_second > 1000.0); assert!(metrics.budget_violations == 0);
println!("â
Performance benchmarks validated");
}
#[test]
fn test_integration_all_systems() {
println!("ð Testing integration of all systems...");
let config = SchedulerConfig {
topology: SchedulerTopology::Mesh,
run_duration_ns: 5_000_000, tick_duration_ns: 50_000, max_agents: 8,
bus_capacity: 1000,
enable_tracing: true,
};
let mut scheduler = NanoScheduler::new(config);
scheduler.add_agent(Box::new(SensorAgent::new(10)));
scheduler.add_agent(Box::new(DebounceAgent::new(3)));
scheduler.add_agent(Box::new(QuantumDecisionAgent::new()));
scheduler.add_agent(Box::new(TemporalPredictorAgent::new()));
scheduler.add_agent(Box::new(EvolvingAgent::new()));
let metrics = scheduler.run();
println!("â
Integration test: {} agents, {} ticks, {} violations",
metrics.agent_count, metrics.total_ticks, metrics.budget_violations);
assert_eq!(metrics.agent_count, 5);
assert!(metrics.total_ticks > 0);
println!("â
Full system integration validated");
}
#[test]
fn test_framework_completeness() {
println!("ð Verifying framework completeness...");
let _vector = Vector3D::new(1.0, 2.0, 3.0);
println!("â
Vector3D system available");
#[cfg(feature = "quantum")]
{
let _quantum = strange_loop::quantum_container::QuantumContainer::new(2);
println!("â
Quantum computing system available");
}
#[cfg(feature = "consciousness")]
{
use strange_loop::consciousness::ConsciousnessConfig;
let _config = ConsciousnessConfig::default();
println!("â
Consciousness system available");
}
let _attractor = strange_loop::strange_attractor::StrangeAttractor::new(
strange_loop::strange_attractor::AttractorConfig::default()
);
println!("â
Strange attractor system available");
let _retro = strange_loop::retrocausal::RetrocausalLoop::new(0.1);
println!("â
Retrocausal system available");
let _self_mod = strange_loop::self_modifying::SelfModifyingLoop::new(0.1);
println!("â
Self-modifying system available");
let _predictor = TemporalLeadPredictor::new(1_000_000, 100);
println!("â
Temporal prediction system available");
println!("â
Framework completeness verified - all systems operational");
}