use feagi_evolutionary::{convert_flat_to_hierarchical_full, load_genome_from_json};
use std::fs;
#[test]
fn test_load_barebones_flat_genome() {
let genome_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("genomes")
.join("barebones_genome.json");
let flat_json = fs::read_to_string(&genome_path)
.unwrap_or_else(|_| panic!("Failed to read genome file: {}", genome_path.display()));
let flat_genome: serde_json::Value =
serde_json::from_str(&flat_json).expect("Failed to parse flat genome JSON");
let hierarchical = convert_flat_to_hierarchical_full(&flat_genome)
.expect("Failed to convert flat to hierarchical");
assert!(
hierarchical.get("blueprint").is_some(),
"Missing blueprint section"
);
let blueprint = hierarchical.get("blueprint").unwrap().as_object().unwrap();
assert!(!blueprint.is_empty(), "Blueprint should not be empty");
println!(
"✅ Converted barebones genome: {} cortical areas",
blueprint.len()
);
let hierarchical_json = serde_json::to_string_pretty(&hierarchical)
.expect("Failed to serialize hierarchical genome");
let runtime_genome = load_genome_from_json(&hierarchical_json)
.expect("Failed to load converted genome as RuntimeGenome");
assert!(
!runtime_genome.cortical_areas.is_empty(),
"Should have cortical areas"
);
println!(
"✅ Loaded as RuntimeGenome: {} cortical areas, {} morphologies",
runtime_genome.cortical_areas.len(),
runtime_genome.morphologies.count()
);
}
#[test]
fn test_load_all_flat_genomes() {
let genome_files = [
"barebones_genome.json",
"essential_genome.json",
"test_genome.json",
"vision_genome.json",
];
for genome_path in genome_files {
let genome_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("genomes")
.join(genome_path);
println!("\n📂 Testing: {}", genome_path.display());
match fs::read_to_string(&genome_path) {
Ok(flat_json) => match serde_json::from_str::<serde_json::Value>(&flat_json) {
Ok(flat_genome) => match convert_flat_to_hierarchical_full(&flat_genome) {
Ok(hierarchical) => {
let blueprint = hierarchical
.get("blueprint")
.and_then(|b| b.as_object())
.expect("Missing or invalid blueprint");
println!(" ✅ Converted: {} cortical areas", blueprint.len());
}
Err(e) => {
println!(" ❌ Conversion failed: {}", e);
panic!("Conversion failed for {}: {}", genome_path.display(), e);
}
},
Err(e) => {
println!(" ❌ JSON parse failed: {}", e);
panic!("JSON parse failed for {}: {}", genome_path.display(), e);
}
},
Err(e) => {
println!(" ⚠️ File not found: {}", e);
}
}
}
}