Scaffold
#[derive(Clone, Debug, PartialEq)]
struct GCounter {
counts: Vec<u64>,
node_id: usize,
}
impl GCounter {
fn new(node_id: usize, num_nodes: usize) -> Self { ... }
fn increment(&mut self) { ... }
fn value(&self) -> u64 { self.counts.iter().sum() }
fn merge(&mut self, other: &GCounter) { ... }
}
Write tests that simulate:
- Node 0 increments 3×, Node 1 increments 2×, Node 2 increments 5×
- Each node merges with the others
- All nodes converge to value 10