@@ -981,24 +981,48 @@ public void testMillisecondsBasedUnitCalendarRoundingSize() {
981
981
Rounding .Prepared prepared = unitRounding .prepare (time ("2010-01-01T00:00:00.000Z" ), time ("2020-01-01T00:00:00.000Z" ));
982
982
assertThat (prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .SECOND_OF_MINUTE ),
983
983
closeTo (3600.0 , 0.000001 ));
984
- assertThat (prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .MINUTES_OF_HOUR ), closeTo (60.0 , 0.000001 ));
985
- assertThat (prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .HOUR_OF_DAY ), closeTo (1.0 , 0.000001 ));
984
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .SECOND_OF_MINUTE ),
985
+ closeTo (3600.0 , 0.000001 ));
986
+ assertThat (prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .MINUTES_OF_HOUR ),
987
+ closeTo (60.0 , 0.000001 ));
988
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .MINUTES_OF_HOUR ),
989
+ closeTo (60.0 , 0.000001 ));
990
+ assertThat (prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .HOUR_OF_DAY ),
991
+ closeTo (1.0 , 0.000001 ));
992
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .HOUR_OF_DAY ),
993
+ closeTo (1.0 , 0.000001 ));
986
994
assertThat (prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .DAY_OF_MONTH ),
987
995
closeTo (1 / 24.0 , 0.000001 ));
996
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .DAY_OF_MONTH ),
997
+ closeTo (1 / 24.0 , 0.000001 ));
988
998
assertThat (prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .WEEK_OF_WEEKYEAR ),
989
999
closeTo (1 / 168.0 , 0.000001 ));
1000
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .WEEK_OF_WEEKYEAR ),
1001
+ closeTo (1 / 168.0 , 0.000001 ));
990
1002
IllegalArgumentException ex = expectThrows (IllegalArgumentException .class ,
991
1003
() -> prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .MONTH_OF_YEAR ));
992
1004
assertThat (ex .getMessage (), equalTo ("Cannot use month-based rate unit [month] with non-month based calendar interval " +
993
1005
"histogram [hour] only week, day, hour, minute and second are supported for this histogram" ));
1006
+ ex = expectThrows (IllegalArgumentException .class ,
1007
+ () -> prepared .roundingSize (Rounding .DateTimeUnit .MONTH_OF_YEAR ));
1008
+ assertThat (ex .getMessage (), equalTo ("Cannot use month-based rate unit [month] with non-month based calendar interval " +
1009
+ "histogram [hour] only week, day, hour, minute and second are supported for this histogram" ));
994
1010
ex = expectThrows (IllegalArgumentException .class ,
995
1011
() -> prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .QUARTER_OF_YEAR ));
996
1012
assertThat (ex .getMessage (), equalTo ("Cannot use month-based rate unit [quarter] with non-month based calendar interval " +
997
1013
"histogram [hour] only week, day, hour, minute and second are supported for this histogram" ));
1014
+ ex = expectThrows (IllegalArgumentException .class ,
1015
+ () -> prepared .roundingSize (Rounding .DateTimeUnit .QUARTER_OF_YEAR ));
1016
+ assertThat (ex .getMessage (), equalTo ("Cannot use month-based rate unit [quarter] with non-month based calendar interval " +
1017
+ "histogram [hour] only week, day, hour, minute and second are supported for this histogram" ));
998
1018
ex = expectThrows (IllegalArgumentException .class ,
999
1019
() -> prepared .roundingSize (time ("2015-01-01T00:00:00.000Z" ), Rounding .DateTimeUnit .YEAR_OF_CENTURY ));
1000
1020
assertThat (ex .getMessage (), equalTo ("Cannot use month-based rate unit [year] with non-month based calendar interval " +
1001
1021
"histogram [hour] only week, day, hour, minute and second are supported for this histogram" ));
1022
+ ex = expectThrows (IllegalArgumentException .class ,
1023
+ () -> prepared .roundingSize (Rounding .DateTimeUnit .YEAR_OF_CENTURY ));
1024
+ assertThat (ex .getMessage (), equalTo ("Cannot use month-based rate unit [year] with non-month based calendar interval " +
1025
+ "histogram [hour] only week, day, hour, minute and second are supported for this histogram" ));
1002
1026
}
1003
1027
1004
1028
public void testNonMillisecondsBasedUnitCalendarRoundingSize () {
@@ -1009,6 +1033,9 @@ public void testNonMillisecondsBasedUnitCalendarRoundingSize() {
1009
1033
assertThat (prepared .roundingSize (firstQuarter , Rounding .DateTimeUnit .MONTH_OF_YEAR ), closeTo (3.0 , 0.000001 ));
1010
1034
assertThat (prepared .roundingSize (firstQuarter , Rounding .DateTimeUnit .QUARTER_OF_YEAR ), closeTo (1.0 , 0.000001 ));
1011
1035
assertThat (prepared .roundingSize (firstQuarter , Rounding .DateTimeUnit .YEAR_OF_CENTURY ), closeTo (0.25 , 0.000001 ));
1036
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .MONTH_OF_YEAR ), closeTo (3.0 , 0.000001 ));
1037
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .QUARTER_OF_YEAR ), closeTo (1.0 , 0.000001 ));
1038
+ assertThat (prepared .roundingSize (Rounding .DateTimeUnit .YEAR_OF_CENTURY ), closeTo (0.25 , 0.000001 ));
1012
1039
// Real interval based
1013
1040
assertThat (prepared .roundingSize (firstQuarter , Rounding .DateTimeUnit .SECOND_OF_MINUTE ), closeTo (7776000.0 , 0.000001 ));
1014
1041
assertThat (prepared .roundingSize (firstQuarter , Rounding .DateTimeUnit .MINUTES_OF_HOUR ), closeTo (129600.0 , 0.000001 ));
@@ -1017,6 +1044,10 @@ public void testNonMillisecondsBasedUnitCalendarRoundingSize() {
1017
1044
long thirdQuarter = prepared .round (time ("2015-07-01T00:00:00.000Z" ));
1018
1045
assertThat (prepared .roundingSize (thirdQuarter , Rounding .DateTimeUnit .DAY_OF_MONTH ), closeTo (92.0 , 0.000001 ));
1019
1046
assertThat (prepared .roundingSize (thirdQuarter , Rounding .DateTimeUnit .HOUR_OF_DAY ), closeTo (2208.0 , 0.000001 ));
1047
+ IllegalArgumentException ex = expectThrows (IllegalArgumentException .class ,
1048
+ () -> prepared .roundingSize (Rounding .DateTimeUnit .SECOND_OF_MINUTE ));
1049
+ assertThat (ex .getMessage (), equalTo ("Cannot use non month-based rate unit [second] with calendar interval histogram " +
1050
+ "[quarter] only month, quarter and year are supported for this histogram" ));
1020
1051
}
1021
1052
1022
1053
public void testFixedRoundingPoints () {
0 commit comments