diff --git a/lib/node_modules/@stdlib/array/base/cusome/README.md b/lib/node_modules/@stdlib/array/base/cusome/README.md new file mode 100644 index 000000000000..cbc394963f44 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/README.md @@ -0,0 +1,114 @@ + + +# cusome + +> Cumulatively test whether at least `n` array elements in a provided array are truthy. + +
+ +## Usage + +```javascript +var cusome = require( '@stdlib/array/base/cusome' ); +``` + +#### cusome( x, n ) + +Cumulatively tests whether at least `n` array elements in a provided array are truthy. + +```javascript +var x = [ false, false, false, true, true ]; + +var y = cusome( x, 2 ); +// returns [ false, false, false, false, true ]; +``` + +#### cusome.assign( x, n, y, stride, offset ) + +Cumulatively tests whether at least `n` array elements in a provided array are truthy and assigns results to a provided output array. + +```javascript +var x = [ false, false, false, true, true ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cusome.assign( x, 2, y, 2, 0 ); +// returns [ false, null, false, null, false, null, false, null, true, null ] + +var bool = ( out === y ); +// returns true +``` + +The function supports the following parameters: + +- **x**: input array. +- **n**: number of elements. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cusome = require( '@stdlib/array/base/cusome' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.3 ); +console.log( x ); + +// Cumulatively test whether at least two array elements are truthy: +var out = cusome( x, 2 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.assign.length.js new file mode 100644 index 000000000000..e0e43ff4e77e --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.assign.length.js @@ -0,0 +1,98 @@ +/** +* @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 isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cusome = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var v; + var i; + + y = filled( true, len ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cusome.assign( x, 2, y, 1, 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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+':assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.js new file mode 100644 index 000000000000..416e480616df --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.js @@ -0,0 +1,51 @@ +/** +* @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 isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var cusome = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var i; + var v; + + x = [ false, false, true, false, false ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cusome( x, 2 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.length.js new file mode 100644 index 000000000000..557079bf781e --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/benchmark/benchmark.length.js @@ -0,0 +1,95 @@ +/** +* @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 isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cusome = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cusome( x, 2 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cusome/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cusome/docs/repl.txt new file mode 100644 index 000000000000..417ea0e2ec4a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/docs/repl.txt @@ -0,0 +1,61 @@ + +{{alias}}( x, n ) + Cumulatively tests whether at least `n` array elements in a provided array + are truthy. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + n: integer + Number of elements. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > var x = [ false, false, false, true, true ]; + > var y = {{alias}}( x, 2 ) + [ false, false, false, false, true ]; + + +{{alias}}.assign( x, n, y, stride, offset ) + Cumulatively tests whether at least `n` array elements in a provided array + are truthy and assigns results to provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + n: integer + Number of elements. + + y: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + Returns + ------- + y: ArrayLikeObject + Output array. + + Examples + -------- + > var x = [ false, false, false, true, true ]; + > var y = [ false, null, false, null, false, null, true, null, false ]; + > var result = {{alias}}.assign( x, 2, y, 2, 0 ) + [ false, null, false, null, false, null, false, null, true ]; + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/cusome/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cusome/docs/types/index.d.ts new file mode 100644 index 000000000000..8051d0036391 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/docs/types/index.d.ts @@ -0,0 +1,89 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Interface describing `cusome`. +*/ +interface cusome { + /** + * Cumulatively tests whether at least `n` array elements in a provided array are truthy. + * + * @param x - input array + * @param n - number of elements + * @returns output array + * + * @example + * var x = [ false, false, false, true, true ]; + * + * var y = cusome( x, 2 ); + * // returns [ false, false, false, false, true ]; + */ + ( x: Collection | AccessorArrayLike, n: number ): Array; + + /** + * Cumulatively tests whether at least `n` array elements in a provided array are truthy and assigns the results to a provided output array. + * + * @param x - input array + * @param n - number of elements + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @returns output array + * + * @example + * var x = [ false, false, false, true, true ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cusome.assign( x, 2, y, 2, 0 );, + * // returns [ false, null, false, null, false, null, false, null, true, null ]; + */ + assign | AccessorArrayLike>( x: Collection | AccessorArrayLike, n: number, y: U, stride: number, offset: number ): U; +} + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @param x - input array +* @param n - number of elements +* @returns output array +* +* @example +* var x = [ false, false, false, true, true ]; +* +* var result = cusome( x, 2 ); +* // returns [ false, false, false, false, true ]; +* +* @example +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cusome.assign( x, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ]; +*/ +declare var cusome: cusome; + + +// EXPORTS // + +export = cusome; diff --git a/lib/node_modules/@stdlib/array/base/cusome/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cusome/docs/types/test.ts new file mode 100644 index 000000000000..45d3da570652 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/docs/types/test.ts @@ -0,0 +1,137 @@ +/* +* @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. +*/ + + +import cusome = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + cusome( [false, false, true, false, false], 2 ); // $ExpectType boolean[] + cusome( [ false, false, true, false, false ], 1 ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + cusome( 1, 2 ); // $ExpectError + cusome( true, 2 ); // $ExpectError + cusome( false, 2 ); // $ExpectError + cusome( null, 2 ); // $ExpectError + cusome( void 0, 2 ); // $ExpectError + cusome( {}, 2 ); // $ExpectError + cusome( undefined, 2 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + cusome( [ true, false, true ], true ); // $ExpectError + cusome( [ true, false, true ], false ); // $ExpectError + cusome( [ true, false, true ], null ); // $ExpectError + cusome( [ true, false, true ], [] ); // $ExpectError + cusome( [ true, false, true ], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cusome(); // $ExpectError + cusome( [] ); // $ExpectError + cusome( [], [], [] ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cusome.assign( x, 2, y, 2, 0 ); // $ExpectType (boolean | null)[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... +{ + const y = [ false, false, true, false, false ]; + + cusome.assign( 1, 2, y, 2, 0 ); // $ExpectError + cusome.assign( true, 2, y, 2, 0 ); // $ExpectError + cusome.assign( false, 2, y, 2, 0 ); // $ExpectError + cusome.assign( null, 2, y, 2, 0 ); // $ExpectError + cusome.assign( void 0, 2, y, 2, 0 ); // $ExpectError + cusome.assign( {}, 2, y, 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an number... +{ + const x = [ false, false, true, false, false ]; + const y = [false, false, true, false, false]; + + cusome.assign( x, undefined, y, 2, 0 ); // $ExpectError + cusome.assign( x, true, y, 2, 0 ); // $ExpectError + cusome.assign( x, false, y, 2, 0 ); // $ExpectError + cusome.assign( x, null, y, 2, 0 ); // $ExpectError + cusome.assign( x, void 0, y, 2, 0 ); // $ExpectError + cusome.assign( x, {}, y, 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an array-like object... +{ + const x = [ false, false, true, false, false ]; + + cusome.assign( x, 2, true, 2, 0 ); // $ExpectError + cusome.assign( x, 2, false, 2, 0 ); // $ExpectError + cusome.assign( x, 2, null, 2, 0 ); // $ExpectError + cusome.assign( x, 2, void 0, 2, 0 ); // $ExpectError + cusome.assign( x, 2, {}, 2, 0 ); // $ExpectError + cusome.assign( x, 2, undefined, 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cusome.assign( x, 2, y, true, 2 ); // $ExpectError + cusome.assign( x, 2, y, false, 2 ); // $ExpectError + cusome.assign( x, 2, y, null, 2 ); // $ExpectError + cusome.assign( x, 2, y, void 0, 2 ); // $ExpectError + cusome.assign( x, 2, y, {}, 2 ); // $ExpectError + cusome.assign( x, 2, y, undefined, 2 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cusome.assign( x, 2, y, 1, '1' ); // $ExpectError + cusome.assign( x, 1, y, 1, true ); // $ExpectError + cusome.assign( x, 2, y, 1, false ); // $ExpectError + cusome.assign( x, 1, y, 1, null ); // $ExpectError + cusome.assign( x, 2, y, 1, void 0 ); // $ExpectError + cusome.assign( x, 1, y, 1, {} ); // $ExpectError + cusome.assign( x, 2, y, 1, [] ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cusome.assign(); // $ExpectError + cusome.assign( [] ); // $ExpectError + cusome.assign( [], [] ); // $ExpectError + cusome.assign( [], [], 2 ); // $ExpectError + cusome.assign( [], [], 1, 1, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cusome/examples/index.js b/lib/node_modules/@stdlib/array/base/cusome/examples/index.js new file mode 100644 index 000000000000..50680580d529 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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'; + +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cusome = require( './../lib' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.3 ); +console.log( x ); + +// Cumulatively test whether at least two array elements are truthy: +var out = cusome( x, 2 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/array/base/cusome/lib/assign.js b/lib/node_modules/@stdlib/array/base/cusome/lib/assign.js new file mode 100644 index 000000000000..c58f1a379741 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/lib/assign.js @@ -0,0 +1,309 @@ +/** +* @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 isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' ); +var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' ); +var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); + + +// FUNCTIONS // + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @private +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @param {Collection} y - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var out = indexed( x, 2, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +*/ +function indexed( x, n, y, stride, offset ) { + var flg; + var io; + var i; + + flg = false; + io = offset; + for ( i = 0; i < x.length; i++ ) { + if ( !flg && x[ i ] ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + y[ io ] = flg; + io += stride; + } + return y; +} + +/** +* Cumulatively tests whether at least `n` array elements in accessor array are truthy. +* +* @private +* @param {Object} x - input array object +* @param {integer} n - number of elements +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ false, false, false, true, true ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, true, null ] ); +* +* var arr = accessors( arraylike2object( x ), 2, arraylike2object( y ), 2, 0 ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns false +* +* v = y.get( 8 ); +* // returns true +*/ +function accessors( x, n, y, stride, offset ) { + var xdata; + var ydata; + var xget; + var yset; + var flg; + var io; + var i; + + xdata = x.data; + ydata = y.data; + + xget = x.accessors[ 0 ]; + yset = y.accessors[ 1 ]; + + flg = false; + io = offset; + for ( i = 0; i < xdata.length; i++ ) { + if ( !flg && xget( xdata, i ) ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + +/** +* Cumulatively tests whether at least `n` array elements in a provided complex number are truthy and assigns results to provided output array. +* +* @private +* @param {Collection} x - array containing interleaved real and imaginary components +* @param {integer} n - number of elements +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); +* +* var arr = complex( x, 2, arraylike2object( y ), 2, 0 ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns false +* +* v = y.get( 8 ); +* // returns false +*/ +function complex( x, n, y, stride, offset ) { + var ydata; + var yset; + var flg; + var io; + var i; + + yset = y.accessors[ 1 ]; + ydata = y.data; + + flg = false; + io = offset; + for ( i = 0; i < x.length; i += 2 ) { + if ( !flg && ( x[ i ] || x[ i+1 ] ) ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @private +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @param {Object} y - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = new Uint8Array( [ 0, 0, 0, 1, 0 ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); +* +* var arr = boolean( x, 2, arraylike2object( y ), 2, 0 ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns false +* +* v = y.get( 8 ); +* // returns false +*/ +function boolean( x, n, y, stride, offset ) { + var ydata; + var yset; + var flg; + var io; + var i; + + yset = y.accessors[ 1 ]; + ydata = y.data; + + flg = false; + io = offset; + for ( i = 0; i < x.length; i++ ) { + if ( !flg && x[ i ] ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + + +// MAIN // + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy and assigns results to provided output array. +* +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @param {Collection} y - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var out = assign( x, 2, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +* +* var bool = ( y === out ); +* // returns true +*/ +function assign( x, n, y, stride, offset ) { + var xo = arraylike2object( x ); + var yo = arraylike2object( y ); + if ( + xo.accessorProtocol || + yo.accessorProtocol + ) { + // If provided a complex number array, reinterpret as a real typed array and test interleaved real and imaginary components, where we consider a complex number to be truthy if at least one component is non-zero... + if ( isComplex128Array( x ) ) { + return complex( reinterpret128( x, 0 ), n, yo, stride, offset ); + } + if ( isComplex64Array( x ) ) { + return complex( reinterpret64( x, 0 ), n, yo, stride, offset ); + } + if ( isBooleanArray( x ) ) { + return boolean( reinterpretBoolean( x, 0 ), n, yo, stride, offset ); + } + return accessors( xo, n, yo, stride, offset ); + } + indexed( x, n, y, stride, offset ); + return y; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cusome/lib/index.js b/lib/node_modules/@stdlib/array/base/cusome/lib/index.js new file mode 100644 index 000000000000..43203f529281 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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'; + +/** +* Cumulatively test whether at least `n` array elements in a provided array are truthy. +* +* @module @stdlib/array/base/cusome +* +* @example +* var cusome = require( '@stdlib/array/base/cusome' ); +* +* var x = [ false, false, false, true, true ]; +* +* var y = cusome( x, 2 ); +* // returns [ false, false, false, false, true ] +* +* @example +* var cusome = require( '@stdlib/array/base/cusome' ); +* +* var x = [ false, false, false, true, true ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cusome.assign( x, 2, y, 2, 0 ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/cusome/lib/main.js b/lib/node_modules/@stdlib/array/base/cusome/lib/main.js new file mode 100644 index 000000000000..4ba62ce44613 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/lib/main.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 filled = require( '@stdlib/array/base/filled' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least `n` array elements in a provided array are truthy. +* +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @returns {Array} output array +* +* @example +* var x = [ false, false, false, true, true ]; +* +* var y = cusome( x, 2 ); +* // returns [ false, false, false, false, true ] +*/ +function cusome( x, n ) { + var y = filled( true, x.length ); + return assign( x, n, y, 1, 0 ); +} + + +// EXPORTS // + +module.exports = cusome; diff --git a/lib/node_modules/@stdlib/array/base/cusome/package.json b/lib/node_modules/@stdlib/array/base/cusome/package.json new file mode 100644 index 000000000000..69a917f90732 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/cusome", + "version": "0.0.0", + "description": "Cumulatively test whether at least `n` array elements in a provided array are truthy.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "utils", + "generic", + "array", + "cusome", + "cumulative", + "test", + "every", + "array.every", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cusome/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cusome/test/test.assign.js new file mode 100644 index 000000000000..367e35861c3d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/test/test.assign.js @@ -0,0 +1,400 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cusome = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (generic)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = [ false, false, false, true, false ]; + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ false, false, false, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false, false, true, false, false ]; + y = [ false, null, false, null, true, null, true, null, true, null ]; + + actual = cusome( x, 1, y, 2, 0 ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false, false, true, false, false ]; + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 2, y, 1, 1 ); + expected = [ false, false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = []; + y = [ false, false, false, false, false ]; + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ false ]; + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (typed)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0 ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (boolean)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new BooleanArray( [ true, true, true, true, true ] ); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, true, false, false ] ); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, true, false, false ] ); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex128)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Complex128Array([ + 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0 + ]); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [ 1.0, 1.0 ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex64)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Complex64Array([ + 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0 + ]); + y = [ false, true, false, true, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + y = [ false, false, false, true, true, true ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array( [ 1.0, 1.0 ] ); + y = [ false, false ]; + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var x; + var y; + + x = toAccessorArray( [ true, false, true, false, true ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, null, false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 2, y, 2, 0 ); + expected = [ + false, null, false, null, false, null, false, null, false, null + ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ true, false, false, false, false ] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 0 ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 2, y, 1, 0 ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ true ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusome( x, 1, y, 1, 1 ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome/test/test.js b/lib/node_modules/@stdlib/array/base/cusome/test/test.js new file mode 100644 index 000000000000..2924a728ba79 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/test/test.js @@ -0,0 +1,41 @@ +/** +* @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 hasMethod = require( '@stdlib/assert/is-method' ); +var cusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cusome, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cusome, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome/test/test.main.js b/lib/node_modules/@stdlib/array/base/cusome/test/test.main.js new file mode 100644 index 000000000000..6e93aa5d4bf4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome/test/test.main.js @@ -0,0 +1,252 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ false, false, false, true, false ]; + actual = cusome( x, 2 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + actual = cusome( x, 1 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, true, true, true, true ]; + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ null, {}, null ]; + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, false, false, true, false ]; + actual = cusome( x, 1); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (typed)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + actual = cusome( x, 1 ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + actual = cusome( x, 1 ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cusome( x, 1); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (boolean)', function test( t ) { + var expected; + var actual; + var x; + + x = new BooleanArray( [ false, false, true, false, false ] ); + actual = cusome( x, 2 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, false, false, false ] ); + actual = cusome( x, 1); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, true, true, true, true ] ); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, true, true ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, false, true, false, false ] ); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex128)', function test( t ) { + var expected; + var actual; + var x; + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 + ]); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [ 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 ] ); + actual = cusome( x, 1); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array([ + 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (complex64)', function test( t ) { + var expected; + var actual; + var x; + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 1 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 + ]); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array( [ 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 ] ); + actual = cusome( x, 1); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Complex64Array([ + 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 + ]); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `n` array elements are truthy (accessor)', function test( t ) { + var expected; + var actual; + var x; + + x = new toAccessorArray( [ false, false, true, false, false ] ); + actual = cusome( x, 2 ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ false, false, false, false, false ] ); + actual = cusome( x, 1); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ true, true, true, true, true ] ); + actual = cusome( x, 2 ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ false, true, true ] ); + actual = cusome( x, 1 ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new toAccessorArray( [ true, false, true, false, false ] ); + actual = cusome( x, 2); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +});