@@ -766,29 +766,32 @@ apiDescribe.skip(
766
766
} ) ;
767
767
768
768
it ( 'performs sum that overflows max int using getAggregationFromServer' , ( ) => {
769
+ // A large value that will be represented as a Long on the server, but
770
+ // doubling (2x) this value must overflow Long and force the result to be
771
+ // represented as a Double type on the server.
772
+ const maxLong = Math . pow ( 2 , 63 ) - 1 ;
773
+
769
774
const testDocs = {
770
775
a : {
771
776
author : 'authorA' ,
772
777
title : 'titleA' ,
773
778
pages : 100 ,
774
779
year : 1980 ,
775
- rating : Number . MAX_SAFE_INTEGER
780
+ rating : maxLong
776
781
} ,
777
782
b : {
778
783
author : 'authorB' ,
779
784
title : 'titleB' ,
780
785
pages : 50 ,
781
786
year : 2020 ,
782
- rating : Number . MAX_SAFE_INTEGER
787
+ rating : maxLong
783
788
}
784
789
} ;
785
790
return withTestCollection ( persistence , testDocs , async coll => {
786
791
const snapshot = await getAggregateFromServer ( coll , {
787
792
totalRating : sum ( 'rating' )
788
793
} ) ;
789
- expect ( snapshot . data ( ) . totalRating ) . to . equal (
790
- Number . MAX_SAFE_INTEGER + Number . MAX_SAFE_INTEGER
791
- ) ;
794
+ expect ( snapshot . data ( ) . totalRating ) . to . equal ( maxLong + maxLong ) ;
792
795
} ) ;
793
796
} ) ;
794
797
@@ -1296,7 +1299,10 @@ apiDescribe.skip(
1296
1299
const snapshot = await getAggregateFromServer ( coll , {
1297
1300
averageRating : average ( 'rating' )
1298
1301
} ) ;
1299
- expect ( snapshot . data ( ) . averageRating ) . to . equal ( 9.2 ) ;
1302
+ expect ( snapshot . data ( ) . averageRating ) . to . be . approximately (
1303
+ 9.2 ,
1304
+ 0.0000001
1305
+ ) ;
1300
1306
} ) ;
1301
1307
} ) ;
1302
1308
@@ -1368,7 +1374,7 @@ apiDescribe.skip(
1368
1374
} ) ;
1369
1375
} ) ;
1370
1376
1371
- it ( 'performs average that could overflow IEEE754 during accumulation using getAggregationFromServer' , ( ) => {
1377
+ it ( 'performs average that overflows IEEE754 during accumulation using getAggregationFromServer' , ( ) => {
1372
1378
const testDocs = {
1373
1379
a : {
1374
1380
author : 'authorA' ,
@@ -1389,7 +1395,9 @@ apiDescribe.skip(
1389
1395
const snapshot = await getAggregateFromServer ( coll , {
1390
1396
averageRating : average ( 'rating' )
1391
1397
} ) ;
1392
- expect ( snapshot . data ( ) . averageRating ) . to . equal ( Number . MAX_VALUE ) ;
1398
+ expect ( snapshot . data ( ) . averageRating ) . to . equal (
1399
+ Number . POSITIVE_INFINITY
1400
+ ) ;
1393
1401
} ) ;
1394
1402
} ) ;
1395
1403
0 commit comments