use super::*;
use std::io::Write;
use tempfile::NamedTempFile;
#[test]
fn test_format_size_zero() {
let result = format_size(0);
assert_eq!(result, "0 B");
}
#[test]
fn test_format_size_bytes() {
assert_eq!(format_size(1), "1 B");
assert_eq!(format_size(512), "512 B");
assert_eq!(format_size(1023), "1023 B");
}
#[test]
fn test_format_size_kilobytes() {
assert_eq!(format_size(1024), "1.0 KB");
assert_eq!(format_size(1536), "1.5 KB");
assert_eq!(format_size(1024 * 100), "100.0 KB");
}
#[test]
fn test_format_size_megabytes() {
assert_eq!(format_size(1024 * 1024), "1.0 MB");
assert_eq!(format_size(1024 * 1024 * 512), "512.0 MB");
}
#[test]
fn test_format_size_gigabytes() {
assert_eq!(format_size(1024 * 1024 * 1024), "1.0 GB");
assert_eq!(format_size(1024 * 1024 * 1024 * 7), "7.0 GB");
}
#[test]
fn test_format_size_boundary_kb() {
assert_eq!(format_size(1023), "1023 B");
assert_eq!(format_size(1024), "1.0 KB");
}
#[test]
fn test_format_size_boundary_mb() {
let result = format_size(1024 * 1024 - 1);
assert!(result.contains("KB"));
assert_eq!(format_size(1024 * 1024), "1.0 MB");
}
#[test]
fn test_format_size_boundary_gb() {
let result = format_size(1024 * 1024 * 1024 - 1);
assert!(result.contains("MB"));
assert_eq!(format_size(1024 * 1024 * 1024), "1.0 GB");
}
#[test]
fn test_benchmark_suites_exist() {
assert!(BENCHMARK_SUITES.len() >= 5);
}
#[test]
fn test_benchmark_suites_have_descriptions() {
for (name, desc) in BENCHMARK_SUITES {
assert!(!name.is_empty(), "Suite name should not be empty");
assert!(!desc.is_empty(), "Suite description should not be empty");
}
}
#[test]
fn test_benchmark_suite_names_valid() {
let expected = ["tensor_ops", "inference", "cache", "tokenizer", "quantize"];
for name in expected {
assert!(
BENCHMARK_SUITES.iter().any(|(n, _)| *n == name),
"Expected suite '{}' not found",
name
);
}
}
#[test]
fn test_display_model_info_gguf_valid_header() {
use crate::gguf::{GGUF_MAGIC, GGUF_VERSION_V3};
let mut data = Vec::new();
data.extend_from_slice(&GGUF_MAGIC.to_le_bytes());
data.extend_from_slice(&GGUF_VERSION_V3.to_le_bytes());
data.extend_from_slice(&1u64.to_le_bytes()); data.extend_from_slice(&0u64.to_le_bytes());
let result = display_model_info("test.gguf", &data);
let _ = result;
}
#[test]
fn test_display_model_info_gguf_poisoned_truncated() {
use crate::gguf::GGUF_MAGIC;
let mut data = Vec::new();
data.extend_from_slice(&GGUF_MAGIC.to_le_bytes());
data.extend_from_slice(&3u32.to_le_bytes());
let result = display_model_info("test.gguf", &data);
assert!(result.is_err());
}
#[test]
fn test_display_model_info_safetensors_poisoned() {
let mut data = Vec::new();
let header = b"{ not valid json }";
data.extend_from_slice(&(header.len() as u64).to_le_bytes());
data.extend_from_slice(header);
let result = display_model_info("test.safetensors", &data);
assert!(result.is_err());
}
#[test]
fn test_display_model_info_apr_poisoned() {
use crate::format::APR_MAGIC;
let mut data = Vec::new();
data.extend_from_slice(APR_MAGIC);
data.extend_from_slice(&[0xFF; 100]);
let result = display_model_info("test.apr", &data);
let _ = result;
}
#[test]
fn test_display_model_info_unknown_format() {
let data = b"UNKNOWN_FORMAT_HEADER_DATA_HERE";
let result = display_model_info("test.bin", data);
assert!(result.is_ok());
}
#[test]
fn test_display_model_info_empty_file() {
let data: &[u8] = &[];
let result = display_model_info("empty.gguf", data);
assert!(result.is_err() || result.is_ok()); }
#[test]
fn test_run_visualization_zero_samples() {
run_visualization(false, 0);
}
#[test]
fn test_run_visualization_one_sample() {
run_visualization(false, 1);
}
#[test]
fn test_run_visualization_large_samples() {
run_visualization(false, 1000);
}
#[test]
fn test_run_visualization_with_color() {
run_visualization(true, 100);
}
#[test]
fn test_run_visualization_without_color() {
run_visualization(false, 100);
}
#[test]
fn test_is_local_file_path_absolute() {
assert!(is_local_file_path("/home/user/model.gguf"));
assert!(is_local_file_path("/tmp/test.apr"));
}
#[test]
fn test_is_local_file_path_relative() {
assert!(is_local_file_path("./model.gguf"));
assert!(is_local_file_path("models/test.apr"));
}
#[test]
fn test_is_local_file_path_registry_uri() {
assert!(!is_local_file_path("pacha://model/name"));
assert!(!is_local_file_path("hf://org/model"));
}
#[test]
fn test_is_local_file_path_empty() {
let result = is_local_file_path("");
let _ = result;
}
#[test]
fn test_is_local_file_path_just_filename() {
assert!(is_local_file_path("model.gguf"));
}
#[test]
fn test_run_bench_compare_nonexistent_files() {
let result = run_bench_compare("/nonexistent/file1.json", "/nonexistent/file2.json", 0.1);
assert!(result.is_err());
}
#[test]
fn test_run_bench_compare_empty_file() {
let mut temp = NamedTempFile::new().unwrap();
temp.write_all(b"").unwrap();
temp.flush().unwrap();
let result = run_bench_compare(
temp.path().to_str().unwrap(),
temp.path().to_str().unwrap(),
0.1,
);
assert!(result.is_err());
}
#[test]
fn test_run_bench_compare_invalid_json() {
let mut temp = NamedTempFile::new().unwrap();
temp.write_all(b"{ not valid json }").unwrap();
temp.flush().unwrap();
let result = run_bench_compare(
temp.path().to_str().unwrap(),
temp.path().to_str().unwrap(),
0.1,
);
assert!(result.is_err());
}
#[test]
fn test_run_bench_regression_nonexistent() {
let result = run_bench_regression(
"/nonexistent/baseline.json",
"/nonexistent/current.json",
false, );
assert!(result.is_err());
}
#[test]
fn test_run_convoy_test_no_model() {
let result = run_convoy_test(None, None, None);
let _ = result;
}
#[test]
fn test_run_saturation_test_no_model() {
let result = run_saturation_test(None, None, None);
let _ = result;
}
#[test]
fn test_run_benchmarks_list_mode() {
let result = run_benchmarks(None, true, None, None, None, None);
assert!(result.is_ok());
}
#[test]
#[ignore = "calls std::process::exit(1) which kills test process"]
fn test_run_benchmarks_invalid_suite() {
let result = run_benchmarks(
Some("nonexistent_suite".to_string()),
false,
None,
None,
None,
None,
);
let _ = result;
}
#[test]
#[ignore = "requires cargo bench infrastructure"]
fn test_run_benchmarks_valid_suite_no_runtime() {
let result = run_benchmarks(
Some("tensor_ops".to_string()),
false,
None,
None,
None,
None,
);
let _ = result;
}
#[test]
fn test_display_model_info_by_extension() {
use crate::gguf::GGUF_MAGIC;
let mut data = Vec::new();
data.extend_from_slice(&GGUF_MAGIC.to_le_bytes());
let result = display_model_info("model.gguf", &data);
let _ = result;
}
#[test]
fn test_display_model_info_safetensors_extension() {
let mut data = Vec::new();
let header = b"{}"; data.extend_from_slice(&(header.len() as u64).to_le_bytes());
data.extend_from_slice(header);
let result = display_model_info("model.safetensors", &data);
let _ = result;
}
#[test]
fn test_validate_suite_name_valid() {
for (name, _) in BENCHMARK_SUITES {
let is_valid = BENCHMARK_SUITES.iter().any(|(n, _)| *n == *name);
assert!(is_valid);
}
}
#[test]
fn test_validate_suite_name_invalid() {
let invalid_names = ["invalid", "nonexistent", "test123", ""];
for name in invalid_names {
let is_valid = BENCHMARK_SUITES.iter().any(|(n, _)| *n == name);
if !name.is_empty() {
assert!(!is_valid, "Name '{}' should not be valid", name);
}
}
}
#[test]
fn test_model_not_found_error_path() {
use crate::error::RealizarError;
let err = RealizarError::ModelNotFound("nonexistent.gguf".to_string());
let msg = err.to_string();
assert!(msg.contains("nonexistent.gguf") || msg.contains("not found"));
}
#[test]
fn test_unsupported_operation_error_path() {
use crate::error::RealizarError;
let err = RealizarError::UnsupportedOperation {
operation: "test_op".to_string(),
reason: "test reason".to_string(),
};
let msg = err.to_string();
assert!(msg.contains("test_op") || msg.contains("test reason") || msg.contains("Unsupported"));
}