@@ -42,6 +42,9 @@ private void putTestEntityInteger(byte vByte, short vShort, int vInt, long vLong
42
42
entity .setSimpleShort (vShort );
43
43
entity .setSimpleInt (vInt );
44
44
entity .setSimpleLong (vLong );
45
+ entity .setSimpleShortU (vShort );
46
+ entity .setSimpleIntU (vInt );
47
+ entity .setSimpleLongU (vLong );
45
48
box .put (entity );
46
49
}
47
50
@@ -479,6 +482,18 @@ public void avg_notSupported() {
479
482
assertUnsupported (() -> query .property (simpleString ).avg (), exceptionMessage );
480
483
}
481
484
485
+ @ Test
486
+ public void avgLong_notSupported () {
487
+ Query <TestEntity > query = box .query ().build ();
488
+ String exceptionMessage = "Cannot calculate sum. This function is for integer types only. This operation is not supported for Property " ;
489
+ assertUnsupported (() -> query .property (simpleByteArray ).avgLong (), exceptionMessage );
490
+ assertUnsupported (() -> query .property (simpleString ).avgLong (), exceptionMessage );
491
+
492
+ String exceptionMessage2 = "Please use the double based average instead. This operation is not supported for Property " ;
493
+ assertUnsupported (() -> query .property (simpleFloat ).avgLong (), exceptionMessage2 );
494
+ assertUnsupported (() -> query .property (simpleDouble ).avgLong (), exceptionMessage2 );
495
+ }
496
+
482
497
@ Test
483
498
public void min_notSupported () {
484
499
Query <TestEntity > query = box .query ().build ();
@@ -568,6 +583,20 @@ public void avg_noData() {
568
583
assertEquals (Double .NaN , baseQuery .property (simpleDouble ).avg (), 0.0 );
569
584
}
570
585
586
+ @ Test
587
+ public void avgLong_noData () {
588
+ Query <TestEntity > baseQuery = box .query ().build ();
589
+ // Integer.
590
+ assertEquals (0 , baseQuery .property (simpleByte ).avgLong ());
591
+ assertEquals (0 , baseQuery .property (simpleShort ).avgLong ());
592
+ assertEquals (0 , baseQuery .property (simpleInt ).avgLong ());
593
+ assertEquals (0 , baseQuery .property (simpleLong ).avgLong ());
594
+ // Integer treated as unsigned.
595
+ assertEquals (0 , baseQuery .property (simpleShortU ).avgLong ());
596
+ assertEquals (0 , baseQuery .property (simpleIntU ).avgLong ());
597
+ assertEquals (0 , baseQuery .property (simpleLongU ).avgLong ());
598
+ }
599
+
571
600
@ Test
572
601
public void min_noData () {
573
602
Query <TestEntity > baseQuery = box .query ().build ();
@@ -668,6 +697,39 @@ public void avg_NaN() {
668
697
assertEquals (Double .NaN , baseQuery .property (simpleDouble ).avg (), 0.001 );
669
698
}
670
699
700
+ @ Test
701
+ public void avgLong_positiveOverflow () {
702
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , Long .MAX_VALUE );
703
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , 1 );
704
+
705
+ Query <TestEntity > baseQuery = box .query ().build ();
706
+ assertEquals (Long .MAX_VALUE / 2 + 1 , baseQuery .property (simpleLong ).avgLong ());
707
+ // Should not change if treated as unsigned.
708
+ assertEquals (Long .MAX_VALUE / 2 + 1 , baseQuery .property (simpleLongU ).avgLong ());
709
+ }
710
+
711
+ @ Test
712
+ public void avgLong_negativeOverflow () {
713
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , Long .MIN_VALUE );
714
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , -1 );
715
+
716
+ Query <TestEntity > baseQuery = box .query ().build ();
717
+ assertEquals (Long .MIN_VALUE / 2 , baseQuery .property (simpleLong ).avgLong ());
718
+ // Should not change if treated as unsigned.
719
+ assertEquals (Long .MIN_VALUE / 2 , baseQuery .property (simpleLongU ).avgLong ());
720
+ }
721
+
722
+ @ Test
723
+ public void avgLong_unsignedOverflow () {
724
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , -1 );
725
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , 1 );
726
+
727
+ Query <TestEntity > baseQuery = box .query ().build ();
728
+ assertEquals (Long .MIN_VALUE , baseQuery .property (simpleLongU ).avgLong ());
729
+ // Should be different if treated as signed.
730
+ assertEquals (0 , baseQuery .property (simpleLong ).avgLong ());
731
+ }
732
+
671
733
@ Test
672
734
public void sum_byteShortIntOverflow () {
673
735
putTestEntityInteger (Byte .MAX_VALUE , Short .MAX_VALUE , Integer .MAX_VALUE , 0 );
@@ -777,6 +839,15 @@ public void testAggregates() {
777
839
assertEquals (2100.5 , shortUQuery .avg (), 0.0001 );
778
840
assertEquals (2000.5 , intUQuery .avg (), 0.0001 );
779
841
assertEquals (3000.5 , longUQuery .avg (), 0.0001 );
842
+ // avgLong
843
+ assertEquals (1 , booleanQuery .avgLong ());
844
+ assertEquals (-38 , byteQuery .avgLong ());
845
+ assertEquals (2101 , shortQuery .avgLong ());
846
+ assertEquals (2001 , intQuery .avgLong ());
847
+ assertEquals (3001 , longQuery .avgLong ());
848
+ assertEquals (2101 , shortUQuery .avgLong ());
849
+ assertEquals (2001 , intUQuery .avgLong ());
850
+ assertEquals (3001 , longUQuery .avgLong ());
780
851
// min
781
852
assertEquals (-38 , byteQuery .min ());
782
853
assertEquals (2100 , shortQuery .min ());
0 commit comments