@@ -24,6 +24,17 @@ var resolve = require( 'path' ).resolve;
2424var tape = require ( 'tape' ) ;
2525var tryRequire = require ( '@stdlib/utils/try-require' ) ;
2626var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
27+ var abs = require ( '@stdlib/math/base/special/abs' ) ;
28+ var PINF = require ( '@stdlib/constants/float64/pinf' ) ;
29+ var NINF = require ( '@stdlib/constants/float64/ninf' ) ;
30+ var EPS = require ( '@stdlib/constants/float64/eps' ) ;
31+
32+
33+ // FIXTURES //
34+
35+ var largeRate = require ( './fixtures/julia/large_rate.json' ) ;
36+ var largeShape = require ( './fixtures/julia/large_shape.json' ) ;
37+ var bothLarge = require ( './fixtures/julia/both_large.json' ) ;
2738
2839
2940// VARIABLES //
@@ -33,41 +44,174 @@ var opts = {
3344 'skip' : ( pdf instanceof Error )
3445} ;
3546
36-
37- // TESTS //
38-
3947tape ( 'main export is a function' , opts , function test ( t ) {
40- t . ok ( true , __filename ) ;
41- t . strictEqual ( typeof pdf , 'function' , 'main export is a function' ) ;
42- t . end ( ) ;
48+ t . ok ( true , __filename ) ;
49+ t . strictEqual ( typeof pdf , 'function' , 'main export is a function' ) ;
50+ t . end ( ) ;
4351} ) ;
4452
4553tape ( 'if provided `NaN` for any parameter, the function returns `NaN`' , opts , function test ( t ) {
46- var y = pdf ( NaN , 1.0 , 1.0 ) ;
47- t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
48- y = pdf ( 0.0 , NaN , 1.0 ) ;
49- t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
50- y = pdf ( 0.0 , 1.0 , NaN ) ;
51- t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
52- t . end ( ) ;
54+ var y = pdf ( NaN , 1.0 , 1.0 ) ;
55+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
56+
57+ y = pdf ( 0.0 , NaN , 1.0 ) ;
58+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
59+
60+ y = pdf ( 0.0 , 1.0 , NaN ) ;
61+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
62+
63+ t . end ( ) ;
64+ } ) ;
65+
66+ tape ( 'if provided `+infinity` for `x` and a finite `k` and `lambda`, the function returns `0`' , opts , function test ( t ) {
67+ var y = pdf ( PINF , 1.0 , 1.0 ) ;
68+ t . strictEqual ( y , 0.0 , 'returns expected value' ) ;
69+ t . end ( ) ;
5370} ) ;
5471
55- tape ( 'if provided a non-integer `k`, the function returns `NaN `' , opts , function test ( t ) {
56- var y = pdf ( 1.0 , 1.5 , 1.0 ) ;
57- t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
58- t . end ( ) ;
72+ tape ( 'if provided `-infinity` for `x` and a finite `k` and `lambda` , the function returns `0 `' , opts , function test ( t ) {
73+ var y = pdf ( NINF , 1.0 , 1.0 ) ;
74+ t . strictEqual ( y , 0.0 , 'returns expected value' ) ;
75+ t . end ( ) ;
5976} ) ;
6077
61- tape ( 'if provided a negative `k`, the function returns `NaN`' , opts , function test ( t ) {
62- var y = pdf ( 1.0 , - 1.0 , 1.0 ) ;
63- t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
64- t . end ( ) ;
78+ tape ( 'if provided `k <= 0`, the function returns `NaN`' , opts , function test ( t ) {
79+ var y ;
80+
81+ y = pdf ( 2.0 , - 1.0 , 2.0 ) ;
82+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
83+
84+ y = pdf ( 0.0 , - 1.0 , 2.0 ) ;
85+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
86+
87+ y = pdf ( 2.0 , NINF , 1.0 ) ;
88+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
89+
90+ y = pdf ( 2.0 , NINF , PINF ) ;
91+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
92+
93+ y = pdf ( 2.0 , NINF , NINF ) ;
94+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
95+
96+ y = pdf ( 2.0 , NINF , NaN ) ;
97+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
98+
99+ t . end ( ) ;
100+ } ) ;
101+
102+ y = pdf ( 2.0 , NINF , NINF ) ;
103+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
104+
105+ y = pdf ( 2.0 , NINF , NaN ) ;
106+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
107+
108+ t . end ( ) ;
65109} ) ;
66110
67111tape ( 'if provided `lambda <= 0`, the function returns `NaN`' , opts , function test ( t ) {
68- var y = pdf ( 1.0 , 1.0 , 0.0 ) ;
69- t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
70- y = pdf ( 1.0 , 1.0 , - 1.0 ) ;
71- t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
72- t . end ( ) ;
112+ var y ;
113+
114+ y = pdf ( 2.0 , 2.0 , - 1.0 ) ;
115+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
116+
117+ y = pdf ( 0.0 , 2.0 , - 1.0 ) ;
118+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
119+
120+ y = pdf ( 2.0 , 1.0 , NINF ) ;
121+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
122+
123+ y = pdf ( 2.0 , PINF , NINF ) ;
124+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
125+
126+ y = pdf ( 2.0 , NINF , NINF ) ;
127+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
128+
129+ y = pdf ( 2.0 , NaN , NINF ) ;
130+ t . strictEqual ( isnan ( y ) , true , 'returns expected value' ) ;
131+
132+ t . end ( ) ;
133+ } ) ;
134+
135+ tape ( 'the function evaluates the pdf for `x` given large `k` and `lambda`' , opts , function test ( t ) {
136+ var expected ;
137+ var lambda ;
138+ var delta ;
139+ var tol ;
140+ var i ;
141+ var k ;
142+ var x ;
143+ var y ;
144+
145+ expected = bothLarge . expected ;
146+ x = bothLarge . x ;
147+ k = bothLarge . k ;
148+ lambda = bothLarge . lambda ;
149+
150+ for ( i = 0 ; i < x . length ; i ++ ) {
151+ y = pdf ( x [ i ] , k [ i ] , lambda [ i ] ) ;
152+ if ( y === expected [ i ] ) {
153+ t . strictEqual ( y , expected [ i ] , 'x: ' + x [ i ] + ', k: ' + k [ i ] + ', lambda: ' + lambda [ i ] + ', y: ' + y + ', expected: ' + expected [ i ] ) ;
154+ } else {
155+ delta = abs ( y - expected [ i ] ) ;
156+ tol = 180.0 * EPS * abs ( expected [ i ] ) ;
157+ t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. k: ' + k [ i ] + '. lambda: ' + lambda [ i ] + '. y: ' + y + '. E: ' + expected [ i ] + '. Δ: ' + delta + '. tol: ' + tol + '.' ) ;
158+ }
159+ }
160+ t . end ( ) ;
161+ } ) ;
162+
163+ tape ( 'the function evaluates the pdf for `x` given large shape parameter `k`' , opts , function test ( t ) {
164+ var expected ;
165+ var lambda ;
166+ var delta ;
167+ var tol ;
168+ var i ;
169+ var k ;
170+ var x ;
171+ var y ;
172+
173+ expected = largeShape . expected ;
174+ x = largeShape . x ;
175+ k = largeShape . k ;
176+ lambda = largeShape . lambda ;
177+
178+ for ( i = 0 ; i < x . length ; i ++ ) {
179+ y = pdf ( x [ i ] , k [ i ] , lambda [ i ] ) ;
180+ if ( y === expected [ i ] ) {
181+ t . strictEqual ( y , expected [ i ] , 'x: ' + x [ i ] + ', k: ' + k [ i ] + ', lambda: ' + lambda [ i ] + ', y: ' + y + ', expected: ' + expected [ i ] ) ;
182+ } else {
183+ delta = abs ( y - expected [ i ] ) ;
184+ tol = 90.0 * EPS * abs ( expected [ i ] ) ;
185+ t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. k: ' + k [ i ] + '. lambda: ' + lambda [ i ] + '. y: ' + y + '. E: ' + expected [ i ] + '. Δ: ' + delta + '. tol: ' + tol + '.' ) ;
186+ }
187+ }
188+ t . end ( ) ;
189+ } ) ;
190+
191+ tape ( 'the function evaluates the pdf for `x` given large rate parameter `lambda`' , opts , function test ( t ) {
192+ var expected ;
193+ var lambda ;
194+ var delta ;
195+ var tol ;
196+ var i ;
197+ var k ;
198+ var x ;
199+ var y ;
200+
201+ expected = largeRate . expected ;
202+ x = largeRate . x ;
203+ k = largeRate . k ;
204+ lambda = largeRate . lambda ;
205+
206+ for ( i = 0 ; i < x . length ; i ++ ) {
207+ y = pdf ( x [ i ] , k [ i ] , lambda [ i ] ) ;
208+ if ( y === expected [ i ] ) {
209+ t . strictEqual ( y , expected [ i ] , 'x: ' + x [ i ] + ', k: ' + k [ i ] + ', lambda: ' + lambda [ i ] + ', y: ' + y + ', expected: ' + expected [ i ] ) ;
210+ } else {
211+ delta = abs ( y - expected [ i ] ) ;
212+ tol = 100.0 * EPS * abs ( expected [ i ] ) ;
213+ t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. k: ' + k [ i ] + '. lambda: ' + lambda [ i ] + '. y: ' + y + '. E: ' + expected [ i ] + '. Δ: ' + delta + '. tol: ' + tol + '.' ) ;
214+ }
215+ }
216+ t . end ( ) ;
73217} ) ;
0 commit comments