@@ -387,4 +387,50 @@ mod tests {
387
387
U64F64 :: saturating_from_num( 1000 )
388
388
) ;
389
389
}
390
+
391
+ // cargo test --package share-pool --lib -- tests::test_get_shares_per_update --exact --show-output
392
+ #[ test]
393
+ fn test_get_shares_per_update ( ) {
394
+ [
395
+ ( 1_i64 , 1_u64 , 1.0 , 1.0 ) ,
396
+ (
397
+ 1_000 ,
398
+ 21_000_000_000_000_000 ,
399
+ 0.00001 ,
400
+ 0.00000000000000000043 ,
401
+ ) ,
402
+ (
403
+ 21_000_000_000_000_000 ,
404
+ 21_000_000_000_000_000 ,
405
+ 0.00001 ,
406
+ 0.00001 ,
407
+ ) ,
408
+ (
409
+ 210_000_000_000_000_000 ,
410
+ 21_000_000_000_000_000 ,
411
+ 0.00001 ,
412
+ 0.0001 ,
413
+ ) ,
414
+ (
415
+ 1_000 ,
416
+ 1_000 ,
417
+ 21_000_000_000_000_000_f64 ,
418
+ 21_000_000_000_000_000_f64 ,
419
+ ) ,
420
+ ]
421
+ . iter ( )
422
+ . for_each ( |( update, shared_value, denominator, expected) | {
423
+ let mock_ops = MockSharePoolDataOperations :: new ( ) ;
424
+ let pool = SharePool :: < u16 , MockSharePoolDataOperations > :: new ( mock_ops) ;
425
+
426
+ let shared_fixed = U64F64 :: from_num ( * shared_value) ;
427
+ let denominator_fixed = U64F64 :: from_num ( * denominator) ;
428
+ let expected_fixed = I64F64 :: from_num ( * expected) ;
429
+
430
+ let spu: I64F64 =
431
+ pool. get_shares_per_update ( * update, & shared_fixed, & denominator_fixed) ;
432
+ let precision: I64F64 = I64F64 :: from_num ( 1000. ) ;
433
+ assert ! ( ( spu - expected_fixed) . abs( ) <= expected_fixed / precision, ) ;
434
+ } ) ;
435
+ }
390
436
}
0 commit comments