#![allow(unused_variables)]
use interstellar::p;
use interstellar::traversal::__;
use interstellar::value::{Value, VertexId};
use crate::common::graphs::create_small_graph;
#[test]
fn test_has_not_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().has_not("age").to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.graphdb));
}
#[test]
fn test_has_not_with_label_filter() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().has_label("person").has_not("version").to_list();
assert_eq!(results.len(), 3);
}
#[test]
fn test_is_eq_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().values("age").is_eq(Value::Int(30)).to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0], Value::Int(30));
}
#[test]
fn test_is_with_predicate_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().values("age").is_(p::gt(25)).to_list();
assert_eq!(results.len(), 2); assert!(results.contains(&Value::Int(30)));
assert!(results.contains(&Value::Int(35)));
}
#[test]
fn test_simple_path_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.with_path()
.out_labels(&["knows"])
.out_labels(&["knows"])
.simple_path()
.to_list();
assert!(!results.is_empty());
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.charlie));
}
#[test]
fn test_cyclic_path_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.with_path()
.out_labels(&["knows"])
.out_labels(&["knows"])
.out_labels(&["knows"])
.cyclic_path()
.to_list();
assert!(!results.is_empty());
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.alice));
}
#[test]
fn test_simple_path_vs_cyclic_path() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let all_paths = g
.v_ids([tg.alice])
.with_path()
.out_labels(&["knows"])
.out_labels(&["knows"])
.out_labels(&["knows"])
.to_list();
let simple_paths = g
.v_ids([tg.alice])
.with_path()
.out_labels(&["knows"])
.out_labels(&["knows"])
.out_labels(&["knows"])
.simple_path()
.to_list();
let cyclic_paths = g
.v_ids([tg.alice])
.with_path()
.out_labels(&["knows"])
.out_labels(&["knows"])
.out_labels(&["knows"])
.cyclic_path()
.to_list();
assert_eq!(simple_paths.len() + cyclic_paths.len(), all_paths.len());
}
#[test]
fn test_other_v_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.out_e_labels(&["knows"])
.other_v()
.to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
}
#[test]
fn test_other_v_both_directions() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.bob])
.both_e_labels(&["knows"])
.other_v()
.to_list();
assert_eq!(results.len(), 2);
let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.charlie));
}
#[test]
fn test_value_map_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v_ids([tg.alice]).value_map().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert!(matches!(map.get("name"), Some(Value::List(_))));
assert!(matches!(map.get("age"), Some(Value::List(_))));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_value_map_with_keys() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.value_map_keys(vec!["name".to_string()])
.to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert!(map.contains_key("name"));
assert!(!map.contains_key("age")); } else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_value_map_with_tokens() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v_ids([tg.alice]).value_map_with_tokens().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert!(matches!(map.get("id"), Some(Value::Int(_))));
assert!(matches!(map.get("label"), Some(Value::String(_))));
assert!(matches!(map.get("name"), Some(Value::List(_))));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_element_map_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v_ids([tg.alice]).element_map().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert!(matches!(map.get("id"), Some(Value::Int(_))));
assert_eq!(map.get("label"), Some(&Value::String("person".to_string())));
assert_eq!(map.get("name"), Some(&Value::String("Alice".to_string())));
assert_eq!(map.get("age"), Some(&Value::Int(30)));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_element_map_for_edge() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.e_ids([tg.alice_knows_bob]).element_map().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert!(matches!(map.get("id"), Some(Value::Int(_))));
assert_eq!(map.get("label"), Some(&Value::String("knows".to_string())));
assert!(matches!(map.get("IN"), Some(Value::Map(_))));
assert!(matches!(map.get("OUT"), Some(Value::Map(_))));
assert_eq!(map.get("since"), Some(&Value::Int(2020)));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_unfold_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v_ids([tg.alice]).value_map().unfold().to_list();
assert!(results.len() >= 2);
for result in results {
if let Value::Map(map) = result {
assert_eq!(map.len(), 1);
} else {
panic!("Expected unfolded values to be single-entry maps");
}
}
}
#[test]
fn test_unfold_list() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let list = Value::List(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
let results = g.inject([list]).unfold().to_list();
assert_eq!(results.len(), 3);
assert_eq!(results[0], Value::Int(1));
assert_eq!(results[1], Value::Int(2));
assert_eq!(results[2], Value::Int(3));
}
#[test]
fn test_mean_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().has_label("person").values("age").mean().to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0], Value::Float(30.0));
}
#[test]
fn test_mean_empty() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().values("nonexistent").mean().to_list();
assert_eq!(results.len(), 0);
}
#[test]
fn test_order_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.order()
.by_key_asc("age")
.build()
.to_list();
assert_eq!(results.len(), 3);
assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
assert_eq!(results[1].as_vertex_id(), Some(tg.alice));
assert_eq!(results[2].as_vertex_id(), Some(tg.charlie));
}
#[test]
fn test_order_descending() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.order()
.by_key_desc("age")
.build()
.to_list();
assert_eq!(results.len(), 3);
assert_eq!(results[0].as_vertex_id(), Some(tg.charlie));
assert_eq!(results[1].as_vertex_id(), Some(tg.alice));
assert_eq!(results[2].as_vertex_id(), Some(tg.bob));
}
#[test]
fn test_order_with_limit() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.order()
.by_key_desc("age")
.build()
.limit(1)
.to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.charlie)); }
#[test]
fn test_group_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().group().by_label().by_value().build().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert!(map.contains_key("person"));
assert!(map.contains_key("software"));
if let Some(Value::List(persons)) = map.get("person") {
assert_eq!(persons.len(), 3);
} else {
panic!("Expected person list");
}
if let Some(Value::List(software)) = map.get("software") {
assert_eq!(software.len(), 1);
} else {
panic!("Expected software list");
}
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_group_by_property() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.group()
.by_key("age")
.by_value_key("name")
.build()
.to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert_eq!(map.len(), 3);
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_group_count_integration() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().group_count().by_label().build().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert_eq!(map.get("person"), Some(&Value::Int(3)));
assert_eq!(map.get("software"), Some(&Value::Int(1)));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_group_count_edges() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.e().group_count().by_label().build().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert_eq!(map.get("knows"), Some(&Value::Int(3)));
assert_eq!(map.get("uses"), Some(&Value::Int(2)));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_value_map_unfold_combination() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v_ids([tg.alice]).value_map().unfold().to_list();
assert!(results.len() >= 2);
}
#[test]
fn test_order_limit_values_combination() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.order()
.by_key_desc("age")
.build()
.limit(2)
.values("name")
.to_list();
assert_eq!(results.len(), 2);
assert!(results.contains(&Value::String("Charlie".to_string())));
assert!(results.contains(&Value::String("Alice".to_string())));
}
#[test]
fn test_repeat_simple_path_combination() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.with_path()
.out_labels(&["knows"])
.out_labels(&["knows"])
.simple_path()
.path()
.to_list();
assert!(!results.is_empty());
}
#[test]
fn test_group_with_order() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().group().by_label().by_value().build().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert_eq!(map.len(), 2);
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_has_not_with_navigation() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().has_not("age").out().to_list();
assert_eq!(results.len(), 0);
}
#[test]
fn test_is_filter_with_aggregation() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().values("age").is_(p::gt(25)).mean().to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0], Value::Float(32.5));
}
#[test]
fn test_other_v_with_filter() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v_ids([tg.alice])
.out_e_labels(&["knows"])
.other_v()
.has_where("age", p::lt(30))
.to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0].as_vertex_id(), Some(tg.bob)); }
#[test]
fn test_element_map_with_select() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g.v().has_label("person").limit(1).element_map().to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert!(map.contains_key("id"));
assert!(map.contains_key("label"));
assert!(map.contains_key("name"));
assert!(map.contains_key("age"));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_group_count_with_has_filter() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.group_count()
.by_key("age")
.build()
.to_list();
assert_eq!(results.len(), 1);
if let Value::Map(map) = &results[0] {
assert_eq!(map.len(), 3); assert!(map.contains_key("25"));
assert!(map.contains_key("30"));
assert!(map.contains_key("35"));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_complex_traversal_with_all_new_steps() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.has_not("version")
.order()
.by_key_desc("age")
.build()
.limit(2)
.element_map()
.to_list();
assert_eq!(results.len(), 2);
if let Value::Map(map) = &results[0] {
assert_eq!(map.get("age"), Some(&Value::Int(35)));
} else {
panic!("Expected Value::Map");
}
if let Value::Map(map) = &results[1] {
assert_eq!(map.get("age"), Some(&Value::Int(30)));
} else {
panic!("Expected Value::Map");
}
}
#[test]
fn test_anonymous_traversal_with_new_steps() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.where_(__.values("age").is_(p::gte(30)))
.to_list();
assert_eq!(results.len(), 2); let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
assert!(ids.contains(&tg.alice));
assert!(ids.contains(&tg.charlie));
}
#[test]
fn test_mean_with_navigation() {
let tg = create_small_graph();
let snapshot = tg.graph.snapshot();
let g = snapshot.gremlin();
let results = g
.v()
.has_label("person")
.where_(__.out_labels(&["knows"]))
.values("age")
.mean()
.to_list();
assert_eq!(results.len(), 1);
assert_eq!(results[0], Value::Float(30.0));
}