From 027da5368e17787f18e4d510cb0d79cba8ca3b0c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Jul 2024 10:09:36 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 4 +- bool/README.md | 49 +++++- bool/benchmark/benchmark.join.js | 50 ++++++ bool/benchmark/benchmark.join.length.js | 102 ++++++++++++ bool/benchmark/benchmark.to_string.js | 50 ++++++ bool/benchmark/benchmark.to_string.length.js | 102 ++++++++++++ bool/docs/repl.txt | 40 +++++ bool/docs/types/index.d.ts | 38 +++++ bool/lib/main.js | 90 +++++++++++ bool/test/test.join.js | 162 +++++++++++++++++++ bool/test/test.to_string.js | 97 +++++++++++ 11 files changed, 782 insertions(+), 2 deletions(-) create mode 100644 bool/benchmark/benchmark.join.js create mode 100644 bool/benchmark/benchmark.join.length.js create mode 100644 bool/benchmark/benchmark.to_string.js create mode 100644 bool/benchmark/benchmark.to_string.length.js create mode 100644 bool/test/test.join.js create mode 100644 bool/test/test.to_string.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 98309589..6b01e438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2024-07-07) +## Unreleased (2024-07-12)
@@ -1324,6 +1324,7 @@ This release closes the following issue: ##### Features +- [`5a66b4b`](https://github.com/stdlib-js/stdlib/commit/5a66b4bb677cdbc4706811ea9f776343297c9f87) - add `join` and `toString` methods to `array/bool` [(#2557)](https://github.com/stdlib-js/stdlib/pull/2557) - [`4a6be43`](https://github.com/stdlib-js/stdlib/commit/4a6be430830868fb181bfa0b8923f37dabaffe8a) - add `reduce` and `reduceRight` methods to `array/bool` [(#2509)](https://github.com/stdlib-js/stdlib/pull/2509) - [`29615af`](https://github.com/stdlib-js/stdlib/commit/29615af970796a43f65f4b00d29bd23a122f2208) - add `slice` and `subarray` methods to `array/bool` [(#2472)](https://github.com/stdlib-js/stdlib/pull/2472) - [`fbc42b4`](https://github.com/stdlib-js/stdlib/commit/fbc42b4c66cf695c6c114f64bf3eff65186026f0) - add `includes` method to `array/bool` [(#2441)](https://github.com/stdlib-js/stdlib/pull/2441) @@ -2394,6 +2395,7 @@ A total of 13 people contributed to this release. Thank you to the following con
+- [`5a66b4b`](https://github.com/stdlib-js/stdlib/commit/5a66b4bb677cdbc4706811ea9f776343297c9f87) - **feat:** add `join` and `toString` methods to `array/bool` [(#2557)](https://github.com/stdlib-js/stdlib/pull/2557) _(by Jaysukh Makvana, Athan Reines)_ - [`659f752`](https://github.com/stdlib-js/stdlib/commit/659f752db18317bf5fc237fdbcad0d74b61e1ed9) - **style:** add missing spaces _(by Philipp Burckhardt)_ - [`a78f7d1`](https://github.com/stdlib-js/stdlib/commit/a78f7d1b859b6b1d7b0bc0ee4daf76789e3e0910) - **style:** add missing spaces _(by Philipp Burckhardt)_ - [`4708d70`](https://github.com/stdlib-js/stdlib/commit/4708d704db87214af36a82e77072e3aade8c29fd) - **docs:** update namespace table of contents [(#2532)](2532) _(by stdlib-bot, Philipp Burckhardt)_ diff --git a/bool/README.md b/bool/README.md index c217ea86..6ad6b03c 100644 --- a/bool/README.md +++ b/bool/README.md @@ -680,6 +680,36 @@ var idx = arr.indexOf( false ); // returns -1 ``` + + +#### BooleanArray.prototype.join( \[separator] ) + +Returns a new string by concatenating all array elements. + +```javascript +var arr = new BooleanArray( 3 ); + +arr.set( true, 0 ); +arr.set( false, 1 ); +arr.set( true, 2 ); + +var str = arr.join(); +// returns 'true,false,true' +``` + +By default, the method separates serialized array elements with a comma. To use an alternative separator, provide a `separator` string. + +```javascript +var arr = new BooleanArray( 3 ); + +arr.set( true, 0 ); +arr.set( false, 1 ); +arr.set( true, 2 ); + +var str = arr.join( '|' ); +// returns 'true|false|true' +``` + #### BooleanArray.prototype.lastIndexOf( searchElement\[, fromIndex] ) @@ -829,7 +859,7 @@ var out = arr.reduce( reducer, 0 ); -#### Complex64Array.prototype.reduceRight( reducerFn\[, initialValue] ) +#### BooleanArray.prototype.reduceRight( reducerFn\[, initialValue] ) Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. @@ -1290,6 +1320,23 @@ The function should return a number where: - a positive value indicates that `a` should come after `b`. - zero or `NaN` indicates that `a` and `b` are considered equal. + + +#### BooleanArray.prototype.toString() + +Serializes an array as a string. + +```javascript +var arr = new BooleanArray( 3 ); + +arr.set( true, 0 ); +arr.set( false, 1 ); +arr.set( true, 2 ); + +var str = arr.toString(); +// returns 'true,false,true' +``` +
diff --git a/bool/benchmark/benchmark.join.js b/bool/benchmark/benchmark.join.js new file mode 100644 index 00000000..d96ca36a --- /dev/null +++ b/bool/benchmark/benchmark.join.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 bench = require( '@stdlib/bench' ); +var pkg = require( './../package.json' ).name; +var BooleanArray = require( './../lib' ); + + +// MAIN // + +bench( pkg+':join', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new BooleanArray( [ true, false, false, true ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.join(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/bool/benchmark/benchmark.join.length.js b/bool/benchmark/benchmark.join.length.js new file mode 100644 index 00000000..51581532 --- /dev/null +++ b/bool/benchmark/benchmark.join.length.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Boolean = require( '@stdlib/boolean/ctor' ); +var pkg = require( './../package.json' ).name; +var BooleanArray = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr; + var i; + + arr = []; + for ( i = 0; i < len; i++ ) { + arr.push( Boolean( i%2 ) ); + } + arr = new BooleanArray( arr ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.join( '/' ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':join:len='+len, f ); + } +} + +main(); diff --git a/bool/benchmark/benchmark.to_string.js b/bool/benchmark/benchmark.to_string.js new file mode 100644 index 00000000..d549731f --- /dev/null +++ b/bool/benchmark/benchmark.to_string.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 bench = require( '@stdlib/bench' ); +var pkg = require( './../package.json' ).name; +var BooleanArray = require( './../lib' ); + + +// MAIN // + +bench( pkg+':toString', function benchmark( b ) { + var out; + var arr; + var i; + + arr = new BooleanArray( [ true, false, false, true ] ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/bool/benchmark/benchmark.to_string.length.js b/bool/benchmark/benchmark.to_string.length.js new file mode 100644 index 00000000..36834b58 --- /dev/null +++ b/bool/benchmark/benchmark.to_string.length.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Boolean = require( '@stdlib/boolean/ctor' ); +var pkg = require( './../package.json' ).name; +var BooleanArray = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr; + var i; + + arr = []; + for ( i = 0; i < len; i++ ) { + arr.push( Boolean( i%2 ) ); + } + arr = new BooleanArray( arr ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.toString(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':toString:len='+len, f ); + } +} + +main(); diff --git a/bool/docs/repl.txt b/bool/docs/repl.txt index 661490b5..dd3bc26c 100644 --- a/bool/docs/repl.txt +++ b/bool/docs/repl.txt @@ -542,6 +542,30 @@ -1 +{{alias}}.prototype.join( [separator] ) + Returns a new string by concatenating all array elements separated by a + separator string. + + Parameters + ---------- + separator: string (optional) + Separator string. Default: ','. + + Returns + ------- + out: string + Array serialized as a string. + + Examples + -------- + > var arr = new {{alias}}( [ true, false, true ] ) + + > var str = arr.join() + 'true,false,true' + > str = arr.join( '|' ) + 'true|false|true' + + {{alias}}.prototype.lastIndexOf( searchElement[, fromIndex] ) Returns the last index at which a given element can be found. @@ -943,5 +967,21 @@ false +{{alias}}.prototype.toString() + Serializes an array as a string. + + Returns + ------- + out: string + String serialization of the array. + + Examples + -------- + > var arr = new {{alias}}( [ true, false, true ] ) + + > var str = arr.toString() + 'true,false,true' + + See Also -------- diff --git a/bool/docs/types/index.d.ts b/bool/docs/types/index.d.ts index bb3dc550..4a00df95 100644 --- a/bool/docs/types/index.d.ts +++ b/bool/docs/types/index.d.ts @@ -511,6 +511,27 @@ declare class BooleanArray implements BooleanArrayInterface { */ indexOf( searchElement: boolean, fromIndex?: number ): number; + /** + * Returns a new string by concatenating all array elements. + * + * @param separator - value separator (default: ',') + * @returns string + * + * @example + * var arr = new BooleanArray( 3 ); + * + * arr.set( true, 0 ); + * arr.set( false, 1 ); + * arr.set( true, 2 ); + * + * var str = arr.join(); + * // returns 'true,false,true' + * + * str = arr.join( '|' ); + * // returns 'true|false|true' + */ + join( separator?: string ): string; + /** * Returns the last index at which a given element can be found. * @@ -904,6 +925,23 @@ declare class BooleanArray implements BooleanArrayInterface { * // returns false */ toSorted( compareFcn: CompareFcn ): BooleanArray; + + /** + * Serializes an array as a string. + * + * @returns string + * + * @example + * var arr = new BooleanArray( 3 ); + * + * arr.set( true, 0 ); + * arr.set( false, 1 ); + * arr.set( true, 2 ); + * + * var str = arr.toString(); + * // returns 'true,false,true' + */ + toString(): string; } /** diff --git a/bool/lib/main.js b/bool/lib/main.js index 0c2a71a9..acaba18d 100644 --- a/bool/lib/main.js +++ b/bool/lib/main.js @@ -29,6 +29,7 @@ var isObject = require( '@stdlib/assert/is-object' ); var isFunction = require( '@stdlib/assert/is-function' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var hasIteratorSymbolSupport = require( '@stdlib/assert/has-iterator-symbol-support' ); var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' ); var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); @@ -843,6 +844,57 @@ setReadOnly( BooleanArray.prototype, 'indexOf', function indexOf( searchElement, return -1; }); +/** +* Returns a new string by concatenating all array elements. +* +* @name join +* @memberof BooleanArray.prototype +* @type {Function} +* @param {string} [separator=','] - element separator +* @throws {TypeError} `this` must be a boolean array +* @throws {TypeError} first argument must be a string +* @returns {string} string representation +* +* @example +* var arr = new BooleanArray( 3 ); +* +* arr.set( true, 0 ); +* arr.set( false, 1 ); +* arr.set( true, 2 ); +* +* var str = arr.join(); +* // returns 'true,false,true' +* +* str = arr.join( '|' ); +* // returns 'true|false|true' +*/ +setReadOnly( BooleanArray.prototype, 'join', function join( separator ) { + var buf; + var out; + var i; + + if ( !isBooleanArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); + } + if ( arguments.length > 0 ) { + if ( !isString( separator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', separator ) ); + } + } else { + separator = ','; + } + buf = this._buffer; + out = []; + for ( i = 0; i < this._length; i++ ) { + if ( buf[i] ) { + out.push( 'true' ); + } else { + out.push( 'false' ); + } + } + return out.join( separator ); +}); + /** * Returns the last index at which a given element can be found. * @@ -1696,6 +1748,44 @@ setReadOnly( BooleanArray.prototype, 'toSorted', function toSorted( compareFcn ) } }); +/** +* Serializes an array as a string. +* +* @name toString +* @memberof BooleanArray.prototype +* @type {Function} +* @throws {TypeError} `this` must be a boolean array +* @returns {string} string representation +* +* @example +* var arr = new BooleanArray( 3 ); +* +* arr.set( true, 0 ); +* arr.set( false, 1 ); +* arr.set( true, 2 ); +* +* var str = arr.toString(); +* // returns 'true,false,true' +*/ +setReadOnly( BooleanArray.prototype, 'toString', function toString() { + var out; + var buf; + var i; + if ( !isBooleanArray( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a boolean array.' ); + } + out = []; + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + if ( buf[i] ) { + out.push( 'true' ); + } else { + out.push( 'false' ); + } + } + return out.join( ',' ); +}); + // EXPORTS // diff --git a/bool/test/test.join.js b/bool/test/test.join.js new file mode 100644 index 00000000..096cf8c0 --- /dev/null +++ b/bool/test/test.join.js @@ -0,0 +1,162 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var BooleanArray = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof BooleanArray, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `join` method', function test( t ) { + t.strictEqual( hasOwnProp( BooleanArray.prototype, 'join' ), true, 'has property' ); + t.strictEqual( isFunction( BooleanArray.prototype.join ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a boolean array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new BooleanArray( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.join.call( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with a `separator` argument which is not a string', function test( t ) { + var values; + var arr; + var i; + + arr = new BooleanArray( 5 ); + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.join( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new BooleanArray(); + str = arr.join(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a boolean array with elements separated by a separator', function test( t ) { + var expected; + var str; + var arr; + + arr = new BooleanArray( [ true, false, false, true ] ); + expected = 'true@false@false@true'; + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a boolean array with elements separated by a separator (single element)', function test( t ) { + var expected; + var str; + var arr; + + arr = new BooleanArray( [ true ] ); + expected = 'true'; + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + + arr = new BooleanArray( [ false ] ); + expected = 'false'; + + str = arr.join( '@' ); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if the method is invoked without a separator argument, the method returns a string representation of a boolean array with elements separated by a comma', function test( t ) { + var expected; + var str; + var arr; + + arr = new BooleanArray( [ true, false, false, true ] ); + expected = 'true,false,false,true'; + + str = arr.join(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +}); diff --git a/bool/test/test.to_string.js b/bool/test/test.to_string.js new file mode 100644 index 00000000..cdfc074e --- /dev/null +++ b/bool/test/test.to_string.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var BooleanArray = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof BooleanArray, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toString` method', function test( t ) { + t.strictEqual( hasOwnProp( BooleanArray.prototype, 'toString' ), true, 'has property' ); + t.strictEqual( isFunction( BooleanArray.prototype.toString ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a boolean array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new BooleanArray( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.toString.call( value ); + }; + } +}); + +tape( 'the method returns an empty string if invoked on an empty array', function test( t ) { + var str; + var arr; + + arr = new BooleanArray(); + str = arr.toString(); + + t.strictEqual( str, '', 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns a string representation of a boolean array', function test( t ) { + var expected; + var str; + var arr; + + arr = new BooleanArray( [ true, false, false, true ] ); + expected = 'true,false,false,true'; + + str = arr.toString(); + + t.strictEqual( str, expected, 'returns expected value' ); + t.end(); +});