use super::*;
#[test]
fn p061_conversion_lossless() {
let report = ConversionReport {
path: ConversionPath::direct(FormatType::Gguf, FormatType::Apr),
source_inspection: InspectionReport {
format: FormatType::Gguf,
file_size: 1000,
metadata: BTreeMap::new(),
tensors: vec![],
total_params: 100,
quantization: None,
architecture: None,
},
target_inspection: InspectionReport {
format: FormatType::Apr,
file_size: 1000,
metadata: BTreeMap::new(),
tensors: vec![],
total_params: 100,
quantization: None,
architecture: None,
},
warnings: vec![],
duration_ms: 100,
modified_tensors: vec![],
dropped_tensors: vec![],
};
assert!(report.is_lossless());
assert!(report.tensor_counts_match());
}
#[test]
fn p062_conversion_with_dropped_tensors() {
let report = ConversionReport {
path: ConversionPath::direct(FormatType::Gguf, FormatType::Apr),
source_inspection: InspectionReport {
format: FormatType::Gguf,
file_size: 1000,
metadata: BTreeMap::new(),
tensors: vec![
TensorInfo {
name: "layer.0".to_string(),
dtype: "F32".to_string(),
shape: vec![100, 100],
size_bytes: 40000,
stats: None,
},
TensorInfo {
name: "layer.1".to_string(),
dtype: "F32".to_string(),
shape: vec![100, 100],
size_bytes: 40000,
stats: None,
},
],
total_params: 20000,
quantization: None,
architecture: None,
},
target_inspection: InspectionReport {
format: FormatType::Apr,
file_size: 800,
metadata: BTreeMap::new(),
tensors: vec![TensorInfo {
name: "layer.0".to_string(),
dtype: "F32".to_string(),
shape: vec![100, 100],
size_bytes: 40000,
stats: None,
}],
total_params: 10000,
quantization: None,
architecture: None,
},
warnings: vec!["Tensor dropped".to_string()],
duration_ms: 100,
modified_tensors: vec![],
dropped_tensors: vec!["layer.1".to_string()],
};
assert!(!report.is_lossless());
assert!(!report.tensor_counts_match());
}
#[test]
fn p063_conversion_warnings() {
let report = ConversionReport {
path: ConversionPath::direct(FormatType::Gguf, FormatType::Apr),
source_inspection: InspectionReport {
format: FormatType::Gguf,
file_size: 1000,
metadata: BTreeMap::new(),
tensors: vec![],
total_params: 0,
quantization: None,
architecture: None,
},
target_inspection: InspectionReport {
format: FormatType::Apr,
file_size: 1000,
metadata: BTreeMap::new(),
tensors: vec![],
total_params: 0,
quantization: None,
architecture: None,
},
warnings: vec!["Warning 1".to_string(), "Warning 2".to_string()],
duration_ms: 50,
modified_tensors: vec![],
dropped_tensors: vec![],
};
assert_eq!(report.warnings.len(), 2);
assert!(report.is_lossless());
}
#[test]
fn p071_tensor_info_creation() {
let info = TensorInfo {
name: "model.embed".to_string(),
dtype: "F32".to_string(),
shape: vec![32000, 4096],
size_bytes: 32000 * 4096 * 4,
stats: None,
};
assert_eq!(info.name, "model.embed");
assert_eq!(info.dtype, "F32");
}
#[test]
fn p072_tensor_info_with_stats() {
let stats = TensorStats {
min: -1.0,
max: 1.0,
mean: 0.0,
std: 0.5,
};
let info = TensorInfo {
name: "layer.weight".to_string(),
dtype: "F16".to_string(),
shape: vec![1024, 1024],
size_bytes: 1024 * 1024 * 2,
stats: Some(stats),
};
assert!(info.stats.is_some());
let s = info.stats.unwrap();
assert_eq!(s.min, -1.0);
assert_eq!(s.max, 1.0);
}
#[test]
fn p073_tensor_info_multidim_shape() {
let info = TensorInfo {
name: "conv.weight".to_string(),
dtype: "F32".to_string(),
shape: vec![64, 32, 3, 3],
size_bytes: 64 * 32 * 3 * 3 * 4,
stats: None,
};
assert_eq!(info.shape.len(), 4);
let total: usize = info.shape.iter().product();
assert_eq!(total, 64 * 32 * 3 * 3);
}
#[test]
fn p074_tensor_stats_range() {
let stats = TensorStats {
min: -2.5,
max: 2.5,
mean: 0.01,
std: 1.0,
};
assert!(stats.min < stats.max);
assert!(stats.mean >= stats.min && stats.mean <= stats.max);
}
#[test]
fn p081_inspection_report_format() {
let report = InspectionReport {
format: FormatType::Gguf,
file_size: 1_000_000,
metadata: BTreeMap::new(),
tensors: vec![],
total_params: 100_000,
quantization: None,
architecture: None,
};
assert_eq!(report.format, FormatType::Gguf);
assert_eq!(report.file_size, 1_000_000);
}
#[test]
fn p082_inspection_report_with_metadata() {
let mut metadata = BTreeMap::new();
metadata.insert("model_name".to_string(), "test-model".to_string());
metadata.insert("version".to_string(), "1.0".to_string());
let report = InspectionReport {
format: FormatType::Apr,
file_size: 500_000,
metadata,
tensors: vec![],
total_params: 50_000,
quantization: None,
architecture: Some("transformer".to_string()),
};
assert_eq!(report.metadata.len(), 2);
assert!(report.architecture.is_some());
}
#[test]
fn p083_inspection_report_with_quantization() {
let report = InspectionReport {
format: FormatType::Gguf,
file_size: 2_000_000,
metadata: BTreeMap::new(),
tensors: vec![],
total_params: 1_000_000,
quantization: Some("Q4_K_M".to_string()),
architecture: Some("llama".to_string()),
};
assert_eq!(report.quantization, Some("Q4_K_M".to_string()));
}
#[test]
fn p084_inspection_report_display() {
let report = InspectionReport {
format: FormatType::SafeTensors,
file_size: 100,
metadata: BTreeMap::new(),
tensors: vec![],
total_params: 10,
quantization: None,
architecture: None,
};
let display = format!("{}", report);
assert!(display.contains("Rosetta Stone Inspection"));
assert!(display.contains("SafeTensors"));
}
#[test]
fn p091_pdf_imposter_test() {
let temp_dir = std::env::temp_dir();
let fake_gguf = temp_dir.join("fake.gguf");
std::fs::write(&fake_gguf, b"%PDF-1.4\n").expect("Write test file");
let result = FormatType::from_magic(&fake_gguf);
let _ = std::fs::remove_file(&fake_gguf);
assert!(
result.is_err(),
"PDF disguised as GGUF should fail magic detection"
);
}
#[test]
fn p092_unicode_ghost_test() {
let path = Path::new("模型_テスト_🤖.gguf");
let format = FormatType::from_extension(path);
assert!(
format.is_ok(),
"Unicode path should parse extension correctly"
);
}
#[test]
fn p093_infinite_loop_test() {
let _rosetta = RosettaStone::new();
let chain = vec![
FormatType::Gguf,
FormatType::Apr,
FormatType::Gguf,
FormatType::Apr,
FormatType::SafeTensors,
];
let path = ConversionPath {
source: chain[0],
target: chain[chain.len() - 1],
intermediates: chain[1..chain.len() - 1].to_vec(),
};
assert!(
path.has_cycle(),
"Chain with repeated formats should have cycle"
);
}
#[test]
fn p094_zero_size_file_test() {
let temp_dir = std::env::temp_dir();
let empty_file = temp_dir.join("empty.gguf");
std::fs::write(&empty_file, b"").expect("Write empty file");
let result = FormatType::from_magic(&empty_file);
let _ = std::fs::remove_file(&empty_file);
assert!(result.is_err(), "Empty file should fail magic detection");
}
#[test]
fn p095_truncated_magic_test() {
let temp_dir = std::env::temp_dir();
let short_file = temp_dir.join("short.gguf");
std::fs::write(&short_file, b"GGU").expect("Write short file");
let result = FormatType::from_magic(&short_file);
let _ = std::fs::remove_file(&short_file);
assert!(result.is_err(), "Truncated magic should fail");
}
#[test]
fn p096_symlink_path_extension() {
let path = Path::new("model.v1.backup.gguf");
let format = FormatType::from_extension(path);
assert!(format.is_ok());
assert_eq!(format.unwrap(), FormatType::Gguf);
}
#[test]
fn p097_hidden_file_extension() {
let path = Path::new(".hidden_model.safetensors");
let format = FormatType::from_extension(path);
assert!(format.is_ok());
assert_eq!(format.unwrap(), FormatType::SafeTensors);
}
#[test]
fn p098_mixed_case_extension() {
let path = Path::new("model.GgUf");
let format = FormatType::from_extension(path);
assert!(format.is_ok());
assert_eq!(format.unwrap(), FormatType::Gguf);
}
#[test]
fn p099_format_hash_trait() {
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(FormatType::Gguf);
set.insert(FormatType::Apr);
set.insert(FormatType::Gguf); assert_eq!(set.len(), 2);
}
#[test]
fn p100_format_eq_trait() {
assert_eq!(FormatType::Gguf, FormatType::Gguf);
assert_ne!(FormatType::Gguf, FormatType::Apr);
assert_ne!(FormatType::Apr, FormatType::SafeTensors);
}
#[test]
fn p101_conversion_path_clone() {
let path = ConversionPath::direct(FormatType::Gguf, FormatType::Apr);
let path2 = path.clone();
assert_eq!(path, path2);
}
#[test]
fn p102_conversion_path_debug() {
let path = ConversionPath::direct(FormatType::Gguf, FormatType::Apr);
let debug = format!("{:?}", path);
assert!(debug.contains("ConversionPath"));
assert!(debug.contains("Gguf"));
}
#[test]
fn p103_tensor_info_clone() {
let info = TensorInfo {
name: "test".to_string(),
dtype: "F32".to_string(),
shape: vec![10, 20],
size_bytes: 800,
stats: None,
};
let info2 = info.clone();
assert_eq!(info.name, info2.name);
assert_eq!(info.shape, info2.shape);
}
#[test]
fn p104_tensor_stats_copy() {
let stats = TensorStats {
min: 0.0,
max: 1.0,
mean: 0.5,
std: 0.25,
};
let stats2 = stats; assert_eq!(stats.mean, stats2.mean);
}
#[test]
fn p105_verification_report_clone() {
let report = VerificationReport::passing();
let report2 = report.clone();
assert_eq!(report.is_equivalent, report2.is_equivalent);
}
#[test]
fn p106_options_debug() {
let opts = ConversionOptions::default();
let debug = format!("{:?}", opts);
assert!(debug.contains("ConversionOptions"));
}