Skip to content

Commit 99e6a6f

Browse files
committed
Add tests
1 parent 96caef8 commit 99e6a6f

File tree

4 files changed

+208
-3
lines changed

4 files changed

+208
-3
lines changed

lib/node_modules/@stdlib/array/complex64/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ Object.defineProperty( Complex64Array.prototype, 'get', {
742742
if ( !isNonNegativeInteger( idx ) ) {
743743
throw new TypeError( 'invalid argument. Index argument must be a nonnegative integer. Value: `'+idx+'`.' );
744744
}
745-
if ( idx < 0 || idx >= this._length ) {
745+
if ( idx >= this._length ) {
746746
return;
747747
}
748748
idx *= 2;

lib/node_modules/@stdlib/array/complex64/test/test.copy_within.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tape( 'main export is a function', function test( t ) {
3838
t.end();
3939
});
4040

41-
tape( 'attached to the main export is a `copyWithin` method for copying a sequence of array elements within a complex number array', function test( t ) {
41+
tape( 'attached to the prototype of the main export is a `copyWithin` method for copying a sequence of array elements within a complex number array', function test( t ) {
4242
t.strictEqual( hasOwnProp( Complex64Array.prototype, 'copyWithin' ), true, 'has property' );
4343
t.strictEqual( isFunction( Complex64Array.prototype.copyWithin ), true, 'has method' );
4444
t.end();

lib/node_modules/@stdlib/array/complex64/test/test.entries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tape( 'main export is a function', function test( t ) {
4040
t.end();
4141
});
4242

43-
tape( 'attached to the main export is an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) {
43+
tape( 'attached to the prototype of the main export is an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) {
4444
t.strictEqual( hasOwnProp( Complex64Array.prototype, 'entries' ), true, 'has property' );
4545
t.strictEqual( isFunction( Complex64Array.prototype.entries ), true, 'has method' );
4646
t.end();
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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 tape = require( 'tape' );
24+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var isFunction = require( '@stdlib/assert/is-function' );
26+
var Complex64 = require( '@stdlib/complex/float32' );
27+
var real = require( '@stdlib/complex/real' );
28+
var imag = require( '@stdlib/complex/imag' );
29+
var Complex64Array = require( './../lib' );
30+
31+
32+
// TESTS //
33+
34+
tape( 'main export is a function', function test( t ) {
35+
t.ok( true, __filename );
36+
t.strictEqual( typeof Complex64Array, 'function', 'main export is a function' );
37+
t.end();
38+
});
39+
40+
tape( 'attached to the prototype of the main export is a `get` method for returning an array element', function test( t ) {
41+
t.strictEqual( hasOwnProp( Complex64Array.prototype, 'get' ), true, 'has property' );
42+
t.strictEqual( isFunction( Complex64Array.prototype.get ), true, 'has method' );
43+
t.end();
44+
});
45+
46+
tape( 'the method throws an error if provided an index argument which is not a nonnegative integer', function test( t ) {
47+
var values;
48+
var arr;
49+
var i;
50+
51+
arr = new Complex64Array( 10 );
52+
53+
values = [
54+
'5',
55+
-5,
56+
3.14,
57+
NaN,
58+
true,
59+
false,
60+
null,
61+
void 0,
62+
{},
63+
[],
64+
function noop() {}
65+
];
66+
for ( i = 0; i < values.length; i++ ) {
67+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
68+
}
69+
t.end();
70+
71+
function badValue( value ) {
72+
return function badValue() {
73+
return arr.get( value );
74+
};
75+
}
76+
});
77+
78+
tape( 'the method throws an error if provided an index argument which is not a nonnegative integer (output argument)', function test( t ) {
79+
var values;
80+
var arr;
81+
var i;
82+
83+
arr = new Complex64Array( 10 );
84+
85+
values = [
86+
'5',
87+
-5,
88+
3.14,
89+
NaN,
90+
true,
91+
false,
92+
null,
93+
void 0,
94+
{},
95+
[],
96+
function noop() {}
97+
];
98+
for ( i = 0; i < values.length; i++ ) {
99+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
100+
}
101+
t.end();
102+
103+
function badValue( value ) {
104+
return function badValue() {
105+
return arr.get( [ 0.0, 0.0 ], value );
106+
};
107+
}
108+
});
109+
110+
tape( 'the method throws an error if provided an output argument which is not an array-like object', function test( t ) {
111+
var values;
112+
var arr;
113+
var i;
114+
115+
arr = new Complex64Array( 10 );
116+
117+
values = [
118+
'5',
119+
5,
120+
NaN,
121+
true,
122+
false,
123+
null,
124+
void 0,
125+
{},
126+
function noop() {}
127+
];
128+
for ( i = 0; i < values.length; i++ ) {
129+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
130+
}
131+
t.end();
132+
133+
function badValue( value ) {
134+
return function badValue() {
135+
return arr.get( value, 0 );
136+
};
137+
}
138+
});
139+
140+
tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) {
141+
var arr;
142+
var v;
143+
var i;
144+
145+
arr = new Complex64Array( 10 );
146+
for ( i = 0; i < arr.length; i++ ) {
147+
v = arr.get( arr.length+i );
148+
t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) );
149+
}
150+
t.end();
151+
});
152+
153+
tape( 'the method returns `undefined` if provided an index which exceeds array dimensions (output argument)', function test( t ) {
154+
var arr;
155+
var v;
156+
var i;
157+
158+
arr = new Complex64Array( 10 );
159+
for ( i = 0; i < arr.length; i++ ) {
160+
v = arr.get( [ 0.0, 0.0 ], arr.length+i );
161+
t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) );
162+
}
163+
t.end();
164+
});
165+
166+
tape( 'the method returns an array element', function test( t ) {
167+
var arr;
168+
var v;
169+
var i;
170+
171+
arr = [];
172+
for ( i = 0; i < 10; i++ ) {
173+
arr.push( new Complex64( i, -i ) );
174+
}
175+
arr = new Complex64Array( arr );
176+
177+
for ( i = 0; i < arr.length; i++ ) {
178+
v = arr.get( i );
179+
t.strictEqual( real( v ), i, 'returns expected real component for index '+i );
180+
t.strictEqual( imag( v ), -i, 'returns expected imaginary component for index '+i );
181+
}
182+
t.end();
183+
});
184+
185+
tape( 'the method returns an array element (output argument)', function test( t ) {
186+
var arr;
187+
var out;
188+
var v;
189+
var i;
190+
191+
arr = [];
192+
for ( i = 0; i < 10; i++ ) {
193+
arr.push( new Complex64( i, -i ) );
194+
}
195+
arr = new Complex64Array( arr );
196+
197+
out = [ 0.0, 0.0 ];
198+
for ( i = 0; i < arr.length; i++ ) {
199+
v = arr.get( out, i );
200+
t.strictEqual( v, out, 'returns expected value for index '+i );
201+
t.strictEqual( v[ 0 ], i, 'returns expected real component for index '+i );
202+
t.strictEqual( v[ 1 ], -i, 'returns expected imaginary component for index '+i );
203+
}
204+
t.end();
205+
});

0 commit comments

Comments
 (0)