diff --git a/lib/node_modules/@stdlib/stats/kstest/test/test.js b/lib/node_modules/@stdlib/stats/kstest/test/test.js index 6033fa55326c..cd6d4446aa76 100644 --- a/lib/node_modules/@stdlib/stats/kstest/test/test.js +++ b/lib/node_modules/@stdlib/stats/kstest/test/test.js @@ -21,12 +21,11 @@ // MODULES // var tape = require( 'tape' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var contains = require( '@stdlib/assert/contains' ); var uniform = require( '@stdlib/random/base/uniform' ).factory; var uniformCDF = require( '@stdlib/stats/base/dists/uniform/cdf' ); -var abs = require( '@stdlib/math/base/special/abs' ); var Float64Array = require( '@stdlib/array/float64' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var zeros = require( '@stdlib/array/base/zeros' ); var kstest = require( './../lib' ); @@ -183,46 +182,34 @@ tape( 'the function throws an error if the `alpha` option is a numeric value out tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test', function test( t ) { var expected; - var delta; var out; - var tol; // Choosing the CDF via a string... out = kstest( data, 'uniform', 0.0, 1.0 ); // Tested against R: expected = twosided.pvalue; - delta = abs( out.pValue - expected ); - tol = 20.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' ); expected = twosided.statistic; - delta = abs( out.statistic - expected ); - tol = 5.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); // Directly passing the CDF... out = kstest( data, uniformCDF, 0.0, 1.0 ); // Tested against R: expected = twosided.pvalue; - delta = abs( out.pValue - expected ); - tol = 20.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' ); expected = twosided.statistic; - delta = abs( out.statistic - expected ); - tol = 5.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for an already sorted array', function test( t ) { var expected; - var delta; var out; - var tol; var x; x = [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.8, 0.9 ]; @@ -232,23 +219,17 @@ tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for // Tested against R: expected = 0.99963712; - delta = abs( out.pValue - expected ); - tol = EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' ); expected = 0.10000000000000009; - delta = abs( out.statistic - expected ); - tol = EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for an already sorted typed array', function test( t ) { var expected; - var delta; var out; - var tol; var x; x = new Float64Array( [ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.8, 0.9 ] ); // eslint-disable-line max-len @@ -258,23 +239,17 @@ tape( 'the function correctly computes the two-sided Kolmogorov-Smirnov test for // Tested against R: expected = 0.99963712; - delta = abs( out.pValue - expected ); - tol = EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 0 ), true, 'returns expected value' ); expected = 0.10000000000000009; - delta = abs( out.statistic - expected ); - tol = EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); t.end(); }); tape( 'the function correctly computes a one-sided Kolmogorov-Smirnov test', function test( t ) { var expected; - var delta; var out; - var tol; out = kstest( data, 'uniform', 0.0, 1.0, { 'alternative': 'less' @@ -282,14 +257,10 @@ tape( 'the function correctly computes a one-sided Kolmogorov-Smirnov test', fun // Tested against R: expected = less.pvalue; - delta = abs( out.pValue - expected ); - tol = 60.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 2 ), true, 'returns expected value' ); expected = less.statistic; - delta = abs( out.statistic - expected ); - tol = 20.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); out = kstest( data, 'uniform', 0.0, 1.0, { 'alternative': 'greater' @@ -297,14 +268,10 @@ tape( 'the function correctly computes a one-sided Kolmogorov-Smirnov test', fun // Tested against R: expected = greater.pvalue; - delta = abs( out.pValue - expected ); - tol = 40.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. p-value: '+out.pValue+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.pValue, expected, 1 ), true, 'returns expected value' ); expected = greater.statistic; - delta = abs( out.statistic - expected ); - tol = 80.0 * EPS * abs( expected ); - t.ok( delta <= tol, 'within tolerance. test statistic: '+out.statistic+'. E: '+expected+' Δ: '+delta+'. tol: '+tol ); + t.strictEqual( isAlmostSameValue( out.statistic, expected, 0 ), true, 'returns expected value' ); t.end(); });