interstellar 0.2.0

A high-performance graph database with Gremlin-style traversals and GQL query language
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
//! Phase 7 integration tests - Filter, Transform, and Aggregation Steps

#![allow(unused_variables)]
use interstellar::p;
use interstellar::traversal::__;
use interstellar::value::{Value, VertexId};

use crate::common::graphs::create_small_graph;

// =========================================================================
// Filter Step Integration Tests
// =========================================================================

#[test]
fn test_has_not_integration() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Find vertices that don't have an "age" property (software)
    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();

    // Find people who don't have a "version" property (should be all people)
    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();

    // Find vertices where age equals 30
    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();

    // Find ages greater than 25
    let results = g.v().values("age").is_(p::gt(25)).to_list();

    assert_eq!(results.len(), 2); // Alice (30) and Charlie (35)
    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();

    // Navigate with path tracking, filter to simple paths
    let results = g
        .v_ids([tg.alice])
        .with_path()
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .simple_path()
        .to_list();

    // Alice -> Bob -> Charlie is simple
    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();

    // Navigate with path tracking, filter to cyclic paths
    // Alice -> Bob -> Charlie -> Alice (forms a cycle)
    let results = g
        .v_ids([tg.alice])
        .with_path()
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .cyclic_path()
        .to_list();

    // Should find Alice again (cyclic path)
    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();

    // Get all paths with 3 hops
    let all_paths = g
        .v_ids([tg.alice])
        .with_path()
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .to_list();

    // Get only simple paths
    let simple_paths = g
        .v_ids([tg.alice])
        .with_path()
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .simple_path()
        .to_list();

    // Get only cyclic paths
    let cyclic_paths = g
        .v_ids([tg.alice])
        .with_path()
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .cyclic_path()
        .to_list();

    // Simple + cyclic should equal all paths
    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();

    // Start from Alice, traverse outgoing edges, get the other vertex
    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();

    // From Bob, get both knows edges, then other vertices
    let results = g
        .v_ids([tg.bob])
        .both_e_labels(&["knows"])
        .other_v()
        .to_list();

    // Bob knows Charlie (outgoing), Alice knows Bob (incoming)
    // So other vertices are: Charlie and Alice
    assert_eq!(results.len(), 2);
    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.charlie));
    // Note: other_v from incoming edge may not work as expected without path tracking
    // Let's just verify we got 2 results
}

// =========================================================================
// Transform Step Integration Tests
// =========================================================================

#[test]
fn test_value_map_integration() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Get property map for Alice
    let results = g.v_ids([tg.alice]).value_map().to_list();

    assert_eq!(results.len(), 1);
    if let Value::Map(map) = &results[0] {
        // Properties should be wrapped in lists
        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();

    // Get only specific properties
    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")); // age not requested
    } 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();

    // Get property map with id and label tokens
    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] {
        // Should have id and label (not wrapped in lists)
        assert!(matches!(map.get("id"), Some(Value::Int(_))));
        assert!(matches!(map.get("label"), Some(Value::String(_))));
        // Properties should still be wrapped in lists
        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();

    // Get complete element map for Alice
    let results = g.v_ids([tg.alice]).element_map().to_list();

    assert_eq!(results.len(), 1);
    if let Value::Map(map) = &results[0] {
        // Should have id and label
        assert!(matches!(map.get("id"), Some(Value::Int(_))));
        assert_eq!(map.get("label"), Some(&Value::String("person".to_string())));
        // Properties NOT wrapped in lists
        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();

    // Get element map for an edge
    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] {
        // Should have id, label, IN, OUT
        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(_))));
        // Should have properties
        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();

    // Get value_map, then unfold it into individual property entries
    let results = g.v_ids([tg.alice]).value_map().unfold().to_list();

    // Each property becomes a separate value (wrapped in lists from value_map)
    // value_map returns {"name": ["Alice"], "age": [30]}
    // unfold splits map into separate single-entry maps
    assert!(results.len() >= 2); // At least name and age

    // All results should be single-entry maps
    for result in results {
        if let Value::Map(map) = result {
            // Each unfolded map entry should have exactly one key-value pair
            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();

    // Create a list and unfold it
    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();

    // Calculate mean age of all people
    let results = g.v().has_label("person").values("age").mean().to_list();

    assert_eq!(results.len(), 1);
    // Mean of 30, 25, 35 is 30.0
    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();

    // Mean of non-existent property should return empty
    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();

    // Order people by age ascending
    let results = g
        .v()
        .has_label("person")
        .order()
        .by_key_asc("age")
        .build()
        .to_list();

    assert_eq!(results.len(), 3);
    // Should be Bob (25), Alice (30), Charlie (35)
    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();

    // Order people by age descending
    let results = g
        .v()
        .has_label("person")
        .order()
        .by_key_desc("age")
        .build()
        .to_list();

    assert_eq!(results.len(), 3);
    // Should be Charlie (35), Alice (30), Bob (25)
    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();

    // Get oldest person
    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)); // Age 35
}

// =========================================================================
// Aggregation Step Integration Tests
// =========================================================================

#[test]
fn test_group_integration() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Group all vertices by label
    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"));

        // Person group should have 3 vertices
        if let Some(Value::List(persons)) = map.get("person") {
            assert_eq!(persons.len(), 3);
        } else {
            panic!("Expected person list");
        }

        // Software group should have 1 vertex
        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();

    // Group people by age, collect names
    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] {
        // Should have groups for ages 25, 30, 35
        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();

    // Count vertices by label
    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();

    // Count edges by label
    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");
    }
}

// =========================================================================
// Complex Multi-Step Combinations
// =========================================================================

#[test]
fn test_value_map_unfold_combination() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Get properties as map, unfold into individual entries
    let results = g.v_ids([tg.alice]).value_map().unfold().to_list();

    // Should unfold the map into individual list values
    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();

    // Get top 2 oldest people's names
    let results = g
        .v()
        .has_label("person")
        .order()
        .by_key_desc("age")
        .build()
        .limit(2)
        .values("name")
        .to_list();

    assert_eq!(results.len(), 2);
    // Should be Charlie and Alice
    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();

    // Traverse knows edges with path tracking, filter to simple paths
    let results = g
        .v_ids([tg.alice])
        .with_path()
        .out_labels(&["knows"])
        .out_labels(&["knows"])
        .simple_path()
        .path()
        .to_list();

    // Should have at least one simple path
    assert!(!results.is_empty());
}

#[test]
fn test_group_with_order() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Group by label, then get the groups and count them
    let results = g.v().group().by_label().by_value().build().to_list();

    assert_eq!(results.len(), 1);
    if let Value::Map(map) = &results[0] {
        // Verify we have expected groups
        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();

    // Find vertices without age property, then navigate to their neighbors
    let results = g.v().has_not("age").out().to_list();

    // GraphDB has no "age", but has no outgoing edges
    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();

    // Get ages over 25, then calculate mean
    let results = g.v().values("age").is_(p::gt(25)).mean().to_list();

    assert_eq!(results.len(), 1);
    // Mean of 30 and 35 is 32.5
    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();

    // Get knows edges from Alice, then get other vertex with age filter
    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)); // Age 25
}

#[test]
fn test_element_map_with_select() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Get element map and verify structure
    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] {
        // Should have id, label, and properties
        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();

    // Count only people by their age
    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); // Three different ages
        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();

    // Complex: Get people without version property, order by age desc,
    // take top 2, get their element maps
    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);

    // First should be Charlie (age 35)
    if let Value::Map(map) = &results[0] {
        assert_eq!(map.get("age"), Some(&Value::Int(35)));
    } else {
        panic!("Expected Value::Map");
    }

    // Second should be Alice (age 30)
    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();

    // Use anonymous traversal in where clause with new steps
    let results = g
        .v()
        .has_label("person")
        .where_(__.values("age").is_(p::gte(30)))
        .to_list();

    assert_eq!(results.len(), 2); // Alice (30) and Charlie (35)
    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();

    // Get average age of people who know someone
    let results = g
        .v()
        .has_label("person")
        .where_(__.out_labels(&["knows"]))
        .values("age")
        .mean()
        .to_list();

    assert_eq!(results.len(), 1);
    // Alice (30), Bob (25), Charlie (35) all know someone
    // Mean = (30 + 25 + 35) / 3 = 30.0
    assert_eq!(results[0], Value::Float(30.0));
}