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
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
//! Edge case tests for traversal engine.
//!
//! Tests boundary conditions and edge cases including:
//! - Empty result handling
//! - Single element operations
//! - Missing property handling
//! - Type coercion scenarios

#![allow(unused_variables)]

use std::collections::HashMap;

use interstellar::p;
use interstellar::storage::Graph;
use interstellar::traversal::__;
use interstellar::value::Value;

use crate::common::graphs::{create_empty_graph, create_property_test_graph, create_small_graph};

// =============================================================================
// Empty Traversal Handling (10+ tests)
// =============================================================================

#[test]
fn empty_graph_v_returns_empty_list() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let results = g.v().to_list();
    assert!(results.is_empty());
}

#[test]
fn empty_graph_e_returns_empty_list() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let results = g.e().to_list();
    assert!(results.is_empty());
}

#[test]
fn empty_graph_count_returns_zero() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    assert_eq!(g.v().count(), 0);
    assert_eq!(g.e().count(), 0);
}

#[test]
fn empty_graph_out_returns_empty() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let results = g.v().out().to_list();
    assert!(results.is_empty());
}

#[test]
fn empty_graph_values_returns_empty() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let results = g.v().values("name").to_list();
    assert!(results.is_empty());
}

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

    // Filter that matches nothing
    let results = g.v().has_value("name", "NonexistentPerson").to_list();
    assert!(results.is_empty());
}

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

    // Chained steps after empty should remain empty
    let results = g
        .v()
        .has_value("name", "NonexistentPerson")
        .out()
        .values("name")
        .to_list();
    assert!(results.is_empty());
}

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

    // where_() with non-matching sub-traversal should filter all
    // No "manages" edges exist in small_graph
    let results = g
        .v()
        .has_label("person")
        .where_(__.out_labels(&["manages"]))
        .to_list();
    assert!(results.is_empty());
}

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

    // Request vertex IDs that don't exist
    let results = g.v_ids([interstellar::value::VertexId(99999)]).to_list();
    assert!(results.is_empty());
}

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

    // GraphDB has no outgoing edges
    let results = g.v_ids([tg.graphdb]).out().to_list();
    assert!(results.is_empty());

    // Chained navigation from empty should stay empty
    let results = g.v_ids([tg.graphdb]).out().out().out().to_list();
    assert!(results.is_empty());
}

#[test]
fn empty_dedup_on_empty_traversal() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let results = g.v().dedup().to_list();
    assert!(results.is_empty());
}

#[test]
fn empty_limit_on_empty_traversal() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let results = g.v().limit(10).to_list();
    assert!(results.is_empty());
}

#[test]
fn empty_traversal_sum_returns_zero() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let result = g.v().values("age").sum();
    assert_eq!(result, Value::Int(0));
}

#[test]
fn empty_traversal_min_returns_none() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let result = g.v().values("age").min();
    assert!(result.is_none());
}

#[test]
fn empty_traversal_max_returns_none() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    let result = g.v().values("age").max();
    assert!(result.is_none());
}

#[test]
fn empty_traversal_next_returns_none() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    assert!(g.v().next().is_none());
}

#[test]
fn empty_traversal_has_next_returns_false() {
    let graph = create_empty_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    assert!(!g.v().has_next());
}

// =============================================================================
// Single Element Operations (5+ tests)
// =============================================================================

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

    // one() on single result should succeed
    let result = g.v_ids([tg.alice]).one();
    assert!(result.is_ok());
    assert_eq!(result.unwrap().as_vertex_id(), Some(tg.alice));
}

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

    // one() on single result after filter
    let result = g.v().has_value("name", "Alice").one();
    assert!(result.is_ok());
}

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

    // one() should fail on multiple results
    let result = g.v().has_label("person").one();
    assert!(result.is_err());
}

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

    // one() should fail on empty results
    let result = g.v().has_value("name", "Nobody").one();
    assert!(result.is_err());
}

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

    // min/max on single value should be equal
    let min = g.v_ids([tg.alice]).values("age").min();
    let max = g.v_ids([tg.alice]).values("age").max();

    assert!(min.is_some());
    assert!(max.is_some());
    assert_eq!(min, max); // Single element: min == max
}

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

    assert_eq!(g.v_ids([tg.alice]).count(), 1);
}

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

    let results = g.v_ids([tg.alice]).dedup().to_list();
    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

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

    // limit(10) on single element should return 1
    let results = g.v_ids([tg.alice]).limit(10).to_list();
    assert_eq!(results.len(), 1);
}

// =============================================================================
// Missing Property Handling (5+ tests)
// =============================================================================

#[test]
fn values_skips_vertices_without_property() {
    let graph = Graph::new();
    let v1 = graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("A".to_string()));
        props
    });
    let v2 = graph.add_vertex("test", HashMap::new()); // No "name" property

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // values() should skip vertices without the property
    let names = g.v().values("name").to_list();
    assert_eq!(names.len(), 1);
    assert_eq!(names[0], Value::String("A".to_string()));
}

#[test]
fn has_property_filters_out_missing() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("A".to_string()));
        props
    });
    graph.add_vertex("test", HashMap::new()); // No "name" property
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("C".to_string()));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // has() filters out vertices without property
    let with_name = g.v().has("name").to_list();
    assert_eq!(with_name.len(), 2);
}

#[test]
fn has_value_filters_out_missing_property() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Alice".to_string()));
        props
    });
    graph.add_vertex("test", HashMap::new()); // No properties

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // has_value should not match vertex without the property
    let results = g.v().has_value("name", "Alice").to_list();
    assert_eq!(results.len(), 1);
}

#[test]
fn has_where_on_missing_property() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("age".to_string(), Value::Int(30));
        props
    });
    graph.add_vertex("test", HashMap::new()); // No "age" property

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // has_where on missing property should filter that vertex
    let results = g.v().has_where("age", p::gt(20)).to_list();
    assert_eq!(results.len(), 1);
}

#[test]
fn multiple_properties_some_missing() {
    let graph = Graph::new();
    graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Alice".to_string()));
        props.insert("age".to_string(), Value::Int(30));
        props
    });
    graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Bob".to_string()));
        // No age
        props
    });
    graph.add_vertex("person", {
        let mut props = HashMap::new();
        // No name
        props.insert("age".to_string(), Value::Int(25));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Only vertices with both properties match
    let with_both = g.v().has("name").has("age").to_list();
    assert_eq!(with_both.len(), 1);

    // Count of name values
    let names = g.v().values("name").to_list();
    assert_eq!(names.len(), 2);

    // Count of age values
    let ages = g.v().values("age").to_list();
    assert_eq!(ages.len(), 2);
}

#[test]
fn aggregation_on_partially_missing_properties() {
    let graph = Graph::new();
    graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("age".to_string(), Value::Int(30));
        props
    });
    graph.add_vertex("person", HashMap::new()); // No age
    graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("age".to_string(), Value::Int(20));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // sum/min/max should only consider vertices with the property
    let sum = g.v().values("age").sum();
    assert_eq!(sum, Value::Int(50)); // 30 + 20

    let min = g.v().values("age").min();
    assert_eq!(min, Some(Value::Int(20)));

    let max = g.v().values("age").max();
    assert_eq!(max, Some(Value::Int(30)));
}

#[test]
fn order_by_missing_property() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("B".to_string()));
        props.insert("priority".to_string(), Value::Int(2));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("A".to_string()));
        // No priority
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("C".to_string()));
        props.insert("priority".to_string(), Value::Int(1));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Ordering by property - behavior for missing property may vary
    // Just verify it doesn't panic
    let results = g.v().values("priority").order().by_asc().build().to_list();
    // Should have 2 values (vertices with priority)
    assert_eq!(results.len(), 2);
}

// =============================================================================
// Type Coercion Scenarios (5+ tests)
// =============================================================================

#[test]
fn mixed_int_float_sum() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(10));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Float(5.5));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(20));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Sum of mixed Int/Float should work and produce Float
    let result = g.v().values("value").sum();
    if let Value::Float(f) = result {
        assert!((f - 35.5).abs() < 1e-10);
    } else {
        panic!("Expected Float for mixed sum, got {:?}", result);
    }
}

#[test]
fn mixed_int_float_min() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(10));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Float(5.5));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(20));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // min of mixed Int/Float uses type discriminant ordering (Int < Float)
    // so the minimum is the smallest Int, not the smallest numeric value
    let result = g.v().values("value").min();
    assert!(result.is_some());
    // Int(10) is minimum because Int < Float in type ordering
    assert_eq!(result, Some(Value::Int(10)));
}

#[test]
fn mixed_int_float_max() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(10));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Float(25.5));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(20));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // max of mixed Int/Float uses type discriminant ordering (Int < Float)
    // so the maximum is the largest Float, not the largest numeric value
    let result = g.v().values("value").max();
    assert!(result.is_some());
    // Float(25.5) is maximum because Float > Int in type ordering
    if let Some(Value::Float(f)) = result {
        assert!((f - 25.5).abs() < 1e-10);
    } else {
        panic!("Expected Float maximum, got {:?}", result);
    }
}

#[test]
fn int_comparison_with_int_predicate() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(42));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(10));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Exact match with Int
    let results = g.v().has_where("value", p::eq(42i64)).to_list();
    assert_eq!(results.len(), 1);

    // Greater than comparison
    let results = g.v().has_where("value", p::gt(30i64)).to_list();
    assert_eq!(results.len(), 1);
}

#[test]
fn string_comparison_exact_match() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Alice".to_string()));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Bob".to_string()));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Exact string match
    let results = g.v().has_value("name", "Alice").to_list();
    assert_eq!(results.len(), 1);

    // Non-matching string
    let results = g.v().has_value("name", "Charlie").to_list();
    assert!(results.is_empty());
}

#[test]
fn bool_property_filtering() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("active".to_string(), Value::Bool(true));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("active".to_string(), Value::Bool(false));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Filter by boolean property
    let active = g.v().has_value("active", true).to_list();
    assert_eq!(active.len(), 1);

    let inactive = g.v().has_value("active", false).to_list();
    assert_eq!(inactive.len(), 1);
}

#[test]
fn null_property_handling() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Null);
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(42));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // has() should still find vertex with null property (property exists)
    let with_value = g.v().has("value").to_list();
    assert_eq!(with_value.len(), 2);

    // values() returns both (including null)
    let values = g.v().values("value").to_list();
    assert_eq!(values.len(), 2);
}

#[test]
fn type_mismatch_in_predicate() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::String("42".to_string()));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("value".to_string(), Value::Int(42));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Type-specific comparison: string "42" != int 42
    // This tests strict type matching behavior
    let int_results = g.v().has_where("value", p::eq(42i64)).to_list();
    // Should only match the Int(42), not String("42")
    assert_eq!(int_results.len(), 1);
}

#[test]
fn ordering_mixed_numeric_types() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("score".to_string(), Value::Int(10));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("score".to_string(), Value::Float(5.5));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("score".to_string(), Value::Int(20));
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("score".to_string(), Value::Float(15.0));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Order by mixed numeric types ascending
    // Note: Types are ordered by type discriminant first (Int < Float),
    // then by value within each type
    let ordered = g.v().values("score").order().by_asc().build().to_list();
    assert_eq!(ordered.len(), 4);

    // Verify: All Ints come before all Floats, sorted within each type
    // Expected order: Int(10), Int(20), Float(5.5), Float(15.0)
    assert_eq!(ordered[0], Value::Int(10));
    assert_eq!(ordered[1], Value::Int(20));
    if let Value::Float(f) = ordered[2] {
        assert!((f - 5.5).abs() < 1e-10);
    } else {
        panic!("Expected Float at index 2, got {:?}", ordered[2]);
    }
    if let Value::Float(f) = ordered[3] {
        assert!((f - 15.0).abs() < 1e-10);
    } else {
        panic!("Expected Float at index 3, got {:?}", ordered[3]);
    }
}

#[test]
fn list_property_handling() {
    let graph = Graph::new();
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert(
            "tags".to_string(),
            Value::List(vec![
                Value::String("rust".to_string()),
                Value::String("graph".to_string()),
            ]),
        );
        props
    });
    graph.add_vertex("test", {
        let mut props = HashMap::new();
        props.insert("tags".to_string(), Value::List(vec![]));
        props
    });

    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Both vertices have the "tags" property
    let with_tags = g.v().has("tags").to_list();
    assert_eq!(with_tags.len(), 2);

    // values() returns List values
    let tags = g.v().values("tags").to_list();
    assert_eq!(tags.len(), 2);
}

// =============================================================================
// Property Test Graph Scenarios (using create_property_test_graph fixture)
// =============================================================================

#[test]
fn property_test_graph_all_vertex_types() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // The fixture creates 6 vertices with different property patterns
    let vertex_count = g.v().count();
    assert_eq!(vertex_count, 6);

    // Each vertex has a distinct label
    let complete = g.v().has_label("complete").count();
    let strings_only = g.v().has_label("strings_only").count();
    let numbers_only = g.v().has_label("numbers_only").count();
    let booleans = g.v().has_label("booleans").count();
    let sparse = g.v().has_label("sparse").count();
    let nested = g.v().has_label("nested").count();

    assert_eq!(complete, 1);
    assert_eq!(strings_only, 1);
    assert_eq!(numbers_only, 1);
    assert_eq!(booleans, 1);
    assert_eq!(sparse, 1);
    assert_eq!(nested, 1);
}

#[test]
fn property_test_graph_string_properties() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // strings_only vertex has name, description, empty_string, unicode
    let names = g.v().has_label("strings_only").values("name").to_list();
    assert_eq!(names.len(), 1);
    assert_eq!(names[0], Value::String("StringVertex".to_string()));

    // Empty string is a valid property value
    let empty = g
        .v()
        .has_label("strings_only")
        .values("empty_string")
        .to_list();
    assert_eq!(empty.len(), 1);
    assert_eq!(empty[0], Value::String("".to_string()));

    // Unicode strings work correctly
    let unicode = g.v().has_label("strings_only").values("unicode").to_list();
    assert_eq!(unicode.len(), 1);
    assert_eq!(unicode[0], Value::String("こんにちは 🌍".to_string()));
}

#[test]
fn property_test_graph_numeric_edge_cases() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // numbers_only vertex has extreme values
    let large_int = g
        .v()
        .has_label("numbers_only")
        .values("large_int")
        .to_list();
    assert_eq!(large_int.len(), 1);
    assert_eq!(large_int[0], Value::Int(i64::MAX));

    let small_int = g
        .v()
        .has_label("numbers_only")
        .values("small_int")
        .to_list();
    assert_eq!(small_int.len(), 1);
    assert_eq!(small_int[0], Value::Int(i64::MIN));

    let zero = g.v().has_label("numbers_only").values("zero").to_list();
    assert_eq!(zero.len(), 1);
    assert_eq!(zero[0], Value::Int(0));

    // Tiny float preserves precision
    let tiny = g
        .v()
        .has_label("numbers_only")
        .values("tiny_float")
        .to_list();
    assert_eq!(tiny.len(), 1);
    if let Value::Float(f) = tiny[0] {
        assert!((f - 0.000001).abs() < 1e-12);
    } else {
        panic!("Expected Float, got {:?}", tiny[0]);
    }
}

#[test]
fn property_test_graph_boolean_filtering() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Filter by boolean property
    let active = g
        .v()
        .has_label("booleans")
        .has_value("is_active", true)
        .count();
    assert_eq!(active, 1);

    let deleted = g
        .v()
        .has_label("booleans")
        .has_value("is_deleted", false)
        .count();
    assert_eq!(deleted, 1);
}

#[test]
fn property_test_graph_null_property_exists() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // sparse vertex has null_value property
    let nulls = g.v().has_label("sparse").values("null_value").to_list();
    assert_eq!(nulls.len(), 1);
    assert_eq!(nulls[0], Value::Null);

    // has() finds vertex even if property is null
    let with_null = g.v().has_label("sparse").has("null_value").count();
    assert_eq!(with_null, 1);
}

#[test]
fn property_test_graph_list_property() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // complete vertex has list_prop
    let list = g.v().has_label("complete").values("list_prop").to_list();
    assert_eq!(list.len(), 1);
    if let Value::List(items) = &list[0] {
        assert_eq!(items.len(), 3);
        assert_eq!(items[0], Value::Int(1));
        assert_eq!(items[1], Value::Int(2));
        assert_eq!(items[2], Value::Int(3));
    } else {
        panic!("Expected List, got {:?}", list[0]);
    }
}

#[test]
fn property_test_graph_map_property() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // complete vertex has map_prop
    let map = g.v().has_label("complete").values("map_prop").to_list();
    assert_eq!(map.len(), 1);
    if let Value::Map(m) = &map[0] {
        assert!(m.contains_key("nested_key"));
        assert_eq!(
            m.get("nested_key"),
            Some(&Value::String("nested_value".to_string()))
        );
    } else {
        panic!("Expected Map, got {:?}", map[0]);
    }
}

#[test]
fn property_test_graph_cross_label_property_query() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // Query for int_prop across all vertices - only complete and numbers_only have numeric props
    let int_prop_count = g.v().has("int_prop").count();
    assert_eq!(int_prop_count, 1); // Only complete has int_prop

    // Query all vertices that have any "name" property
    let with_name = g.v().has("name").count();
    assert_eq!(with_name, 1); // Only strings_only has "name"
}

#[test]
fn property_test_graph_sparse_vs_complete() {
    let graph = create_property_test_graph();
    let snapshot = graph.snapshot();
    let g = snapshot.gremlin();

    // complete has 7 properties, sparse has only 2
    let complete_props = g
        .v()
        .has_label("complete")
        .has("string_prop")
        .has("int_prop")
        .has("float_prop")
        .has("bool_prop")
        .count();
    assert_eq!(complete_props, 1);

    // sparse vertex is missing all these properties
    let sparse_has_int = g.v().has_label("sparse").has("int_prop").count();
    assert_eq!(sparse_has_int, 0);

    let sparse_has_string = g.v().has_label("sparse").has("string_prop").count();
    assert_eq!(sparse_has_string, 0);
}