Skip to content

Commit

Permalink
feat: add assert/is-same-booleanarray
Browse files Browse the repository at this point in the history
PR-URL: #2401
Ref: #2304
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Signed-off-by: Athan Reines <[email protected]>
  • Loading branch information
Jaysukh-409 and kgryte authored Jun 21, 2024
1 parent 4d54abb commit a5c9e56
Show file tree
Hide file tree
Showing 10 changed files with 657 additions and 0 deletions.
102 changes: 102 additions & 0 deletions lib/node_modules/@stdlib/assert/is-same-booleanarray/README.md
Original file line number Diff line number Diff line change
@@ -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.
-->

# isSameBooleanArray

> Test if two arguments are both [BooleanArrays][@stdlib/array/bool] and have the [same values][@stdlib/assert/is-same-value].
<section class="usage">

## Usage

```javascript
var isSameBooleanArray = require( '@stdlib/assert/is-same-booleanarray' );
```

#### isSameBooleanArray( v1, v2 )

Tests if two arguments are both [BooleanArrays][@stdlib/array/bool] and have the [same values][@stdlib/assert/is-same-value].

```javascript
var BooleanArray = require( '@stdlib/array/bool' );

var x = new BooleanArray( [ true, false ] );
var y = new BooleanArray( [ true, false ] );
var bool = isSameBooleanArray( x, y );
// returns true

bool = isSameBooleanArray( x, [ true, false ] );
// returns false
```

</section>

<!-- /.usage -->

<section class="notes">

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var BooleanArray = require( '@stdlib/array/bool' );
var isSameBooleanArray = require( '@stdlib/assert/is-same-booleanarray' );

var x = new BooleanArray( [ true, false, false, true ] );
var y = new BooleanArray( [ true, false, false, true ] );
var out = isSameBooleanArray( x, y );
// returns true

x = new BooleanArray( [ true, false, false, true ] );
y = new BooleanArray( [ true, true, false, false ] );
out = isSameBooleanArray( x, y );
// returns false
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/array/bool]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/bool

[@stdlib/assert/is-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-same-value

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pow = require( '@stdlib/math/base/special/pow' );
var Boolean = require( '@stdlib/boolean/ctor' );
var BooleanArray = require( '@stdlib/array/bool' );
var pkg = require( './../package.json' ).name;
var isSameBooleanArray = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
x.push( Boolean( i%2 ) );
}
x = new BooleanArray( x );
y = new BooleanArray( x );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var bool;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isSameBooleanArray( x, y );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
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();
32 changes: 32 additions & 0 deletions lib/node_modules/@stdlib/assert/is-same-booleanarray/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

{{alias}}( v1, v2 )
Tests if two arguments are both BooleanArrays and have the same values.

Parameters
----------
v1: any
First input value.

v2: any
Second input value.

Returns
-------
bool: boolean
Boolean indicating whether two arguments are the same.

Examples
--------
> var x = new {{alias:@stdlib/array/bool}}( [ true, false, false, true ] );
> var y = new {{alias:@stdlib/array/bool}}( [ true, false, false, true ] );
> var bool = {{alias}}( x, y )
true

> x = new {{alias:@stdlib/array/bool}}( [ true, false, false, true ] );
> y = new {{alias:@stdlib/array/bool}}( [ true, true, false, false ] );
> bool = {{alias}}( x, y )
false

See Also
--------

Original file line number Diff line number Diff line change
@@ -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.
*/

// TypeScript Version: 4.1

/**
* Tests if two arguments are both BooleanArrays and have the same values.
*
* @param v1 - first input value
* @param v2 - second input value
* @returns boolean indicating whether two arguments are the same
*
* @example
* var BooleanArray = require( '@stdlib/array/bool' );
*
* var x = new BooleanArray( [ true, false, false, true ] );
* var y = new BooleanArray( [ true, false, false, true ] );
*
* var out = isSameBooleanArray( x, y );
* // returns true
*
* @example
* var BooleanArray = require( '@stdlib/array/bool' );
*
* var x = new BooleanArray( [ true, false, false, true ] );
* var y = new BooleanArray( [ true, true, false, false ] );
*
* var out = isSameBooleanArray( x, y );
* // returns false
*/
declare function isSameBooleanArray( v1: any, v2: any ): boolean;

Check warning on line 46 in lib/node_modules/@stdlib/assert/is-same-booleanarray/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

Check warning on line 46 in lib/node_modules/@stdlib/assert/is-same-booleanarray/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type


// EXPORTS //

export = isSameBooleanArray;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* @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 isSameBooleanArray = require( './index' );


// TESTS //

// The function returns a boolean...
{
isSameBooleanArray( true, true ); // $ExpectType boolean
isSameBooleanArray( null, null ); // $ExpectType boolean
isSameBooleanArray( 'beep', 'boop' ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isSameBooleanArray(); // $ExpectError
isSameBooleanArray( 3.14 ); // $ExpectError
isSameBooleanArray( 'beep', 'beep', 3.14 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @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 BooleanArray = require( '@stdlib/array/bool' );
var isSameBooleanArray = require( './../lib' );

var x = new BooleanArray( [ true, false, false, true ] );
var y = new BooleanArray( [ true, false, false, true ] );
var out = isSameBooleanArray( x, y );
console.log( out );
// => true

x = new BooleanArray( [ true, false, false, true ] );
y = new BooleanArray( [ true, true, false, false ] );
out = isSameBooleanArray( x, y );
console.log( out );
// => false
Loading

1 comment on commit a5c9e56

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
assert/is-same-booleanarray $\color{green}118/118$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}118/118$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.