use data::Flow;
use doublets::{split, unit, Doublets, Error, Links};
use mem::Global;
#[test]
fn unit_count_links_empty_query() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
store.create_point()?;
store.create_point()?;
assert_eq!(store.count_by([]), 2);
Ok(())
}
#[test]
fn unit_count_links_single_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
store.create_point()?;
store.create_point()?;
assert_eq!(store.count_by([any]), 2);
Ok(())
}
#[test]
fn unit_count_links_single_index() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
assert_eq!(store.count_by([a]), 1);
assert_eq!(store.count_by([100]), 0);
Ok(())
}
#[test]
fn unit_count_links_two_element_any_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
store.create_point()?;
store.create_point()?;
assert_eq!(store.count_by([any, any]), 2);
Ok(())
}
#[test]
fn unit_count_links_two_element_any_value() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
store.create_link(a, b)?;
let count = store.count_by([any, a]);
assert!(count >= 1);
Ok(())
}
#[test]
fn unit_count_links_two_element_index_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
assert_eq!(store.count_by([a, any]), 1);
assert_eq!(store.count_by([100, any]), 0);
Ok(())
}
#[test]
fn unit_count_links_two_element_index_value_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
assert_eq!(store.count_by([c, a]), 1);
assert_eq!(store.count_by([c, b]), 1);
assert_eq!(store.count_by([c, 100]), 0);
Ok(())
}
#[test]
fn unit_count_links_three_element_any_any_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
store.create_point()?;
store.create_point()?;
assert_eq!(store.count_by([any, any, any]), 2);
Ok(())
}
#[test]
fn unit_count_links_three_element_any_source_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
store.create_link(a, b)?;
let count = store.count_by([any, a, any]);
assert!(count >= 1);
Ok(())
}
#[test]
fn unit_count_links_three_element_any_any_target() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
store.create_link(a, b)?;
let count = store.count_by([any, any, b]);
assert!(count >= 1);
Ok(())
}
#[test]
fn unit_count_links_three_element_any_source_target() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
store.create_link(a, b)?;
assert_eq!(store.count_by([any, a, b]), 1);
assert_eq!(store.count_by([any, b, a]), 0);
Ok(())
}
#[test]
fn unit_count_links_three_element_index_any_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
assert_eq!(store.count_by([a, any, any]), 1);
assert_eq!(store.count_by([100, any, any]), 0);
Ok(())
}
#[test]
fn unit_count_links_three_element_index_source_target() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
assert_eq!(store.count_by([c, a, b]), 1);
assert_eq!(store.count_by([c, b, a]), 0);
Ok(())
}
#[test]
fn unit_count_links_three_element_index_any_target() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
assert_eq!(store.count_by([c, any, b]), 1);
assert_eq!(store.count_by([c, any, a]), 0);
let _ = c;
Ok(())
}
#[test]
fn unit_count_links_three_element_index_source_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
assert_eq!(store.count_by([c, a, any]), 1);
assert_eq!(store.count_by([c, b, any]), 0);
let _ = c;
Ok(())
}
#[test]
fn unit_each_empty_query() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let mut collected = Vec::new();
store.each_by([], |link| {
collected.push(link.index);
Flow::Continue
});
assert!(collected.contains(&a));
assert!(collected.contains(&b));
Ok(())
}
#[test]
fn unit_each_single_index() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
store.create_point()?;
let mut collected = Vec::new();
store.each_by([a], |link| {
collected.push(link.index);
Flow::Continue
});
assert_eq!(collected.len(), 1);
assert_eq!(collected[0], a);
Ok(())
}
#[test]
fn unit_each_single_nonexistent() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
store.create_point()?;
let mut count = 0;
store.each_by([100], |_link| {
count += 1;
Flow::Continue
});
assert_eq!(count, 0);
Ok(())
}
#[test]
fn unit_each_two_element_index_any() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let mut collected = Vec::new();
store.each_by([a, any], |link| {
collected.push(link.index);
Flow::Continue
});
assert_eq!(collected.len(), 1);
assert_eq!(collected[0], a);
Ok(())
}
#[test]
fn unit_each_two_element_index_value_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut collected = Vec::new();
store.each_by([c, a], |link| {
collected.push(link.index);
Flow::Continue
});
assert!(collected.contains(&c));
Ok(())
}
#[test]
fn unit_each_two_element_index_value_no_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut count = 0;
store.each_by([c, 100], |_link| {
count += 1;
Flow::Continue
});
assert_eq!(count, 0);
let _ = c;
Ok(())
}
#[test]
fn unit_each_two_element_any_value() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
store.create_link(a, b)?;
let mut collected = Vec::new();
store.each_by([any, a], |link| {
collected.push(link.index);
Flow::Continue
});
assert!(!collected.is_empty());
Ok(())
}
#[test]
fn unit_each_three_element_index_source_target_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut collected = Vec::new();
store.each_by([c, a, b], |link| {
collected.push(link.index);
Flow::Continue
});
assert_eq!(collected.len(), 1);
assert_eq!(collected[0], c);
Ok(())
}
#[test]
fn unit_each_three_element_index_source_target_no_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut count = 0;
store.each_by([c, b, a], |_link| {
count += 1;
Flow::Continue
});
assert_eq!(count, 0);
let _ = c;
Ok(())
}
#[test]
fn unit_each_three_element_index_any_target_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut collected = Vec::new();
store.each_by([c, any, b], |link| {
collected.push(link.index);
Flow::Continue
});
assert_eq!(collected.len(), 1);
assert_eq!(collected[0], c);
Ok(())
}
#[test]
fn unit_each_three_element_index_any_target_no_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut count = 0;
store.each_by([c, any, a], |_link| {
count += 1;
Flow::Continue
});
assert_eq!(count, 0);
let _ = c;
Ok(())
}
#[test]
fn unit_each_three_element_index_source_any_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut collected = Vec::new();
store.each_by([c, a, any], |link| {
collected.push(link.index);
Flow::Continue
});
assert_eq!(collected.len(), 1);
assert_eq!(collected[0], c);
Ok(())
}
#[test]
fn unit_each_three_element_index_source_any_no_match() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_link(a, b)?;
let mut count = 0;
store.each_by([c, b, any], |_link| {
count += 1;
Flow::Continue
});
assert_eq!(count, 0);
let _ = c;
Ok(())
}
#[test]
fn unit_each_three_element_nonexistent_index() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
store.create_point()?;
let mut count = 0;
store.each_by([100, any, any], |_link| {
count += 1;
Flow::Continue
});
assert_eq!(count, 0);
Ok(())
}
#[test]
fn split_count_links_empty_query() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
store.create_point()?;
store.create_point()?;
assert_eq!(store.count_by([]), 2);
Ok(())
}
#[test]
fn split_count_links_single_any() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let any = Links::constants(&store).any;
store.create_point()?;
store.create_point()?;
assert_eq!(store.count_by([any]), 2);
Ok(())
}
#[test]
fn split_count_links_three_element_any_source_target() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
store.create_link(a, b)?;
assert_eq!(store.count_by([any, a, b]), 1);
assert_eq!(store.count_by([any, b, a]), 0);
Ok(())
}
#[test]
fn split_each_empty_query() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let mut collected = Vec::new();
store.each_by([], |link| {
collected.push(link.index);
Flow::Continue
});
assert!(collected.contains(&a));
assert!(collected.contains(&b));
Ok(())
}
#[test]
fn split_each_single_index() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let a = store.create_point()?;
store.create_point()?;
let mut collected = Vec::new();
store.each_by([a], |link| {
collected.push(link.index);
Flow::Continue
});
assert_eq!(collected.len(), 1);
assert_eq!(collected[0], a);
Ok(())
}
#[test]
fn unit_tree_operations_multiple_links() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_point()?;
let l1 = store.create_link(a, b)?;
let l2 = store.create_link(a, c)?;
assert!(store.count_usages(a)? >= 2);
assert_eq!(store.search(a, b), Some(l1));
assert_eq!(store.search(a, c), Some(l2));
Ok(())
}
#[test]
fn split_tree_operations_multiple_links() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_point()?;
let l1 = store.create_link(a, b)?;
let l2 = store.create_link(a, c)?;
assert!(store.count_usages(a)? >= 2);
assert_eq!(store.search(a, b), Some(l1));
assert_eq!(store.search(a, c), Some(l2));
Ok(())
}
#[test]
fn unit_delete_and_recreate() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
store.delete(a)?;
assert!(!store.exist(a));
let b = store.create_point()?;
assert!(store.exist(b));
Ok(())
}
#[test]
fn split_delete_and_recreate() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let a = store.create_point()?;
store.delete(a)?;
assert!(!store.exist(a));
let b = store.create_point()?;
assert!(store.exist(b));
Ok(())
}
#[test]
fn unit_delete_nonexistent() {
let mut store = unit::Store::<usize, _>::new(Global::new()).unwrap();
let result = store.delete(100);
assert!(result.is_err());
}
#[test]
fn split_delete_nonexistent() {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new()).unwrap();
let result = store.delete(100);
assert!(result.is_err());
}
#[test]
fn unit_update_nonexistent() {
let mut store = unit::Store::<usize, _>::new(Global::new()).unwrap();
let result = store.update(100, 1, 1);
assert!(result.is_err());
}
#[test]
fn split_update_nonexistent() {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new()).unwrap();
let result = store.update(100, 1, 1);
assert!(result.is_err());
}
#[test]
fn unit_many_creates() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
for _ in 0..1000 {
store.create_point()?;
}
assert_eq!(store.count(), 1000);
Ok(())
}
#[test]
fn split_many_creates() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
for _ in 0..1000 {
store.create_point()?;
}
assert_eq!(store.count(), 1000);
Ok(())
}
#[test]
fn unit_complex_structure() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_point()?;
store.create_link(a, b)?;
store.create_link(b, c)?;
store.create_link(c, a)?;
assert!(store.count_by([any, a, any]) >= 1);
assert!(store.count_by([any, b, any]) >= 1);
assert!(store.count_by([any, c, any]) >= 1);
assert!(store.count_by([any, any, a]) >= 1);
assert!(store.count_by([any, any, b]) >= 1);
assert!(store.count_by([any, any, c]) >= 1);
Ok(())
}
#[test]
fn split_complex_structure() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let any = Links::constants(&store).any;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_point()?;
store.create_link(a, b)?;
store.create_link(b, c)?;
store.create_link(c, a)?;
assert!(store.count_by([any, a, any]) >= 1);
assert!(store.count_by([any, b, any]) >= 1);
assert!(store.count_by([any, c, any]) >= 1);
assert!(store.count_by([any, any, a]) >= 1);
assert!(store.count_by([any, any, b]) >= 1);
assert!(store.count_by([any, any, c]) >= 1);
Ok(())
}
#[test]
fn unit_update_source_and_target() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_point()?;
let d = store.create_link(a, b)?;
store.update(d, c, c)?;
let link = store.get_link(d).unwrap();
assert_eq!(link.source, c);
assert_eq!(link.target, c);
Ok(())
}
#[test]
fn split_update_source_and_target() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let c = store.create_point()?;
let d = store.create_link(a, b)?;
store.update(d, c, c)?;
let link = store.get_link(d).unwrap();
assert_eq!(link.source, c);
assert_eq!(link.target, c);
Ok(())
}
#[test]
fn unit_each_usages_iteration() -> Result<(), Error<usize>> {
let mut store = unit::Store::<usize, _>::new(Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let l1 = store.create_link(a, b)?;
let l2 = store.create_link(a, a)?;
let usages = store.usages(a)?;
assert!(usages.contains(&l1) || usages.contains(&l2));
Ok(())
}
#[test]
fn split_each_usages_iteration() -> Result<(), Error<usize>> {
let mut store = split::Store::<usize, _, _>::new(Global::new(), Global::new())?;
let a = store.create_point()?;
let b = store.create_point()?;
let l1 = store.create_link(a, b)?;
let l2 = store.create_link(a, a)?;
let usages = store.usages(a)?;
assert!(usages.contains(&l1) || usages.contains(&l2));
Ok(())
}