#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SetDifference {
pub to_insert: Vec<(Vec<u8>, Vec<u8>)>,
pub to_remove: Vec<(Vec<u8>, Vec<u8>)>,
}
impl SetDifference {
pub fn new() -> Self {
Self {
to_insert: Vec::new(),
to_remove: Vec::new(),
}
}
pub fn with_changes(
to_insert: Vec<(Vec<u8>, Vec<u8>)>,
to_remove: Vec<(Vec<u8>, Vec<u8>)>,
) -> Self {
Self {
to_insert,
to_remove,
}
}
pub fn is_empty(&self) -> bool {
self.to_insert.is_empty() && self.to_remove.is_empty()
}
pub fn total_changes(&self) -> usize {
self.to_insert.len() + self.to_remove.len()
}
}
impl Default for SetDifference {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
let diff = SetDifference::new();
assert!(diff.is_empty());
assert_eq!(diff.total_changes(), 0);
}
#[test]
fn test_with_changes() {
let diff = SetDifference::with_changes(
vec![(b"key1".to_vec(), b"insert".to_vec())],
vec![(b"key2".to_vec(), b"remove".to_vec())],
);
assert!(!diff.is_empty());
assert_eq!(diff.total_changes(), 2);
}
#[test]
fn test_clone() {
let diff1 = SetDifference::with_changes(
vec![(b"a".to_vec(), b"va".to_vec())],
vec![(b"b".to_vec(), b"vb".to_vec())],
);
let diff2 = diff1.clone();
assert_eq!(diff1, diff2);
}
#[test]
fn test_debug() {
let diff = SetDifference::new();
let debug_str = format!("{:?}", diff);
assert!(debug_str.contains("SetDifference"));
}
}