@@ -9,6 +9,16 @@ function assertClose(actual, expected, tolerance = 1e-12) {
99 `${ actual } != ${ expected } ` ) ;
1010}
1111
12+ function recordRepeated ( histogram , options , value , count ) {
13+ const block = createHistogram ( options ) ;
14+ block . record ( value ) ;
15+ while ( count > 0 ) {
16+ if ( count % 2 === 1 ) histogram . add ( block ) ;
17+ count = Math . floor ( count / 2 ) ;
18+ if ( count > 0 ) block . add ( block ) ;
19+ }
20+ }
21+
1222( async ( ) => {
1323 const empty = createHistogram ( ) ;
1424 const emptyResult = await empty . qrde ( ) ;
@@ -23,6 +33,9 @@ function assertClose(actual, expected, tolerance = 1e-12) {
2333 assert . strictEqual ( emptyResult . corrections , 0 ) ;
2434 assert . strictEqual ( emptyResult . dequantize , 'hdr' ) ;
2535
36+ assert . throws ( ( ) => empty . qrde . call ( { } ) , {
37+ code : 'ERR_INVALID_THIS' ,
38+ } ) ;
2639 assert . throws ( ( ) => empty . qrde ( null ) , {
2740 code : 'ERR_INVALID_ARG_TYPE' ,
2841 } ) ;
@@ -219,4 +232,18 @@ function assertClose(actual, expected, tolerance = 1e-12) {
219232 await largeCount . qrde ( { bins : 2 , dequantize : 'none' } ) ;
220233 assert . strictEqual ( largeCountResult . count , ( 1n << 53n ) + 1n ) ;
221234 assertClose ( largeCountResult . quantiles [ 1 ] , 2 ) ;
235+
236+ // Exercise correction across the exact-to-asymptotic beta CDF threshold.
237+ const correctionOptions = { highest : 131071 , figures : 5 } ;
238+ const correction = createHistogram ( correctionOptions ) ;
239+ recordRepeated ( correction , correctionOptions , 1 , 26239 ) ;
240+ recordRepeated ( correction , correctionOptions , 131071 , 973761 ) ;
241+ const count = 1_000_000 ;
242+ const threshold = ( 1 - Math . sqrt ( 1 - 100_000 / ( count + 1 ) ) ) / 2 ;
243+ const corrected = await correction . qrde ( {
244+ probabilities : [ 0 , threshold - 1e-10 , threshold + 1e-10 , 1 ] ,
245+ dequantize : 'none' ,
246+ } ) ;
247+ assert . strictEqual ( corrected . corrections , 1 ) ;
248+ assert . strictEqual ( corrected . quantiles [ 1 ] , corrected . quantiles [ 2 ] ) ;
222249} ) ( ) . then ( common . mustCall ( ) ) ;
0 commit comments