Skip to content

Commit 8d4b82d

Browse files
committed
Add assertion utility to test if a value is a Complex128Array
1 parent e879868 commit 8d4b82d

File tree

8 files changed

+622
-0
lines changed

8 files changed

+622
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2018 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isComplex128Array
22+
23+
> Test if a value is a [Complex128Array][@stdlib/array/complex128].
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isComplex128Array = require( '@stdlib/assert/is-complex128array' );
31+
```
32+
33+
#### isComplex128Array( value )
34+
35+
Tests if a value is a [`Complex128Array`][@stdlib/array/complex128].
36+
37+
```javascript
38+
var Complex128Array = require( '@stdlib/array/complex128' );
39+
40+
var bool = isComplex128Array( new Complex128Array( 10 ) );
41+
// returns true
42+
43+
bool = isComplex128Array( [] );
44+
// returns false
45+
```
46+
47+
</section>
48+
49+
<!-- /.usage -->
50+
51+
<section class="examples">
52+
53+
## Examples
54+
55+
<!-- eslint no-undef: "error" -->
56+
57+
```javascript
58+
var Int8Array = require( '@stdlib/array/int8' );
59+
var Uint8Array = require( '@stdlib/array/uint8' );
60+
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
61+
var Int16Array = require( '@stdlib/array/int16' );
62+
var Uint16Array = require( '@stdlib/array/uint16' );
63+
var Int32Array = require( '@stdlib/array/int32' );
64+
var Uint32Array = require( '@stdlib/array/uint32' );
65+
var Float32Array = require( '@stdlib/array/float32' );
66+
var Float64Array = require( '@stdlib/array/float64' );
67+
var Complex64Array = require( '@stdlib/array/complex64' );
68+
var Complex128Array = require( '@stdlib/array/complex128' );
69+
var isComplex128Array = require( '@stdlib/assert/is-complex128array' );
70+
71+
var bool = isComplex128Array( new Complex128Array( 10 ) );
72+
// returns true
73+
74+
bool = isComplex128Array( new Complex64Array( 10 ) );
75+
// returns false
76+
77+
bool = isComplex128Array( new Float64Array( 10 ) );
78+
// returns false
79+
80+
bool = isComplex128Array( new Int8Array( 10 ) );
81+
// returns false
82+
83+
bool = isComplex128Array( new Uint8Array( 10 ) );
84+
// returns false
85+
86+
bool = isComplex128Array( new Uint8ClampedArray( 10 ) );
87+
// returns false
88+
89+
bool = isComplex128Array( new Int16Array( 10 ) );
90+
// returns false
91+
92+
bool = isComplex128Array( new Uint16Array( 10 ) );
93+
// returns false
94+
95+
bool = isComplex128Array( new Int32Array( 10 ) );
96+
// returns false
97+
98+
bool = isComplex128Array( new Uint32Array( 10 ) );
99+
// returns false
100+
101+
bool = isComplex128Array( new Float32Array( 10 ) );
102+
// returns false
103+
104+
bool = isComplex128Array( new Array( 10 ) );
105+
// returns false
106+
107+
bool = isComplex128Array( {} );
108+
// returns false
109+
110+
bool = isComplex128Array( null );
111+
// returns false
112+
```
113+
114+
</section>
115+
116+
<!-- /.examples -->
117+
118+
<section class="links">
119+
120+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib
121+
122+
</section>
123+
124+
<!-- /.links -->
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var Int8Array = require( '@stdlib/array/int8' );
25+
var Uint8Array = require( '@stdlib/array/uint8' );
26+
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
27+
var Int16Array = require( '@stdlib/array/int16' );
28+
var Uint16Array = require( '@stdlib/array/uint16' );
29+
var Int32Array = require( '@stdlib/array/int32' );
30+
var Uint32Array = require( '@stdlib/array/uint32' );
31+
var Float32Array = require( '@stdlib/array/float32' );
32+
var Float64Array = require( '@stdlib/array/float64' );
33+
var Complex128Array = require( '@stdlib/array/complex128' );
34+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
35+
var pkg = require( './../package.json' ).name;
36+
var isComplex128Array = require( './../lib' );
37+
38+
39+
// MAIN //
40+
41+
bench( pkg, function benchmark( b ) {
42+
var values;
43+
var bool;
44+
var i;
45+
46+
values = [
47+
new Float64Array( 10 ),
48+
new Float32Array( 10 ),
49+
new Int32Array( 10 ),
50+
new Uint32Array( 10 ),
51+
new Int16Array( 10 ),
52+
new Uint16Array( 10 ),
53+
new Int8Array( 10 ),
54+
new Uint8Array( 10 ),
55+
new Uint8ClampedArray( 10 ),
56+
new Complex128Array( 10 )
57+
];
58+
59+
b.tic();
60+
for ( i = 0; i < b.iterations; i++ ) {
61+
bool = isComplex128Array( values[ i%values.length ] );
62+
if ( !isBoolean( bool ) ) {
63+
b.fail( 'should return a boolean' );
64+
}
65+
}
66+
b.toc();
67+
if ( !isBoolean( bool ) ) {
68+
b.fail( 'should return a boolean' );
69+
}
70+
b.pass( 'benchmark finished' );
71+
b.end();
72+
});
73+
74+
bench( pkg+'::true', function benchmark( b ) {
75+
var values;
76+
var bool;
77+
var i;
78+
79+
values = [
80+
new Complex128Array( 10 ),
81+
new Complex128Array( 10 )
82+
];
83+
84+
b.tic();
85+
for ( i = 0; i < b.iterations; i++ ) {
86+
bool = isComplex128Array( values[ i%values.length ] );
87+
if ( !isBoolean( bool ) ) {
88+
b.fail( 'should return a boolean' );
89+
}
90+
}
91+
b.toc();
92+
if ( !isBoolean( bool ) ) {
93+
b.fail( 'should return a boolean' );
94+
}
95+
b.pass( 'benchmark finished' );
96+
b.end();
97+
});
98+
99+
bench( pkg+'::false', function benchmark( b ) {
100+
var values;
101+
var bool;
102+
var i;
103+
104+
values = [
105+
new Float64Array( 10 ),
106+
new Float32Array( 10 ),
107+
new Int32Array( 10 ),
108+
new Uint32Array( 10 ),
109+
new Int16Array( 10 ),
110+
new Uint16Array( 10 ),
111+
new Int8Array( 10 ),
112+
new Uint8Array( 10 ),
113+
new Uint8ClampedArray( 10 )
114+
];
115+
116+
b.tic();
117+
for ( i = 0; i < b.iterations; i++ ) {
118+
bool = isComplex128Array( values[ i%values.length ] );
119+
if ( !isBoolean( bool ) ) {
120+
b.fail( 'should return a boolean' );
121+
}
122+
}
123+
b.toc();
124+
if ( !isBoolean( bool ) ) {
125+
b.fail( 'should return a boolean' );
126+
}
127+
b.pass( 'benchmark finished' );
128+
b.end();
129+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
{{alias}}( value )
3+
Tests if a value is a Complex128Array.
4+
5+
Parameters
6+
----------
7+
value: any
8+
Value to test.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating whether value is a Complex128Array.
14+
15+
Examples
16+
--------
17+
> var bool = {{alias}}( new {{alias:@stdlib/array/complex128}}( 10 ) )
18+
true
19+
> bool = {{alias}}( [] )
20+
false
21+
22+
See Also
23+
--------
24+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var Int8Array = require( '@stdlib/array/int8' );
22+
var Uint8Array = require( '@stdlib/array/uint8' );
23+
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
24+
var Int16Array = require( '@stdlib/array/int16' );
25+
var Uint16Array = require( '@stdlib/array/uint16' );
26+
var Int32Array = require( '@stdlib/array/int32' );
27+
var Uint32Array = require( '@stdlib/array/uint32' );
28+
var Float32Array = require( '@stdlib/array/float32' );
29+
var Float64Array = require( '@stdlib/array/float64' );
30+
var Complex64Array = require( '@stdlib/array/complex64' );
31+
var Complex128Array = require( '@stdlib/array/complex128' );
32+
var isComplex128Array = require( './../lib' );
33+
34+
var bool = isComplex128Array( new Complex128Array( 10 ) );
35+
console.log( bool );
36+
// => true
37+
38+
bool = isComplex128Array( new Complex64Array( 10 ) );
39+
console.log( bool );
40+
// => false
41+
42+
bool = isComplex128Array( new Float64Array( 10 ) );
43+
console.log( bool );
44+
// => false
45+
46+
bool = isComplex128Array( new Int8Array( 10 ) );
47+
console.log( bool );
48+
// => false
49+
50+
bool = isComplex128Array( new Uint8Array( 10 ) );
51+
console.log( bool );
52+
// => false
53+
54+
bool = isComplex128Array( new Uint8ClampedArray( 10 ) );
55+
console.log( bool );
56+
// => false
57+
58+
bool = isComplex128Array( new Int16Array( 10 ) );
59+
console.log( bool );
60+
// => false
61+
62+
bool = isComplex128Array( new Uint16Array( 10 ) );
63+
console.log( bool );
64+
// => false
65+
66+
bool = isComplex128Array( new Int32Array( 10 ) );
67+
console.log( bool );
68+
// => false
69+
70+
bool = isComplex128Array( new Uint32Array( 10 ) );
71+
console.log( bool );
72+
// => false
73+
74+
bool = isComplex128Array( new Float32Array( 10 ) );
75+
console.log( bool );
76+
// => false
77+
78+
bool = isComplex128Array( new Array( 10 ) );
79+
console.log( bool );
80+
// => false
81+
82+
bool = isComplex128Array( {} );
83+
console.log( bool );
84+
// => false
85+
86+
bool = isComplex128Array( null );
87+
console.log( bool );
88+
// => false

0 commit comments

Comments
 (0)