Skip to content

Commit bfbe62b

Browse files
authored
test: add tests to stats/base/dists/geometric/mgf
PR-URL: #10483 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Signed-off-by: Vishal Gaikwad <154438441+ivishal-g@users.noreply.github.com>
1 parent f63b6ef commit bfbe62b

3 files changed

Lines changed: 146 additions & 5 deletions

File tree

lib/node_modules/@stdlib/stats/base/dists/geometric/mgf/test/test.factory.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var abs = require( '@stdlib/math/base/special/abs' );
26+
var ln = require( '@stdlib/math/base/special/ln' );
2627
var PINF = require( '@stdlib/constants/float64/pinf' );
2728
var NINF = require( '@stdlib/constants/float64/ninf' );
2829
var EPS = require( '@stdlib/constants/float64/eps' );
@@ -148,3 +149,15 @@ tape( 'the created function evaluates the mgf for `x` given large parameter `p`'
148149
}
149150
t.end();
150151
});
152+
153+
tape( 'the factory function returns NaN when t equals the boundary condition t = -ln(1-p)', function test( t ) {
154+
var boundary;
155+
var mgf;
156+
var y;
157+
158+
mgf = factory( 0.5 );
159+
boundary = -ln( 1 - 0.5 );
160+
y = mgf( boundary );
161+
t.strictEqual( isnan( y ), true, 'returns expected value' );
162+
t.end();
163+
});

lib/node_modules/@stdlib/stats/base/dists/geometric/mgf/test/test.mgf.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ var abs = require( '@stdlib/math/base/special/abs' );
2626
var PINF = require( '@stdlib/constants/float64/pinf' );
2727
var NINF = require( '@stdlib/constants/float64/ninf' );
2828
var EPS = require( '@stdlib/constants/float64/eps' );
29+
var isfinite = require( '@stdlib/math/base/assert/is-finite' );
30+
var ln = require( '@stdlib/math/base/special/ln' );
31+
var exp = require( '@stdlib/math/base/special/exp' );
2932
var mgf = require( './../lib' );
3033

3134

@@ -69,7 +72,7 @@ tape( 'if provided a value outside `[0,1]` for success probability `p`, the func
6972
t.end();
7073
});
7174

72-
tape( 'the function evaluates the mgf for `x` given small parameter `p`', function test( t ) {
75+
tape( 'the function evaluates the MGF for `x` given small parameter `p`', function test( t ) {
7376
var expected;
7477
var delta;
7578
var tol;
@@ -94,7 +97,7 @@ tape( 'the function evaluates the mgf for `x` given small parameter `p`', functi
9497
t.end();
9598
});
9699

97-
tape( 'the function evaluates the mgf for `x` given large parameter `p`', function test( t ) {
100+
tape( 'the function evaluates the MGF for `x` given large parameter `p`', function test( t ) {
98101
var expected;
99102
var delta;
100103
var tol;
@@ -118,3 +121,64 @@ tape( 'the function evaluates the mgf for `x` given large parameter `p`', functi
118121
}
119122
t.end();
120123
});
124+
125+
tape( 'the function returns NaN when t equals the boundary condition t = -ln(1-p)', function test( t ) {
126+
var boundary;
127+
var p;
128+
var y;
129+
130+
p = 0.5;
131+
boundary = -ln( 1 - p );
132+
y = mgf( boundary, p );
133+
t.strictEqual( isnan( y ), true, 'returns expected value' );
134+
t.end();
135+
});
136+
137+
tape( 'the function returns a finite value when t is just below the boundary condition', function test( t ) {
138+
var boundary;
139+
var p;
140+
var y;
141+
142+
p = 0.5;
143+
boundary = -ln( 1 - p );
144+
y = mgf( boundary - 1e-15, p );
145+
t.strictEqual( isnan( y ), false, 'returns expected value' );
146+
t.ok( isfinite( y ), 'value is finite' );
147+
t.end();
148+
});
149+
150+
tape( 'the function returns NaN when t is just above the boundary condition', function test( t ) {
151+
var boundary;
152+
var p;
153+
var y;
154+
155+
p = 0.5;
156+
boundary = -ln( 1 - p );
157+
y = mgf( boundary + 1e-15, p );
158+
t.strictEqual( isnan( y ), true, 'returns expected value' );
159+
t.end();
160+
});
161+
162+
tape( 'the function returns NaN when p equals 0', function test( t ) {
163+
var y;
164+
165+
y = mgf( 0.5, 0.0 );
166+
t.strictEqual( isnan( y ), true, 'returns expected value' );
167+
t.end();
168+
});
169+
170+
tape( 'the function returns e^t when p equals 1', function test( t ) {
171+
var y;
172+
173+
y = mgf( 0.5, 1.0 );
174+
t.strictEqual( y, exp( 0.5 ), 'returns expected value' );
175+
t.end();
176+
});
177+
178+
tape( 'the function returns NaN for very small p values due to boundary condition', function test( t ) {
179+
var y;
180+
181+
y = mgf( 0.001, 1e-10 );
182+
t.strictEqual( isnan( y ), true, 'returns expected value' );
183+
t.end();
184+
});

lib/node_modules/@stdlib/stats/base/dists/geometric/mgf/test/test.native.js

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
25+
var tryRequire = require( '@stdlib/utils/try-require' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var abs = require( '@stdlib/math/base/special/abs' );
2728
var PINF = require( '@stdlib/constants/float64/pinf' );
2829
var NINF = require( '@stdlib/constants/float64/ninf' );
2930
var EPS = require( '@stdlib/constants/float64/eps' );
30-
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var isfinite = require( '@stdlib/math/base/assert/is-finite' );
32+
var ln = require( '@stdlib/math/base/special/ln' );
33+
var exp = require( '@stdlib/math/base/special/exp' );
3134

3235

3336
// FIXTURES //
@@ -78,7 +81,7 @@ tape( 'if provided a value outside `[0,1]` for success probability `p`, the func
7881
t.end();
7982
});
8083

81-
tape( 'the function evaluates the mgf for `x` given small parameter `p`', opts, function test( t ) {
84+
tape( 'the function evaluates the MGF for `x` given small parameter `p`', opts, function test( t ) {
8285
var expected;
8386
var delta;
8487
var tol;
@@ -103,7 +106,7 @@ tape( 'the function evaluates the mgf for `x` given small parameter `p`', opts,
103106
t.end();
104107
});
105108

106-
tape( 'the function evaluates the mgf for `x` given large parameter `p`', opts, function test( t ) {
109+
tape( 'the function evaluates the MGF for `x` given large parameter `p`', opts, function test( t ) {
107110
var expected;
108111
var delta;
109112
var tol;
@@ -127,3 +130,64 @@ tape( 'the function evaluates the mgf for `x` given large parameter `p`', opts,
127130
}
128131
t.end();
129132
});
133+
134+
tape( 'the function returns NaN when t equals the boundary condition t = -ln(1-p)', opts, function test( t ) {
135+
var boundary;
136+
var p;
137+
var y;
138+
139+
p = 0.5;
140+
boundary = -ln( 1 - p );
141+
y = mgf( boundary, p );
142+
t.strictEqual( isnan( y ), true, 'returns expected value' );
143+
t.end();
144+
});
145+
146+
tape( 'the function returns a finite value when t is just below the boundary condition', opts, function test( t ) {
147+
var boundary;
148+
var p;
149+
var y;
150+
151+
p = 0.5;
152+
boundary = -ln( 1 - p );
153+
y = mgf( boundary - 1e-15, p );
154+
t.strictEqual( isnan( y ), false, 'returns expected value' );
155+
t.ok( isfinite( y ), 'value is finite' );
156+
t.end();
157+
});
158+
159+
tape( 'the function returns NaN when t is just above the boundary condition', opts, function test( t ) {
160+
var boundary;
161+
var p;
162+
var y;
163+
164+
p = 0.5;
165+
boundary = -ln( 1 - p );
166+
y = mgf( boundary + 1e-15, p );
167+
t.strictEqual( isnan( y ), true, 'returns expected value' );
168+
t.end();
169+
});
170+
171+
tape( 'the function returns NaN when p equals 0', opts, function test( t ) {
172+
var y;
173+
174+
y = mgf( 0.5, 0.0 );
175+
t.strictEqual( isnan( y ), true, 'returns expected value' );
176+
t.end();
177+
});
178+
179+
tape( 'the function returns e^t when p equals 1', opts, function test( t ) {
180+
var y;
181+
182+
y = mgf( 0.5, 1.0 );
183+
t.strictEqual( y, exp( 0.5 ), 'returns expected value' );
184+
t.end();
185+
});
186+
187+
tape( 'the function returns NaN for very small p values due to boundary condition', opts, function test( t ) {
188+
var y;
189+
190+
y = mgf( 0.001, 1e-10 );
191+
t.strictEqual( isnan( y ), true, 'returns expected value' );
192+
t.end();
193+
});

0 commit comments

Comments
 (0)