use crate::config::QuantizationConfig;
use crate::simd_native::jaccard_similarity_native;
#[test]
fn test_jaccard_simd_identical_sets() {
let a: Vec<f32> = vec![1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0];
let b: Vec<f32> = vec![1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0];
let result = jaccard_similarity_native(&a, &b);
assert!(
(result - 1.0).abs() < 1e-5,
"Identical sets should have Jaccard = 1.0"
);
}
#[test]
fn test_jaccard_simd_disjoint_sets() {
let a: Vec<f32> = vec![1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0];
let b: Vec<f32> = vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0];
let result = jaccard_similarity_native(&a, &b);
assert!(
(result - 0.0).abs() < 1e-5,
"Disjoint sets should have Jaccard = 0.0"
);
}
#[test]
fn test_jaccard_simd_half_overlap() {
let a: Vec<f32> = vec![1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
let b: Vec<f32> = vec![1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0];
let result = jaccard_similarity_native(&a, &b);
assert!((result - 1.0 / 3.0).abs() < 1e-5, "Expected Jaccard = 1/3");
}
#[test]
fn test_jaccard_simd_empty_sets() {
let a: Vec<f32> = vec![0.0; 16];
let b: Vec<f32> = vec![0.0; 16];
let result = jaccard_similarity_native(&a, &b);
assert!((result - 1.0).abs() < 1e-5, "Empty sets should return 1.0");
}
#[test]
fn test_jaccard_simd_large_vector() {
let a: Vec<f32> = (0..768)
.map(|i| if i % 2 == 0 { 1.0 } else { 0.0 })
.collect();
let b: Vec<f32> = (0..768)
.map(|i| if i % 3 == 0 { 1.0 } else { 0.0 })
.collect();
let result = jaccard_similarity_native(&a, &b);
assert!(
result > 0.0 && result < 1.0,
"Jaccard should be between 0 and 1"
);
}
#[test]
fn test_quantization_config_default() {
let config = QuantizationConfig::default();
assert!(config.auto_quantization);
assert_eq!(config.auto_quantization_threshold, 10_000);
}
#[test]
fn test_should_quantize_above_threshold() {
let config = QuantizationConfig::default();
assert!(config.should_quantize(15_000));
assert!(config.should_quantize(10_000));
}
#[test]
fn test_should_quantize_below_threshold() {
let config = QuantizationConfig::default();
assert!(!config.should_quantize(9_999));
assert!(!config.should_quantize(1_000));
}
#[test]
fn test_should_quantize_disabled() {
let config = QuantizationConfig {
auto_quantization: false,
auto_quantization_threshold: 10_000,
..Default::default()
};
assert!(!config.should_quantize(50_000));
}
#[test]
fn test_should_quantize_custom_threshold() {
let config = QuantizationConfig {
auto_quantization: true,
auto_quantization_threshold: 5_000,
..Default::default()
};
assert!(config.should_quantize(5_000));
assert!(!config.should_quantize(4_999));
}