@@ -45,6 +45,14 @@ private void putTestEntityInteger(byte vByte, short vShort, int vInt, long vLong
45
45
box .put (entity );
46
46
}
47
47
48
+ private void putTestEntityUnsignedInteger (short vShort , int vInt , long vLong ) {
49
+ TestEntity entity = new TestEntity ();
50
+ entity .setSimpleShortU (vShort );
51
+ entity .setSimpleIntU (vInt );
52
+ entity .setSimpleLongU (vLong );
53
+ box .put (entity );
54
+ }
55
+
48
56
private void putTestEntityFloat (float vFloat , double vDouble ) {
49
57
TestEntity entity = new TestEntity ();
50
58
entity .setSimpleFloat (vFloat );
@@ -496,6 +504,9 @@ public void minDouble_notSupported() {
496
504
assertUnsupported (() -> query .property (simpleShort ).minDouble (), exceptionMessage );
497
505
assertUnsupported (() -> query .property (simpleInt ).minDouble (), exceptionMessage );
498
506
assertUnsupported (() -> query .property (simpleLong ).minDouble (), exceptionMessage );
507
+ assertUnsupported (() -> query .property (simpleShortU ).minDouble (), exceptionMessage );
508
+ assertUnsupported (() -> query .property (simpleIntU ).minDouble (), exceptionMessage );
509
+ assertUnsupported (() -> query .property (simpleLongU ).minDouble (), exceptionMessage );
499
510
}
500
511
501
512
@ Test
@@ -523,6 +534,9 @@ public void maxDouble_notSupported() {
523
534
assertUnsupported (() -> query .property (simpleShort ).maxDouble (), exceptionMessage );
524
535
assertUnsupported (() -> query .property (simpleInt ).maxDouble (), exceptionMessage );
525
536
assertUnsupported (() -> query .property (simpleLong ).maxDouble (), exceptionMessage );
537
+ assertUnsupported (() -> query .property (simpleShortU ).maxDouble (), exceptionMessage );
538
+ assertUnsupported (() -> query .property (simpleIntU ).maxDouble (), exceptionMessage );
539
+ assertUnsupported (() -> query .property (simpleLongU ).maxDouble (), exceptionMessage );
526
540
}
527
541
528
542
@ Test
@@ -545,6 +559,10 @@ public void avg_noData() {
545
559
assertEquals (Double .NaN , baseQuery .property (simpleShort ).avg (), 0.0 );
546
560
assertEquals (Double .NaN , baseQuery .property (simpleInt ).avg (), 0.0 );
547
561
assertEquals (Double .NaN , baseQuery .property (simpleLong ).avg (), 0.0 );
562
+ // Integer treated as unsigned.
563
+ assertEquals (Double .NaN , baseQuery .property (simpleShortU ).avg (), 0.0 );
564
+ assertEquals (Double .NaN , baseQuery .property (simpleIntU ).avg (), 0.0 );
565
+ assertEquals (Double .NaN , baseQuery .property (simpleLongU ).avg (), 0.0 );
548
566
// Float.
549
567
assertEquals (Double .NaN , baseQuery .property (simpleFloat ).avg (), 0.0 );
550
568
assertEquals (Double .NaN , baseQuery .property (simpleDouble ).avg (), 0.0 );
@@ -557,6 +575,10 @@ public void min_noData() {
557
575
assertEquals (0 , baseQuery .property (simpleShort ).min ());
558
576
assertEquals (0 , baseQuery .property (simpleInt ).min ());
559
577
assertEquals (0 , baseQuery .property (simpleLong ).min ());
578
+ // Integer treated as unsigned.
579
+ assertEquals (0 , baseQuery .property (simpleShortU ).min ());
580
+ assertEquals (0 , baseQuery .property (simpleIntU ).min ());
581
+ assertEquals (0 , baseQuery .property (simpleLongU ).min ());
560
582
}
561
583
562
584
@ Test
@@ -573,6 +595,10 @@ public void max_noData() {
573
595
assertEquals (0 , baseQuery .property (simpleShort ).max ());
574
596
assertEquals (0 , baseQuery .property (simpleInt ).max ());
575
597
assertEquals (0 , baseQuery .property (simpleLong ).max ());
598
+ // Integer treated as unsigned.
599
+ assertEquals (0 , baseQuery .property (simpleShortU ).max ());
600
+ assertEquals (0 , baseQuery .property (simpleIntU ).max ());
601
+ assertEquals (0 , baseQuery .property (simpleLongU ).max ());
576
602
}
577
603
578
604
@ Test
@@ -589,6 +615,10 @@ public void sum_noData() {
589
615
assertEquals (0 , baseQuery .property (simpleShort ).sum ());
590
616
assertEquals (0 , baseQuery .property (simpleInt ).sum ());
591
617
assertEquals (0 , baseQuery .property (simpleLong ).sum ());
618
+ // Integer treated as unsigned.
619
+ assertEquals (0 , baseQuery .property (simpleShortU ).sum ());
620
+ assertEquals (0 , baseQuery .property (simpleIntU ).sum ());
621
+ assertEquals (0 , baseQuery .property (simpleLongU ).sum ());
592
622
}
593
623
594
624
@ Test
@@ -639,6 +669,16 @@ public void sum_byteShortIntOverflow() {
639
669
assertEquals (Integer .MAX_VALUE + 1L , baseQuery .property (simpleInt ).sum ());
640
670
}
641
671
672
+ @ Test
673
+ public void sum_unsignedShortIntOverflow () {
674
+ putTestEntityUnsignedInteger ((short ) -1 , -1 , 0 );
675
+ putTestEntityUnsignedInteger ((short ) 1 , 1 , 0 );
676
+
677
+ Query <TestEntity > baseQuery = box .query ().build ();
678
+ assertEquals (0x1_0000 , baseQuery .property (simpleShortU ).sum ());
679
+ assertEquals (0x1_0000_0000L , baseQuery .property (simpleIntU ).sum ());
680
+ }
681
+
642
682
@ Test
643
683
public void sum_longOverflow_exception () {
644
684
exceptionRule .expect (NumericOverflowException .class );
@@ -650,6 +690,28 @@ public void sum_longOverflow_exception() {
650
690
box .query ().build ().property (simpleLong ).sum ();
651
691
}
652
692
693
+ @ Test
694
+ public void sum_longUnderflow_exception () {
695
+ exceptionRule .expect (NumericOverflowException .class );
696
+ exceptionRule .expectMessage ("Numeric overflow" );
697
+
698
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , Long .MIN_VALUE );
699
+ putTestEntityInteger ((byte ) 0 , (short ) 0 , 0 , -1 );
700
+
701
+ box .query ().build ().property (simpleLong ).sum ();
702
+ }
703
+
704
+ @ Test
705
+ public void sum_unsignedLongOverflow_exception () {
706
+ exceptionRule .expect (NumericOverflowException .class );
707
+ exceptionRule .expectMessage ("Numeric overflow" );
708
+
709
+ putTestEntityUnsignedInteger ((short ) 0 , 0 , -1 );
710
+ putTestEntityUnsignedInteger ((short ) 0 , 0 , 1 );
711
+
712
+ box .query ().build ().property (simpleLongU ).sum ();
713
+ }
714
+
653
715
@ Test
654
716
public void sumDouble_positiveOverflow_exception () {
655
717
putTestEntityFloat (Float .POSITIVE_INFINITY , Double .POSITIVE_INFINITY );
@@ -691,6 +753,9 @@ public void testAggregates() {
691
753
PropertyQuery longQuery = query .property (simpleLong );
692
754
PropertyQuery floatQuery = query .property (simpleFloat );
693
755
PropertyQuery doubleQuery = query .property (simpleDouble );
756
+ PropertyQuery shortUQuery = query .property (simpleShortU );
757
+ PropertyQuery intUQuery = query .property (simpleIntU );
758
+ PropertyQuery longUQuery = query .property (simpleLongU );
694
759
// avg
695
760
assertEquals (0.5 , booleanQuery .avg (), 0.0001 );
696
761
assertEquals (-37.5 , byteQuery .avg (), 0.0001 );
@@ -699,20 +764,29 @@ public void testAggregates() {
699
764
assertEquals (3000.5 , longQuery .avg (), 0.0001 );
700
765
assertEquals (400.05 , floatQuery .avg (), 0.0001 );
701
766
assertEquals (2020.005 , doubleQuery .avg (), 0.0001 );
767
+ assertEquals (2100.5 , shortUQuery .avg (), 0.0001 );
768
+ assertEquals (2000.5 , intUQuery .avg (), 0.0001 );
769
+ assertEquals (3000.5 , longUQuery .avg (), 0.0001 );
702
770
// min
703
771
assertEquals (-38 , byteQuery .min ());
704
772
assertEquals (2100 , shortQuery .min ());
705
773
assertEquals (2000 , intQuery .min ());
706
774
assertEquals (3000 , longQuery .min ());
707
775
assertEquals (400 , floatQuery .minDouble (), 0.001 );
708
776
assertEquals (2020 , doubleQuery .minDouble (), 0.001 );
777
+ assertEquals (2100 , shortUQuery .min ());
778
+ assertEquals (2000 , intUQuery .min ());
779
+ assertEquals (3000 , longUQuery .min ());
709
780
// max
710
781
assertEquals (-37 , byteQuery .max ());
711
782
assertEquals (2101 , shortQuery .max ());
712
783
assertEquals (2001 , intQuery .max ());
713
784
assertEquals (3001 , longQuery .max ());
714
785
assertEquals (400.1 , floatQuery .maxDouble (), 0.001 );
715
786
assertEquals (2020.01 , doubleQuery .maxDouble (), 0.001 );
787
+ assertEquals (2101 , shortUQuery .max ());
788
+ assertEquals (2001 , intUQuery .max ());
789
+ assertEquals (3001 , longUQuery .max ());
716
790
// sum
717
791
assertEquals (1 , booleanQuery .sum ());
718
792
assertEquals (1 , booleanQuery .sumDouble (), 0.001 );
@@ -726,6 +800,12 @@ public void testAggregates() {
726
800
assertEquals (6001 , longQuery .sumDouble (), 0.001 );
727
801
assertEquals (800.1 , floatQuery .sumDouble (), 0.001 );
728
802
assertEquals (4040.01 , doubleQuery .sumDouble (), 0.001 );
803
+ assertEquals (4201 , shortUQuery .sum ());
804
+ assertEquals (4201 , shortUQuery .sumDouble (), 0.001 );
805
+ assertEquals (4001 , intUQuery .sum ());
806
+ assertEquals (4001 , intUQuery .sumDouble (), 0.001 );
807
+ assertEquals (6001 , longUQuery .sum ());
808
+ assertEquals (6001 , longUQuery .sumDouble (), 0.001 );
729
809
}
730
810
731
811
@ Test
0 commit comments