ruvector_robotics/bridge/
config.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
7pub enum DistanceMetric {
8 #[default]
9 Euclidean,
10 Cosine,
11 Manhattan,
12}
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16pub struct BridgeConfig {
17 pub dimensions: usize,
19 pub distance_metric: DistanceMetric,
21 pub max_points: usize,
23 pub search_k: usize,
25}
26
27impl Default for BridgeConfig {
28 fn default() -> Self {
29 Self {
30 dimensions: 3,
31 distance_metric: DistanceMetric::Euclidean,
32 max_points: 1_000_000,
33 search_k: 10,
34 }
35 }
36}
37
38impl BridgeConfig {
39 pub fn new(
41 dimensions: usize,
42 distance_metric: DistanceMetric,
43 max_points: usize,
44 search_k: usize,
45 ) -> Self {
46 Self {
47 dimensions,
48 distance_metric,
49 max_points,
50 search_k,
51 }
52 }
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_default_distance_metric() {
61 assert_eq!(DistanceMetric::default(), DistanceMetric::Euclidean);
62 }
63
64 #[test]
65 fn test_default_bridge_config() {
66 let cfg = BridgeConfig::default();
67 assert_eq!(cfg.dimensions, 3);
68 assert_eq!(cfg.distance_metric, DistanceMetric::Euclidean);
69 assert_eq!(cfg.max_points, 1_000_000);
70 assert_eq!(cfg.search_k, 10);
71 }
72
73 #[test]
74 fn test_config_serde_roundtrip_json() {
75 let cfg = BridgeConfig::new(128, DistanceMetric::Cosine, 500_000, 20);
76 let json = serde_json::to_string(&cfg).unwrap();
77 let restored: BridgeConfig = serde_json::from_str(&json).unwrap();
78 assert_eq!(cfg, restored);
79 }
80
81 #[test]
82 fn test_config_serde_roundtrip_default() {
83 let cfg = BridgeConfig::default();
84 let json = serde_json::to_string_pretty(&cfg).unwrap();
85 let restored: BridgeConfig = serde_json::from_str(&json).unwrap();
86 assert_eq!(cfg, restored);
87 }
88
89 #[test]
90 fn test_distance_metric_serde_variants() {
91 for metric in [
92 DistanceMetric::Euclidean,
93 DistanceMetric::Cosine,
94 DistanceMetric::Manhattan,
95 ] {
96 let json = serde_json::to_string(&metric).unwrap();
97 let restored: DistanceMetric = serde_json::from_str(&json).unwrap();
98 assert_eq!(metric, restored);
99 }
100 }
101
102 #[test]
103 fn test_config_new() {
104 let cfg = BridgeConfig::new(64, DistanceMetric::Manhattan, 250_000, 5);
105 assert_eq!(cfg.dimensions, 64);
106 assert_eq!(cfg.distance_metric, DistanceMetric::Manhattan);
107 assert_eq!(cfg.max_points, 250_000);
108 assert_eq!(cfg.search_k, 5);
109 }
110
111 #[test]
112 fn test_config_clone_eq() {
113 let a = BridgeConfig::default();
114 let b = a.clone();
115 assert_eq!(a, b);
116 }
117
118 #[test]
119 fn test_config_debug_format() {
120 let cfg = BridgeConfig::default();
121 let dbg = format!("{:?}", cfg);
122 assert!(dbg.contains("BridgeConfig"));
123 assert!(dbg.contains("Euclidean"));
124 }
125}