Skip to content

Commit 09fb1d1

Browse files
committed
Add remaining test files in array/float32
1 parent a04c190 commit 09fb1d1

32 files changed

Lines changed: 4801 additions & 0 deletions
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 hasProp = require( '@stdlib/assert/has-property' );
25+
var isFunction = require( '@stdlib/assert/is-function' );
26+
var Float32Array = require( './../lib' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof Float32Array, 'function', 'main export is a function' );
34+
t.end();
35+
});
36+
37+
tape( 'a typed array instance has an `at` method for returning an array element', function test( t ) {
38+
var arr = new Float32Array( 2 );
39+
t.strictEqual( hasProp( arr, 'at' ), true, 'has property' );
40+
t.strictEqual( isFunction( arr.at ), true, 'has method' );
41+
t.end();
42+
});
43+
44+
tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance', function test( t ) {
45+
var values;
46+
var arr;
47+
var i;
48+
49+
arr = new Float32Array( 5 );
50+
51+
values = [
52+
'5',
53+
5,
54+
NaN,
55+
true,
56+
false,
57+
null,
58+
void 0,
59+
{},
60+
[],
61+
function noop() {}
62+
];
63+
for ( i = 0; i < values.length; i++ ) {
64+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
65+
}
66+
t.end();
67+
68+
function badValue( value ) {
69+
return function badValue() {
70+
return arr.at.call( value, 0 );
71+
};
72+
}
73+
});
74+
75+
tape( 'the method returns `undefined` if provided an index which exceeds array dimensions', function test( t ) {
76+
var arr;
77+
var v;
78+
var i;
79+
80+
arr = new Float32Array( 10 );
81+
for ( i = -arr.length; i < arr.length; i++ ) {
82+
if ( i < 0 ) {
83+
v = arr.at( i - arr.length );
84+
t.strictEqual( v, void 0, 'returns expected value for index '+(i-arr.length) );
85+
} else {
86+
v = arr.at( arr.length + i );
87+
t.strictEqual( v, void 0, 'returns expected value for index '+(arr.length+i) );
88+
}
89+
}
90+
t.end();
91+
});
92+
93+
tape( 'the method returns an array element', function test( t ) {
94+
var arr;
95+
var v;
96+
var i;
97+
98+
arr = new Float32Array( 10 );
99+
for ( i = 0; i < arr.length; i++ ) {
100+
arr[ i ] = i * 2.0;
101+
}
102+
103+
for ( i = -arr.length; i < arr.length; i++ ) {
104+
v = arr.at( i );
105+
if ( i < 0 ) {
106+
t.strictEqual( v, ( arr.length + i ) * 2.0, 'returns expected value for index '+i );
107+
} else {
108+
t.strictEqual( v, i * 2.0, 'returns expected value for index '+i );
109+
}
110+
}
111+
t.end();
112+
});
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 hasProp = require( '@stdlib/assert/has-property' );
25+
var isFunction = require( '@stdlib/assert/is-function' );
26+
var isArray = require( '@stdlib/assert/is-array' );
27+
var Float32Array = require( './../lib' );
28+
29+
30+
// TESTS //
31+
32+
tape( 'main export is a function', function test( t ) {
33+
t.ok( true, __filename );
34+
t.strictEqual( typeof Float32Array, 'function', 'main export is a function' );
35+
t.end();
36+
});
37+
38+
tape( 'a typed array instance has an `entries` method for returning an iterator for iterating over array key-value pairs', function test( t ) {
39+
var arr = new Float32Array( 2 );
40+
t.strictEqual( hasProp( arr, 'entries' ), true, 'has property' );
41+
t.strictEqual( isFunction( arr.entries ), true, 'has method' );
42+
t.end();
43+
});
44+
45+
tape( 'the method throws an error if invoked with a `this` context which is not a typed array instance', function test( t ) {
46+
var values;
47+
var arr;
48+
var i;
49+
50+
arr = new Float32Array( 5 );
51+
52+
values = [
53+
'5',
54+
5,
55+
NaN,
56+
true,
57+
false,
58+
null,
59+
void 0,
60+
{},
61+
[],
62+
function noop() {}
63+
];
64+
for ( i = 0; i < values.length; i++ ) {
65+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
66+
}
67+
t.end();
68+
69+
function badValue( value ) {
70+
return function badValue() {
71+
return arr.entries.call( value );
72+
};
73+
}
74+
});
75+
76+
tape( 'the method returns an iterator protocol-compliant object', function test( t ) {
77+
var arr;
78+
var it;
79+
var v;
80+
var i;
81+
82+
arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
83+
84+
it = arr.entries();
85+
t.strictEqual( typeof it.next, 'function', 'has next method' );
86+
87+
for ( i = 0; i < arr.length; i++ ) {
88+
v = it.next();
89+
t.strictEqual( isArray( v.value ), true, 'returns expected value' );
90+
t.strictEqual( v.value[ 0 ], i, 'returns expected index' );
91+
t.strictEqual( v.value[ 1 ], arr[ i ], 'returns expected value' );
92+
t.strictEqual( typeof v.done, 'boolean', 'returns expected value' );
93+
}
94+
t.end();
95+
});
96+
97+
tape( 'the method returns an iterator which indicates completion once all elements have been iterated', function test( t ) {
98+
var arr;
99+
var it;
100+
var v;
101+
102+
arr = new Float32Array( [ 1.0, 2.0 ] );
103+
it = arr.entries();
104+
105+
v = it.next();
106+
t.strictEqual( v.done, false, 'returns expected value' );
107+
108+
v = it.next();
109+
t.strictEqual( v.done, false, 'returns expected value' );
110+
111+
v = it.next();
112+
t.strictEqual( v.done, true, 'returns expected value' );
113+
t.strictEqual( v.value, void 0, 'returns expected value' );
114+
115+
t.end();
116+
});

0 commit comments

Comments
 (0)