@@ -24,6 +24,7 @@ var resolve = require( 'path' ).resolve;
2424var tape = require ( 'tape' ) ;
2525var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
2626var abs = require ( '@stdlib/math/base/special/abs' ) ;
27+ var NINF = require ( '@stdlib/constants/float64/ninf' ) ;
2728var EPS = require ( '@stdlib/constants/float64/eps' ) ;
2829var tryRequire = require ( '@stdlib/utils/try-require' ) ;
2930
@@ -38,7 +39,8 @@ var opts = {
3839
3940// FIXTURES //
4041
41- var data = require ( './fixtures/python/small_c.json' ) ;
42+ var smallC = require ( './fixtures/python/small_c.json' ) ;
43+ var largeC = require ( './fixtures/python/large_c.json' ) ;
4244
4345
4446// TESTS //
@@ -55,29 +57,32 @@ tape( 'the function returns `NaN` if provided `NaN`', opts, function test( t ) {
5557 t . end ( ) ;
5658} ) ;
5759
58- tape ( 'the function returns `NaN` if provided a shape parameter which is not positive ' , opts , function test ( t ) {
59- var y ;
60+ tape ( 'if provided `c <= 0`, the function returns `NaN` ' , opts , function test ( t ) {
61+ var v ;
6062
61- y = entropy ( 0.0 ) ;
62- t . equal ( isnan ( y ) , true , 'returns expected value' ) ;
63+ v = entropy ( 0.0 ) ;
64+ t . equal ( isnan ( v ) , true , 'returns expected value' ) ;
6365
64- y = entropy ( - 1.0 ) ;
65- t . equal ( isnan ( y ) , true , 'returns expected value' ) ;
66+ v = entropy ( - 1.0 ) ;
67+ t . equal ( isnan ( v ) , true , 'returns expected value' ) ;
68+
69+ v = entropy ( NINF ) ;
70+ t . equal ( isnan ( v ) , true , 'returns expected value' ) ;
6671
6772 t . end ( ) ;
6873} ) ;
6974
70- tape ( 'the function returns the differential entropy of a Bradford distribution' , opts , function test ( t ) {
75+ tape ( 'the function returns the differential entropy of a Bradford distribution given small parameter `c` ' , opts , function test ( t ) {
7176 var expected ;
7277 var delta ;
7378 var tol ;
79+ var i ;
7480 var c ;
7581 var y ;
76- var i ;
7782
78- expected = data . expected ;
79- c = data . c ;
80- for ( i = 0 ; i < c . length ; i ++ ) {
83+ expected = smallC . expected ;
84+ c = smallC . c ;
85+ for ( i = 0 ; i < expected . length ; i ++ ) {
8186 y = entropy ( c [ i ] ) ;
8287 if ( y === expected [ i ] ) {
8388 t . equal ( y , expected [ i ] , 'c: ' + c [ i ] + ', y: ' + y + ', expected: ' + expected [ i ] ) ;
@@ -89,3 +94,26 @@ tape( 'the function returns the differential entropy of a Bradford distribution'
8994 }
9095 t . end ( ) ;
9196} ) ;
97+
98+ tape ( 'the function returns the differential entropy of a Bradford distribution given large parameter `c`' , opts , function test ( t ) {
99+ var expected ;
100+ var delta ;
101+ var tol ;
102+ var i ;
103+ var c ;
104+ var y ;
105+
106+ expected = largeC . expected ;
107+ c = largeC . c ;
108+ for ( i = 0 ; i < expected . length ; i ++ ) {
109+ y = entropy ( c [ i ] ) ;
110+ if ( y === expected [ i ] ) {
111+ t . equal ( y , expected [ i ] , 'c: ' + c [ i ] + ', y: ' + y + ', expected: ' + expected [ i ] ) ;
112+ } else {
113+ delta = abs ( y - expected [ i ] ) ;
114+ tol = 45.0 * EPS * abs ( expected [ i ] ) ;
115+ t . ok ( delta <= tol , 'within tolerance. c: ' + c [ i ] + '. y: ' + y + '. E: ' + expected [ i ] + '. Δ: ' + delta + '. tol: ' + tol + '.' ) ;
116+ }
117+ }
118+ t . end ( ) ;
119+ } ) ;
0 commit comments