use ruvector_graph::{Edge, GraphDB, Label, Node, Properties, PropertyValue};
fn setup_test_graph() -> GraphDB {
let db = GraphDB::new();
let mut alice_props = Properties::new();
alice_props.insert(
"name".to_string(),
PropertyValue::String("Alice".to_string()),
);
alice_props.insert("age".to_string(), PropertyValue::Integer(30));
let mut bob_props = Properties::new();
bob_props.insert("name".to_string(), PropertyValue::String("Bob".to_string()));
bob_props.insert("age".to_string(), PropertyValue::Integer(35));
let mut charlie_props = Properties::new();
charlie_props.insert(
"name".to_string(),
PropertyValue::String("Charlie".to_string()),
);
charlie_props.insert("age".to_string(), PropertyValue::Integer(28));
db.create_node(Node::new(
"alice".to_string(),
vec![Label {
name: "Person".to_string(),
}],
alice_props,
))
.unwrap();
db.create_node(Node::new(
"bob".to_string(),
vec![Label {
name: "Person".to_string(),
}],
bob_props,
))
.unwrap();
db.create_node(Node::new(
"charlie".to_string(),
vec![Label {
name: "Person".to_string(),
}],
charlie_props,
))
.unwrap();
db.create_edge(Edge::new(
"e1".to_string(),
"alice".to_string(),
"bob".to_string(),
"KNOWS".to_string(),
Properties::new(),
))
.unwrap();
db.create_edge(Edge::new(
"e2".to_string(),
"bob".to_string(),
"charlie".to_string(),
"KNOWS".to_string(),
Properties::new(),
))
.unwrap();
db
}
#[test]
fn test_execute_simple_match_all_nodes() {
let db = setup_test_graph();
assert!(db.get_node("alice").is_some());
assert!(db.get_node("bob").is_some());
assert!(db.get_node("charlie").is_some());
}
#[test]
fn test_execute_match_with_label_filter() {
let db = setup_test_graph();
assert!(db.get_node("alice").is_some());
}
#[test]
fn test_execute_match_with_property_filter() {
let db = setup_test_graph();
let alice = db.get_node("alice").unwrap();
assert_eq!(
alice.properties.get("name"),
Some(&PropertyValue::String("Alice".to_string()))
);
}
#[test]
fn test_execute_match_with_where_clause() {
let db = setup_test_graph();
let bob = db.get_node("bob").unwrap();
if let Some(PropertyValue::Integer(age)) = bob.properties.get("age") {
assert!(*age > 30);
}
}
#[test]
fn test_execute_match_relationship() {
let db = setup_test_graph();
assert!(db.get_edge("e1").is_some());
assert!(db.get_edge("e2").is_some());
}
#[test]
fn test_execute_create_node() {
let db = GraphDB::new();
let mut props = Properties::new();
props.insert(
"name".to_string(),
PropertyValue::String("David".to_string()),
);
props.insert("age".to_string(), PropertyValue::Integer(40));
db.create_node(Node::new(
"david".to_string(),
vec![Label {
name: "Person".to_string(),
}],
props,
))
.unwrap();
let david = db.get_node("david").unwrap();
assert_eq!(
david.properties.get("name"),
Some(&PropertyValue::String("David".to_string()))
);
}
#[test]
fn test_execute_count_aggregation() {
let db = setup_test_graph();
assert!(db.get_node("alice").is_some());
assert!(db.get_node("bob").is_some());
assert!(db.get_node("charlie").is_some());
}
#[test]
fn test_execute_sum_aggregation() {
let db = setup_test_graph();
let ages: Vec<i64> = ["alice", "bob", "charlie"]
.iter()
.filter_map(|id| {
db.get_node(*id).and_then(|n| {
if let Some(PropertyValue::Integer(age)) = n.properties.get("age") {
Some(*age)
} else {
None
}
})
})
.collect();
assert_eq!(ages.iter().sum::<i64>(), 93);
}
#[test]
fn test_execute_avg_aggregation() {
let db = setup_test_graph();
let ages: Vec<i64> = ["alice", "bob", "charlie"]
.iter()
.filter_map(|id| {
db.get_node(*id).and_then(|n| {
if let Some(PropertyValue::Integer(age)) = n.properties.get("age") {
Some(*age)
} else {
None
}
})
})
.collect();
let avg = ages.iter().sum::<i64>() as f64 / ages.len() as f64;
assert!((avg - 31.0).abs() < 0.1);
}
#[test]
fn test_execute_order_by() {
let db = setup_test_graph();
let mut ages: Vec<i64> = ["alice", "bob", "charlie"]
.iter()
.filter_map(|id| {
db.get_node(*id).and_then(|n| {
if let Some(PropertyValue::Integer(age)) = n.properties.get("age") {
Some(*age)
} else {
None
}
})
})
.collect();
ages.sort();
assert_eq!(ages, vec![28, 30, 35]);
}
#[test]
fn test_execute_limit() {
let db = setup_test_graph();
assert!(db.get_node("alice").is_some());
}
#[test]
fn test_execute_path_query() {
let db = setup_test_graph();
let e1 = db.get_edge("e1").unwrap();
let e2 = db.get_edge("e2").unwrap();
assert_eq!(e1.from, "alice");
assert_eq!(e1.to, "bob");
assert_eq!(e2.from, "bob");
assert_eq!(e2.to, "charlie");
}
#[test]
fn test_execute_multi_hop_traversal() {
let db = setup_test_graph();
assert!(db.get_node("bob").is_some());
assert!(db.get_node("charlie").is_some());
}
#[test]
fn test_execute_pattern_matching() {
let db = setup_test_graph();
assert!(db.get_edge("e1").is_some());
assert!(db.get_edge("e2").is_some());
}
#[test]
fn test_execute_collect_aggregation() {
let db = setup_test_graph();
assert!(db.get_edge("e1").is_some());
}
#[test]
fn test_execute_optional_match() {
let db = setup_test_graph();
assert!(db.get_node("charlie").is_some());
}
#[test]
fn test_query_result_schema() {
}
#[test]
fn test_query_result_ordering() {
}
#[test]
fn test_query_result_pagination() {
}
#[test]
fn test_execute_invalid_property_access() {
}
#[test]
fn test_execute_type_mismatch() {
}