Skip to content

Commit a03a65b

Browse files
committed
Update tests
1 parent 8fe582b commit a03a65b

File tree

2 files changed

+278
-23
lines changed

2 files changed

+278
-23
lines changed

lib/node_modules/@stdlib/strided/base/nullary/test/test.main.js

+123-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19+
/* eslint-disable max-len */
20+
1921
'use strict';
2022

2123
// MODULES //
@@ -24,6 +26,9 @@ var tape = require( 'tape' );
2426
var floor = require( '@stdlib/math/base/special/floor' );
2527
var constantFunction = require( '@stdlib/utils/constant-function' );
2628
var Float64Array = require( '@stdlib/array/float64' );
29+
var Float32Array = require( '@stdlib/array/float32' );
30+
var Complex64Array = require( '@stdlib/array/complex64' );
31+
var Complex64 = require( '@stdlib/complex/float32' );
2732
var nullary = require( './../lib/main.js' );
2833

2934

@@ -54,6 +59,22 @@ tape( 'the function applies a nullary callback to each indexed strided array ele
5459
t.end();
5560
});
5661

62+
tape( 'the function applies a nullary callback to each indexed strided array element (accessors)', function test( t ) {
63+
var expected;
64+
var xbuf;
65+
var x;
66+
67+
xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] );
68+
x = new Complex64Array( xbuf.buffer );
69+
70+
nullary( [ x ], [ x.length ], [ 1 ], constantFunction( new Complex64( 1.0, 1.0 ) ) );
71+
72+
expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
73+
74+
t.deepEqual( xbuf, expected, 'deep equal' );
75+
t.end();
76+
});
77+
5778
tape( 'the function supports an `x` stride', function test( t ) {
5879
var expected;
5980
var x;
@@ -71,18 +92,53 @@ tape( 'the function supports an `x` stride', function test( t ) {
7192
nullary( [ x ], [ N ], [ 2 ], constantFunction( 3.0 ) );
7293

7394
expected = new Float64Array([
74-
3.0,
95+
3.0, // 0
7596
-2.0,
76-
3.0,
97+
3.0, // 1
7798
-4.0,
78-
3.0
99+
3.0 // 2
79100
]);
80101

81102
t.deepEqual( x, expected, 'deep equal' );
82103
t.end();
83104
});
84105

85-
tape( 'if provided a shape whose only element is less than or equal to `0`, the function returns `x` unchanged', function test( t ) {
106+
tape( 'the function supports an `x` stride (accessors)', function test( t ) {
107+
var expected;
108+
var xbuf;
109+
var x;
110+
var N;
111+
112+
xbuf = new Float32Array([
113+
-1.0, // 0
114+
-1.0, // 0
115+
-2.0,
116+
-2.0,
117+
-3.0, // 1
118+
-3.0, // 1
119+
-4.0,
120+
-4.0,
121+
-5.0, // 2
122+
-5.0 // 2
123+
]);
124+
x = new Complex64Array( xbuf );
125+
N = 3;
126+
127+
nullary( [ x ], [ N ], [ 2 ], constantFunction( new Complex64( 1.0, 1.0 ) ) );
128+
129+
expected = new Complex64Array([
130+
new Complex64( 1.0, 1.0 ),
131+
new Complex64( -2.0, -2.0 ),
132+
new Complex64( 1.0, 1.0 ),
133+
new Complex64( -4.0, -4.0 ),
134+
new Complex64( 1.0, 1.0 )
135+
]);
136+
137+
t.deepEqual( new Float32Array( x.buffer ), new Float32Array( expected.buffer ), 'deep equal' );
138+
t.end();
139+
});
140+
141+
tape( 'if provided a shape whose only element is less than or equal to `0`, the function returns the destination array unchanged', function test( t ) {
86142
var expected;
87143
var x;
88144

@@ -99,6 +155,25 @@ tape( 'if provided a shape whose only element is less than or equal to `0`, the
99155
t.end();
100156
});
101157

158+
tape( 'if provided a shape whose only element is less than or equal to `0`, the function returns the destination array unchanged (accessors)', function test( t ) {
159+
var expected;
160+
var xbuf;
161+
var x;
162+
163+
xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] );
164+
x = new Complex64Array( xbuf );
165+
166+
expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ] );
167+
168+
nullary( [ x ], [ -1 ], [ 1 ], constantFunction( new Complex64( 1.0, 1.0 ) ) );
169+
t.deepEqual( new Float32Array( x.buffer ), expected, 'returns expected value' );
170+
171+
nullary( [ x ], [ 0 ], [ 1 ], constantFunction( new Complex64( 1.0, 1.0 ) ) );
172+
t.deepEqual( new Float32Array( x.buffer ), expected, 'returns expected value' );
173+
174+
t.end();
175+
});
176+
102177
tape( 'the function supports negative strides', function test( t ) {
103178
var expected;
104179
var x;
@@ -116,17 +191,52 @@ tape( 'the function supports negative strides', function test( t ) {
116191
nullary( [ x ], [ N ], [ -2 ], constantFunction( 3.0 ) );
117192

118193
expected = new Float64Array([
119-
3.0,
194+
3.0, // 2
120195
-2.0,
121-
3.0,
196+
3.0, // 1
122197
-4.0,
123-
3.0
198+
3.0 // 0
124199
]);
125200

126201
t.deepEqual( x, expected, 'deep equal' );
127202
t.end();
128203
});
129204

205+
tape( 'the function supports negative strides (accessors)', function test( t ) {
206+
var expected;
207+
var xbuf;
208+
var x;
209+
var N;
210+
211+
xbuf = new Float32Array([
212+
-1.0, // 2
213+
-1.0, // 2
214+
-2.0,
215+
-2.0,
216+
-3.0, // 1
217+
-3.0, // 1
218+
-4.0,
219+
-4.0,
220+
-5.0, // 0
221+
-5.0 // 0
222+
]);
223+
x = new Complex64Array( xbuf );
224+
N = 3;
225+
226+
nullary( [ x ], [ N ], [ -2 ], constantFunction( new Complex64( 1.0, 1.0 ) ) );
227+
228+
expected = new Complex64Array([
229+
new Complex64( 1.0, 1.0 ),
230+
new Complex64( -2.0, -2.0 ),
231+
new Complex64( 1.0, 1.0 ),
232+
new Complex64( -4.0, -4.0 ),
233+
new Complex64( 1.0, 1.0 )
234+
]);
235+
236+
t.deepEqual( new Float32Array( x.buffer ), new Float32Array( expected.buffer ), 'deep equal' );
237+
t.end();
238+
});
239+
130240
tape( 'the function supports view offsets', function test( t ) {
131241
var expected;
132242
var x0;
@@ -151,11 +261,11 @@ tape( 'the function supports view offsets', function test( t ) {
151261
nullary( [ x1 ], [ N ], [ -2 ], constantFunction( 3.0 ) );
152262
expected = new Float64Array([
153263
-1.0,
154-
3.0,
264+
3.0, // 2
155265
-3.0,
156-
3.0,
266+
3.0, // 1
157267
-5.0,
158-
3.0
268+
3.0 // 0
159269
]);
160270

161271
t.deepEqual( x0, expected, 'deep equal' );
@@ -181,11 +291,11 @@ tape( 'the function supports array-like objects', function test( t ) {
181291

182292
expected = {
183293
'length': 5,
184-
'0': 3.0,
294+
'0': 3.0, // 0
185295
'1': -2.0,
186-
'2': 3.0,
296+
'2': 3.0, // 1
187297
'3': -4.0,
188-
'4': 3.0
298+
'4': 3.0 // 2
189299
};
190300

191301
t.deepEqual( x, expected, 'deep equal' );

0 commit comments

Comments
 (0)