mecha10-cli 0.9.0

Mecha10 CLI tool
Documentation

use mecha10_cli::services::simulation::*;

use std::path::{Path, PathBuf};
use tempfile::TempDir;


#[test]
fn test_new_service() {
    let service = SimulationService::new();
    assert_eq!(service.base_path(), Path::new("configs/simulation/output"));
}

#[test]
fn test_with_base_path() {
    let service = SimulationService::with_base_path("custom/path");
    assert_eq!(service.base_path(), Path::new("custom/path"));
}

#[test]
fn test_with_base_path_string() {
    let service = SimulationService::with_base_path(String::from("another/path"));
    assert_eq!(service.base_path(), Path::new("another/path"));
}

#[test]
fn test_with_base_path_pathbuf() {
    let path = PathBuf::from("path/from/pathbuf");
    let service = SimulationService::with_base_path(path);
    assert_eq!(service.base_path(), Path::new("path/from/pathbuf"));
}

#[test]
fn test_with_base_path_absolute() {
    let service = SimulationService::with_base_path("/absolute/path");
    assert_eq!(service.base_path(), Path::new("/absolute/path"));
}

#[test]
fn test_with_base_path_relative() {
    let service = SimulationService::with_base_path("./relative/path");
    assert_eq!(service.base_path(), Path::new("./relative/path"));
}

#[test]
fn test_default_trait() {
    let service = SimulationService::default();
    assert_eq!(service.base_path(), Path::new("configs/simulation/output"));
}

#[test]
fn test_default_equals_new() {
    let service1 = SimulationService::new();
    let service2 = SimulationService::default();
    assert_eq!(service1.base_path(), service2.base_path());
}


#[test]
fn test_base_path_getter() {
    let service = SimulationService::with_base_path("test/path");
    assert_eq!(service.base_path(), Path::new("test/path"));
}

#[test]
fn test_base_path_immutable() {
    let service = SimulationService::with_base_path("original");
    let path1 = service.base_path();
    let path2 = service.base_path();
    assert_eq!(path1, path2);
    assert_eq!(path1, Path::new("original"));
}

#[test]
fn test_multiple_services_independent() {
    let service1 = SimulationService::with_base_path("path1");
    let service2 = SimulationService::with_base_path("path2");

    assert_eq!(service1.base_path(), Path::new("path1"));
    assert_eq!(service2.base_path(), Path::new("path2"));
}


#[test]
fn test_is_setup_false_when_path_missing() {
    let temp = TempDir::new().unwrap();
    let service = SimulationService::with_base_path(temp.path().join("nonexistent"));
    assert!(!service.is_setup());
}

#[test]
fn test_is_setup_false_when_robot_scene_missing() {
    let temp = TempDir::new().unwrap();
    std::fs::create_dir_all(temp.path()).unwrap();

    let service = SimulationService::with_base_path(temp.path());
    assert!(!service.is_setup());
}

#[test]
fn test_is_setup_true_when_robot_scene_exists() {
    let temp = TempDir::new().unwrap();
    let robot_scene = temp.path().join("robot.tscn");
    std::fs::write(&robot_scene, "").unwrap();

    let service = SimulationService::with_base_path(temp.path());
    assert!(service.is_setup());
}


#[test]
fn test_generation_result_creation() {
    let result = GenerationResult {
        robot_scene: PathBuf::from("output/robot.tscn"),
        environments: vec!["warehouse".to_string(), "office".to_string()],
        available_count: 2,
    };

    assert_eq!(result.robot_scene, PathBuf::from("output/robot.tscn"));
    assert_eq!(result.environments.len(), 2);
    assert_eq!(result.available_count, 2);
}

#[test]
fn test_generation_result_debug() {
    let result = GenerationResult {
        robot_scene: PathBuf::from("robot.tscn"),
        environments: vec!["env1".to_string()],
        available_count: 1,
    };

    let debug_str = format!("{:?}", result);
    assert!(debug_str.contains("GenerationResult"));
    assert!(debug_str.contains("robot.tscn"));
}


#[test]
fn test_environment_info_creation() {
    let info = EnvironmentInfo {
        id: "warehouse-1".to_string(),
        name: "Warehouse".to_string(),
        description: "A large warehouse environment".to_string(),
        score: 85,
        available: true,
    };

    assert_eq!(info.id, "warehouse-1");
    assert_eq!(info.name, "Warehouse");
    assert_eq!(info.score, 85);
    assert!(info.available);
}

#[test]
fn test_environment_info_clone() {
    let info1 = EnvironmentInfo {
        id: "env1".to_string(),
        name: "Environment 1".to_string(),
        description: "Description".to_string(),
        score: 75,
        available: false,
    };

    let info2 = info1.clone();

    assert_eq!(info1.id, info2.id);
    assert_eq!(info1.name, info2.name);
    assert_eq!(info1.score, info2.score);
    assert_eq!(info1.available, info2.available);
}

#[test]
fn test_environment_info_debug() {
    let info = EnvironmentInfo {
        id: "test-env".to_string(),
        name: "Test Environment".to_string(),
        description: "For testing".to_string(),
        score: 90,
        available: true,
    };

    let debug_str = format!("{:?}", info);
    assert!(debug_str.contains("EnvironmentInfo"));
    assert!(debug_str.contains("test-env"));
}


#[test]
fn test_validation_result_valid() {
    let result = ValidationResult {
        is_valid: true,
        errors: vec![],
        warnings: vec!["No sensors configured".to_string()],
        platform: "rover".to_string(),
        sensor_count: 0,
        node_count: 3,
    };

    assert!(result.is_valid);
    assert!(result.errors.is_empty());
    assert_eq!(result.warnings.len(), 1);
    assert_eq!(result.platform, "rover");
}

#[test]
fn test_validation_result_invalid() {
    let result = ValidationResult {
        is_valid: false,
        errors: vec!["Platform not specified".to_string()],
        warnings: vec![],
        platform: String::new(),
        sensor_count: 2,
        node_count: 1,
    };

    assert!(!result.is_valid);
    assert_eq!(result.errors.len(), 1);
    assert!(result.warnings.is_empty());
}

#[test]
fn test_validation_result_debug() {
    let result = ValidationResult {
        is_valid: true,
        errors: vec![],
        warnings: vec![],
        platform: "arm".to_string(),
        sensor_count: 5,
        node_count: 2,
    };

    let debug_str = format!("{:?}", result);
    assert!(debug_str.contains("ValidationResult"));
    assert!(debug_str.contains("true"));
    assert!(debug_str.contains("arm"));
}


#[test]
fn test_generate_robot_method_exists() {
    let temp = TempDir::new().unwrap();
    let config = temp.path().join("mecha10.json");
    let output = temp.path().join("robot.tscn");

    let service = SimulationService::new();
    let _ = service.generate_robot(&config, &output);
}

#[test]
fn test_list_environments_method_exists() {
    let temp = TempDir::new().unwrap();
    let config = temp.path().join("mecha10.json");
    let robot_tasks_dir = temp.path().join("robot-tasks");

    let service = SimulationService::new();
    let _ = service.list_environments(&config, &robot_tasks_dir, false);
}

#[test]
fn test_validate_config_method_exists() {
    let temp = TempDir::new().unwrap();
    let config = temp.path().join("mecha10.json");

    let service = SimulationService::new();
    let _ = service.validate_config(&config);
}


#[test]
fn test_base_path_with_empty_string() {
    let service = SimulationService::with_base_path("");
    assert_eq!(service.base_path(), Path::new(""));
}

#[test]
fn test_base_path_with_unicode() {
    let service = SimulationService::with_base_path("模拟/路径");
    assert_eq!(service.base_path(), Path::new("模拟/路径"));
}

#[test]
fn test_base_path_with_special_characters() {
    let service = SimulationService::with_base_path("path with spaces/and-dashes");
    assert_eq!(service.base_path(), Path::new("path with spaces/and-dashes"));
}

#[test]
fn test_generation_result_empty_environments() {
    let result = GenerationResult {
        robot_scene: PathBuf::from("robot.tscn"),
        environments: vec![],
        available_count: 0,
    };

    assert!(result.environments.is_empty());
    assert_eq!(result.available_count, 0);
}

#[test]
fn test_validation_result_with_multiple_errors_and_warnings() {
    let result = ValidationResult {
        is_valid: false,
        errors: vec!["Error 1".to_string(), "Error 2".to_string(), "Error 3".to_string()],
        warnings: vec!["Warning 1".to_string(), "Warning 2".to_string()],
        platform: "test".to_string(),
        sensor_count: 0,
        node_count: 0,
    };

    assert_eq!(result.errors.len(), 3);
    assert_eq!(result.warnings.len(), 2);
}