logicaffeine_data/crdt/causal/
dot.rs1use super::super::replica::ReplicaId;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14pub struct Dot {
15 pub replica: ReplicaId,
17 pub counter: u64,
19}
20
21impl Dot {
22 pub fn new(replica: ReplicaId, counter: u64) -> Self {
24 Self { replica, counter }
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31 use std::collections::HashSet;
32
33 #[test]
34 fn test_dot_creation() {
35 let dot = Dot::new(42, 1);
36 assert_eq!(dot.replica, 42);
37 assert_eq!(dot.counter, 1);
38 }
39
40 #[test]
41 fn test_dot_equality() {
42 let a = Dot::new(1, 5);
43 let b = Dot::new(1, 5);
44 let c = Dot::new(1, 6);
45 let d = Dot::new(2, 5);
46
47 assert_eq!(a, b);
48 assert_ne!(a, c);
49 assert_ne!(a, d);
50 }
51
52 #[test]
53 fn test_dot_hash() {
54 let mut set = HashSet::new();
55 set.insert(Dot::new(1, 1));
56 set.insert(Dot::new(1, 2));
57 set.insert(Dot::new(1, 1)); assert_eq!(set.len(), 2);
60 }
61}