diff --git a/lib/node_modules/@stdlib/stats/fligner-test/README.md b/lib/node_modules/@stdlib/stats/fligner-test/README.md index 92ac82e1457b..97c80063752a 100644 --- a/lib/node_modules/@stdlib/stats/fligner-test/README.md +++ b/lib/node_modules/@stdlib/stats/fligner-test/README.md @@ -36,7 +36,7 @@ limitations under the License. var flignerTest = require( '@stdlib/stats/fligner-test' ); ``` -#### flignerTest( a\[,b,...,k]\[, opts] ) +#### flignerTest( a\[,b,...,k]\[, options] ) For input arrays `a`, `b`, ... holding numeric observations, this function calculates the Fligner-Killeen test, which tests the null hypothesis that the variances in all `k` groups are the same. @@ -46,7 +46,9 @@ var x = [ 2.9, 3.0, 2.5, 2.6, 3.2 ]; var y = [ 3.8, 2.7, 4.0, 2.4 ]; var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; -var out = flignerTest( x, y, z ); +var res = flignerTest( x, y, z ); + +var o = res.toJSON(); /* returns { 'rejected': false, @@ -106,7 +108,18 @@ var out = flignerTest( arr, { }); ``` -The returned object comes with a `.print()` method which when invoked will print a formatted output of the results of the hypothesis test. `print` accepts a `digits` option that controls the number of decimal digits displayed for the outputs and a `decision` option, which when set to `false` will hide the test decision. +The function returns a results `object` having the following properties: + +- **alpha**: significance level. +- **rejected**: `boolean` indicating the test decision. +- **pValue**: test p-value. +- **statistic**: test statistic. +- **df**: degrees of freedom. +- **method**: test name. +- **toString**: serializes results as formatted test output. +- **toJSON**: serializes results as a JSON object. + +The returned object comes with a `.toString()` method which when invoked will print a formatted output of the results of the hypothesis test. `toString` accepts a `digits` option that controls the number of decimal digits displayed for the outputs and a `decision` option, which when set to `false` will hide the test decision. ```javascript var x = [ 2.9, 3.0, 2.5, 2.6, 3.2 ]; @@ -114,15 +127,15 @@ var y = [ 3.8, 2.7, 4.0, 2.4 ]; var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; var out = flignerTest( x, y, z ); -console.log( out.print() ); -/* => +var table = out.toString(); +/* returns Fligner-Killeen test of homogeneity of variances - Null hypothesis: The variances in all groups are the same. + Null hypothesis: The variances in all groups are the same pValue: 0.0739 statistic: 5.2092 - df: 2 + degrees of freedom: 2 Test Decision: Fail to reject null in favor of alternative at 5% significance level */ @@ -158,15 +171,15 @@ var out = flignerTest( x, y, z ); } */ -var table = out.print(); +var table = out.toString(); /* returns Fligner-Killeen test of homogeneity of variances - Null hypothesis: The variances in all groups are the same. + Null hypothesis: The variances in all groups are the same pValue: 0.0739 statistic: 5.2092 - df: 2 + degrees of freedom: 2 Test Decision: Fail to reject null in favor of alternative at 5% significance level */ diff --git a/lib/node_modules/@stdlib/stats/fligner-test/docs/repl.txt b/lib/node_modules/@stdlib/stats/fligner-test/docs/repl.txt index 6d13c2fe009f..e2079198f38d 100644 --- a/lib/node_modules/@stdlib/stats/fligner-test/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/fligner-test/docs/repl.txt @@ -40,8 +40,11 @@ out.df: Object Degrees of freedom. - out.print: Function - Function to print formatted output. + out.toString: Function + Serializes results as formatted output. + + out.toJSON: Function + Serializes results as JSON. Examples -------- @@ -50,7 +53,11 @@ > var y = [ 3.8, 2.7, 4.0, 2.4 ]; > var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; - > var out = {{alias}}( x, y, z ) + > var out = {{alias}}( x, y, z ); + > var o = out.toJSON() + {...} + > out.toString() + > var arr = [ 2.9, 3.0, 2.5, 2.6, 3.2, ... 3.8, 2.7, 4.0, 2.4, @@ -61,7 +68,11 @@ ... 'b', 'b', 'b', 'b', ... 'c', 'c', 'c', 'c', 'c' ... ]; - > out = {{alias}}( arr, { 'groups': groups } ) + > out = {{alias}}( arr, { 'groups': groups } ); + > o = out.toJSON() + {...} + > out.toString() + See Also -------- diff --git a/lib/node_modules/@stdlib/stats/fligner-test/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/fligner-test/docs/types/index.d.ts index 0d5959258560..fe4328392495 100644 --- a/lib/node_modules/@stdlib/stats/fligner-test/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/fligner-test/docs/types/index.d.ts @@ -72,9 +72,14 @@ interface Results { df: number; /** - * Function to print formatted output. + * Serializes results as formatted test output. */ - print: Function; + toString: Function; // FIXME: provide better type + + /** + * Serializes results as JSON. + */ + toJSON: Function; // FIXME: provide better type } /** diff --git a/lib/node_modules/@stdlib/stats/fligner-test/examples/index.js b/lib/node_modules/@stdlib/stats/fligner-test/examples/index.js index e79d9c810d30..34b05daaff10 100644 --- a/lib/node_modules/@stdlib/stats/fligner-test/examples/index.js +++ b/lib/node_modules/@stdlib/stats/fligner-test/examples/index.js @@ -30,5 +30,5 @@ console.log( 'Output object: ' ); console.dir( out ); console.log( '\n' ); -var table = out.print(); +var table = out.toString(); console.log( table ); diff --git a/lib/node_modules/@stdlib/stats/fligner-test/lib/main.js b/lib/node_modules/@stdlib/stats/fligner-test/lib/main.js index 84f9190ec87a..11cb8dd99720 100644 --- a/lib/node_modules/@stdlib/stats/fligner-test/lib/main.js +++ b/lib/node_modules/@stdlib/stats/fligner-test/lib/main.js @@ -22,40 +22,20 @@ var isCollection = require( '@stdlib/assert/is-collection' ); var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var setReadOnly = require( '@stdlib/utils/define-read-only-property' ); var objectKeys = require( '@stdlib/utils/keys' ); var qnorm = require( '@stdlib/stats/base/dists/normal/quantile' ); var chisqCDF = require( '@stdlib/stats/base/dists/chisquare/cdf' ); var group = require( '@stdlib/utils/group' ); var ranks = require( '@stdlib/stats/ranks' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var abs = require( '@stdlib/math/strided/special/abs' ); var pow = require( '@stdlib/math/base/special/pow' ); var indexOf = require( '@stdlib/utils/index-of' ); var format = require( '@stdlib/string/format' ); +var filled = require( '@stdlib/array/base/filled' ); +var Float64Array = require( '@stdlib/array/float64' ); var median = require( './median.js' ); var validate = require( './validate.js' ); -var print = require( './print.js' ); // eslint-disable-line stdlib/no-redeclare - - -// FUNCTIONS // - -/** -* Returns an array of a chosen length filled with the supplied value. -* -* @private -* @param {*} val - value to repeat -* @param {NonNegativeInteger} len - array length -* @returns {Array} filled array -*/ -function repeat( val, len ) { - var out = new Array( len ); - var i; - - for ( i = 0; i < len; i++ ) { - out[ i ] = val; - } - return out; -} +var Results = require( './results.js' ); // MAIN // @@ -102,7 +82,6 @@ function fligner() { var stat; var err; var loc; - var out; var df; var M2; var a; @@ -137,7 +116,7 @@ function fligner() { groups = []; for ( i = 0; i < ngroups; i++ ) { args.push( arguments[ i ] ); - groups = groups.concat( repeat( i, arguments[ i ].length ) ); + groups = groups.concat( filled( i, arguments[ i ].length ) ); } } if ( opts.alpha === void 0 ) { @@ -163,15 +142,13 @@ function fligner() { x = x.concat( args[ i ] ); } n = x.length; - xabs = new Array( n ); - for ( i = 0; i < n; i++ ) { - xabs[ i ] = abs( x[ i ] ); - } + xabs = new Float64Array( n ); + abs( n, 'float64', x, 1, 'float64', xabs, 1 ); scores = ranks( xabs ); - a = new Array( n ); + a = new Float64Array( n ); mean = 0.0; M2 = 0.0; - sums = repeat( 0.0, ngroups ); + sums = filled( 0.0, ngroups ); for ( i = 0; i < n; i++ ) { a[ i ] = qnorm( ( 1.0 + ( scores[ i ]/(n+1) ) ) / 2.0, 0.0, 1.0 ); sums[ ( levels ) ? indexOf( levels, groups[i] ) : groups[i] ] += a[ i ]; @@ -188,15 +165,7 @@ function fligner() { df = ngroups - 1; pval = 1.0 - chisqCDF( stat, df ); - out = {}; - setReadOnly( out, 'rejected', pval <= alpha ); - setReadOnly( out, 'alpha', alpha ); - setReadOnly( out, 'pValue', pval ); - setReadOnly( out, 'statistic', stat ); - setReadOnly( out, 'df', df ); - setReadOnly( out, 'method', 'Fligner-Killeen test of homogeneity of variances' ); - setReadOnly( out, 'print', print ); - return out; + return new Results( pval, opts.alpha, stat, df ); } diff --git a/lib/node_modules/@stdlib/stats/fligner-test/lib/print.js b/lib/node_modules/@stdlib/stats/fligner-test/lib/print.js deleted file mode 100644 index bd321bd9bd24..000000000000 --- a/lib/node_modules/@stdlib/stats/fligner-test/lib/print.js +++ /dev/null @@ -1,93 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); -var isObject = require( '@stdlib/assert/is-plain-object' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var roundn = require( '@stdlib/math/base/special/roundn' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Pretty-print output of test. -* -* @param {Object} [opts] - options object -* @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point -* @param {boolean} [opts.decision=true] - boolean indicating whether to print the test decision -* @throws {TypeError} options must be an object -* @throws {TypeError} must provide valid options -* @returns {string} formatted output -*/ -function print( opts ) { // eslint-disable-line stdlib/no-redeclare - /* eslint-disable no-invalid-this */ - var decision; - var dgts; - var str; - - dgts = 4; - decision = true; - if ( arguments.length > 0 ) { - if ( !isObject( opts ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', opts ) ); - } - if ( hasOwnProp( opts, 'digits' ) ) { - if ( !isPositiveInteger( opts.digits ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) ); - } - dgts = opts.digits; - } - if ( hasOwnProp( opts, 'decision' ) ) { - if ( !isBoolean( opts.decision ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'decision', opts.decision ) ); - } - decision = opts.decision; - } - } - - str = ''; - str += this.method; - str += '\n\n'; - str += 'Null hypothesis: The variances in all groups are the same.'; - str += '\n\n'; - str += ' pValue: ' + roundn( this.pValue, -dgts ) + '\n'; - str += ' statistic: ' + roundn( this.statistic, -dgts ) + '\n'; - str += ' df: ' + roundn( this.df, -dgts ); - str += '\n\n'; - if ( decision ) { - str += 'Test Decision: '; - if ( this.rejected ) { - str += 'Reject null in favor of alternative at ' + (this.alpha*100) + '% significance level'; - } else { - str += 'Fail to reject null in favor of alternative at ' + (this.alpha*100) + '% significance level'; - } - str += '\n'; - } - return str; -} - - -// EXPORTS // - -module.exports = print; diff --git a/lib/node_modules/@stdlib/stats/fligner-test/lib/results.js b/lib/node_modules/@stdlib/stats/fligner-test/lib/results.js new file mode 100644 index 000000000000..dcbd74ca23d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/fligner-test/lib/results.js @@ -0,0 +1,283 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable no-invalid-this, no-restricted-syntax */ + +'use strict'; + +// MODULES // + +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var isObject = require( '@stdlib/assert/is-plain-object' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var roundn = require( '@stdlib/math/base/special/roundn' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a results object. +* +* @private +* @constructor +* @param {number} pValue - p-value +* @param {number} alpha - significance +* @param {number} statistic - test statistic +* @param {number} df - degrees of freedom +* @returns {Results} results object +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* // returns +*/ +function Results( pValue, alpha, statistic, df ) { + if ( !(this instanceof Results) ) { + return new Results( pValue, alpha, statistic, df ); + } + this._pValue = pValue; + this._alpha = alpha; + this._statistic = statistic; + this._df = df; + return this; +} + +/** +* Significance level. +* +* @private +* @name alpha +* @memberof Results.prototype +* @type {number} +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var alpha = res.alpha; +* // returns 0.1 +*/ +setReadOnlyAccessor( Results.prototype, 'alpha', function get() { + return this._alpha; +}); + +/** +* Degrees of freedom. +* +* @private +* @name df +* @memberof Results.prototype +* @type {number} +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var df = res.df; +* // returns 1 +*/ +setReadOnlyAccessor( Results.prototype, 'df', function get() { + return this._df; +}); + +/** +* Test name. +* +* @private +* @name method +* @memberof Results.prototype +* @type {string} +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var method = res.method; +* // returns 'Fligner-Killeen test of homogeneity of variances' +*/ +setReadOnly( Results.prototype, 'method', 'Fligner-Killeen test of homogeneity of variances' ); + +/** +* Test p-value. +* +* @private +* @name pValue +* @memberof Results.prototype +* @type {number} +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var pval = res.pValue; +* // returns 0.0719 +*/ +setReadOnlyAccessor( Results.prototype, 'pValue', function get() { + return this._pValue; +}); + +/** +* Boolean indicating the test decision. +* +* @private +* @name rejected +* @memberof Results.prototype +* @type {boolean} +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var bool = res.rejected; +* // returns true +*/ +setReadOnlyAccessor( Results.prototype, 'rejected', function get() { + return ( this._pValue <= this._alpha ); +}); + +/** +* Test statistic. +* +* @private +* @name statistic +* @memberof Results.prototype +* @type {number} +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var stat = res.statistic; +* // returns 3.24 +*/ +setReadOnlyAccessor( Results.prototype, 'statistic', function get() { + return this._statistic; +}); + +/** +* Serializes a results object as a string. +* +* ## Notes +* +* - Example output: +* +* ```text +* +* Fligner-Killeen test of homogeneity of variances +* +* Null hypothesis: The variances in all groups are the same +* +* pValue: 0.0719 +* statistic: 3.24 +* degrees of freedom: 1 +* +* Test Decision: Reject null in favor of alternative at 10% significance level +* +* ``` +* +* @private +* @name toString +* @memberof Results.prototype +* @type {Function} +* @param {Options} [opts] - options object +* @param {PositiveInteger} [opts.digits=4] - number of digits after the decimal point +* @param {boolean} [opts.decision=true] - boolean indicating whether to show the test decision +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {string} serialized results +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var str = res.toString(); +* // returns +*/ +setReadOnly( Results.prototype, 'toString', function toString( opts ) { + var decision; + var dgts; + var out; + + dgts = 4; + decision = true; + if ( arguments.length > 0 ) { + if ( !isObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Must provide an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'digits' ) ) { + if ( !isPositiveInteger( opts.digits ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'digits', opts.digits ) ); + } + dgts = opts.digits; + } + if ( hasOwnProp( opts, 'decision' ) ) { + if ( !isBoolean( opts.decision ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'decision', opts.decision ) ); + } + decision = opts.decision; + } + } + out = [ + this.method, + '', + '', + 'Null hypothesis: The variances in all groups are the same', + '', + '', + ' pValue: ' + roundn( this._pValue, -dgts ), + ' statistic: ' + roundn( this._statistic, -dgts ), + ' degrees of freedom: ' + this._df, + '' + ]; + if ( decision ) { + out.push( 'Test Decision: ' + ( ( this.rejected ) ? 'Reject' : 'Fail to reject' ) + ' null in favor of alternative at ' + (this._alpha*100.0) + '% significance level' ); + out.push( '' ); + } + return out.join( '\n' ); +}); + +/** +* Serializes a results object as a JSON object. +* +* ## Notes +* +* - `JSON.stringify()` implicitly calls this method when stringifying a `Results` instance. +* +* @private +* @name toJSON +* @memberof Results.prototype +* @type {Function} +* @returns {Object} serialized object +* +* @example +* var res = new Results( 0.0719, 0.1, 3.24, 1 ); +* +* var o = res.toJSON(); +* // returns { 'rejected': true, 'alpha': 0.1, 'pValue': 0.0719, 'df': 1, ... } +*/ +setReadOnly( Results.prototype, 'toJSON', function toJSON() { + return { + 'rejected': this.rejected, + 'alpha': this._alpha, + 'pValue': this._pValue, + 'df': this._df, + 'statistic': this._statistic, + 'method': this.method + }; +}); + + +// EXPORTS // + +module.exports = Results; diff --git a/lib/node_modules/@stdlib/stats/fligner-test/lib/validate.js b/lib/node_modules/@stdlib/stats/fligner-test/lib/validate.js index 8a415aff7bb1..38dac0bebea1 100644 --- a/lib/node_modules/@stdlib/stats/fligner-test/lib/validate.js +++ b/lib/node_modules/@stdlib/stats/fligner-test/lib/validate.js @@ -20,7 +20,7 @@ // MODULES // -var isArray = require( '@stdlib/assert/is-array' ); +var isCollection = require( '@stdlib/assert/is-collection' ); var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; var isObject = require( '@stdlib/assert/is-plain-object' ); var isnan = require( '@stdlib/assert/is-nan' ); @@ -52,8 +52,8 @@ function validate( opts, options ) { } if ( hasOwnProp( options, 'groups' ) ) { opts.groups = options.groups; - if ( !isArray( opts.groups ) ) { - return new TypeError( format( 'invalid option. `%s` option must be an array. Option: `%s`.', 'groups', opts.groups ) ); + if ( !isCollection( opts.groups ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a collection. Option: `%s`.', 'groups', opts.groups ) ); } } return null; diff --git a/lib/node_modules/@stdlib/stats/fligner-test/test/test.js b/lib/node_modules/@stdlib/stats/fligner-test/test/test.js index 3c0e21b91e5c..e98b4ba71acd 100644 --- a/lib/node_modules/@stdlib/stats/fligner-test/test/test.js +++ b/lib/node_modules/@stdlib/stats/fligner-test/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var contains = require( '@stdlib/assert/contains' ); var abs = require( '@stdlib/math/base/special/abs' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -184,7 +185,7 @@ tape( 'the function correctly computes a Kruskal-Wallis test', function test( t t.end(); }); -tape( 'the function returns an object with a `.print()` method for printing a formatted output table', function test( t ) { +tape( 'the function returns an object with a `.toString()` method for printing a formatted output table', function test( t ) { var table; var out; @@ -193,19 +194,19 @@ tape( 'the function returns an object with a `.print()` method for printing a fo var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; out = flignerTest( x, y, z ); - table = out.print(); + table = out.toString(); t.equal( typeof table, 'string', 'returns a string' ); out = flignerTest( x, y, z, { 'alpha': 0.01 }); - table = out.print(); + table = out.toString(); t.equal( typeof table, 'string', 'returns a string' ); t.end(); }); -tape( 'the function returns an object with a `.print()` method that accepts a `digits` option to control the number of decimal digits displayed', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that accepts a `digits` option to control the number of decimal digits displayed', function test( t ) { var table; var out; @@ -214,14 +215,14 @@ tape( 'the function returns an object with a `.print()` method that accepts a `d var z = [ 6.8, 3.4, 3.7, 5.2, 4.0 ]; out = flignerTest( x, y, z ); - table = out.print({ + table = out.toString({ 'digits': 6 }); t.equal( typeof table, 'string', 'returns a pretty-printed table' ); t.end(); }); -tape( 'the function returns an object with a `.print()` method that accepts a `decision` option to control whether the test result should be displayed', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that accepts a `decision` option to control whether the test result should be displayed', function test( t ) { var table; var out; @@ -230,7 +231,7 @@ tape( 'the function returns an object with a `.print()` method that accepts a `d var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; out = flignerTest( x, y, z ); - table = out.print({ + table = out.toString({ 'decision': false }); t.equal( typeof table, 'string', 'returns a pretty-printed table' ); @@ -238,7 +239,7 @@ tape( 'the function returns an object with a `.print()` method that accepts a `d t.end(); }); -tape( 'the function returns an object with a `.print()` method that accepts an `options` object', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that accepts an `options` object', function test( t ) { var table; var out; @@ -247,13 +248,13 @@ tape( 'the function returns an object with a `.print()` method that accepts an ` var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; out = flignerTest( x, y, z ); - table = out.print( {} ); + table = out.toString( {} ); t.equal( typeof table, 'string', 'returns a pretty-printed table' ); t.end(); }); -tape( 'the function returns an object with a `.print()` method that throws an error if `options` is not a simple object', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that throws an error if `options` is not a simple object', function test( t ) { var values; var out; var i; @@ -282,12 +283,12 @@ tape( 'the function returns an object with a `.print()` method that throws an er function badValue( value ) { return function badValue() { - out.print( value ); + out.toString( value ); }; } }); -tape( 'the function returns an object with a `.print()` method that throws an error if the `digits` option is not a positive integer', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that throws an error if the `digits` option is not a positive integer', function test( t ) { var values; var out; var i; @@ -319,14 +320,14 @@ tape( 'the function returns an object with a `.print()` method that throws an er function badValue( value ) { return function badValue() { - out.print({ + out.toString({ 'digits': value }); }; } }); -tape( 'the function returns an object with a `.print()` method that throws an error if the `decision` option is not a boolean primitive', function test( t ) { +tape( 'the function returns an object with a `.toString()` method that throws an error if the `decision` option is not a boolean primitive', function test( t ) { var values; var out; var i; @@ -358,9 +359,23 @@ tape( 'the function returns an object with a `.print()` method that throws an er function badValue( value ) { return function badValue() { - out.print({ + out.toString({ 'decision': value }); }; } }); + +tape( 'the function returns an object with a `.toJSON()` method for serializing the test results object', function test( t ) { + var table; + var out; + + var x = [ 2.9, 3.0, 2.5, 2.6, 3.2 ]; + var y = [ 3.8, 2.7, 4.0, 2.4 ]; + var z = [ 2.8, 3.4, 3.7, 2.2, 2.0 ]; + + out = flignerTest( x, y, z ); + table = out.toJSON(); + t.strictEqual( isPlainObject( table ), true, 'returns a plain object' ); + t.end(); +});