16
16
* limitations under the License.
17
17
*/
18
18
19
+ /* eslint-disable max-len */
20
+
19
21
'use strict' ;
20
22
21
23
// MODULES //
@@ -24,6 +26,9 @@ var tape = require( 'tape' );
24
26
var floor = require ( '@stdlib/math/base/special/floor' ) ;
25
27
var constantFunction = require ( '@stdlib/utils/constant-function' ) ;
26
28
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' ) ;
27
32
var nullary = require ( './../lib/main.js' ) ;
28
33
29
34
@@ -54,6 +59,22 @@ tape( 'the function applies a nullary callback to each indexed strided array ele
54
59
t . end ( ) ;
55
60
} ) ;
56
61
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
+
57
78
tape ( 'the function supports an `x` stride' , function test ( t ) {
58
79
var expected ;
59
80
var x ;
@@ -71,18 +92,53 @@ tape( 'the function supports an `x` stride', function test( t ) {
71
92
nullary ( [ x ] , [ N ] , [ 2 ] , constantFunction ( 3.0 ) ) ;
72
93
73
94
expected = new Float64Array ( [
74
- 3.0 ,
95
+ 3.0 , // 0
75
96
- 2.0 ,
76
- 3.0 ,
97
+ 3.0 , // 1
77
98
- 4.0 ,
78
- 3.0
99
+ 3.0 // 2
79
100
] ) ;
80
101
81
102
t . deepEqual ( x , expected , 'deep equal' ) ;
82
103
t . end ( ) ;
83
104
} ) ;
84
105
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 ) {
86
142
var expected ;
87
143
var x ;
88
144
@@ -99,6 +155,25 @@ tape( 'if provided a shape whose only element is less than or equal to `0`, the
99
155
t . end ( ) ;
100
156
} ) ;
101
157
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
+
102
177
tape ( 'the function supports negative strides' , function test ( t ) {
103
178
var expected ;
104
179
var x ;
@@ -116,17 +191,52 @@ tape( 'the function supports negative strides', function test( t ) {
116
191
nullary ( [ x ] , [ N ] , [ - 2 ] , constantFunction ( 3.0 ) ) ;
117
192
118
193
expected = new Float64Array ( [
119
- 3.0 ,
194
+ 3.0 , // 2
120
195
- 2.0 ,
121
- 3.0 ,
196
+ 3.0 , // 1
122
197
- 4.0 ,
123
- 3.0
198
+ 3.0 // 0
124
199
] ) ;
125
200
126
201
t . deepEqual ( x , expected , 'deep equal' ) ;
127
202
t . end ( ) ;
128
203
} ) ;
129
204
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
+
130
240
tape ( 'the function supports view offsets' , function test ( t ) {
131
241
var expected ;
132
242
var x0 ;
@@ -151,11 +261,11 @@ tape( 'the function supports view offsets', function test( t ) {
151
261
nullary ( [ x1 ] , [ N ] , [ - 2 ] , constantFunction ( 3.0 ) ) ;
152
262
expected = new Float64Array ( [
153
263
- 1.0 ,
154
- 3.0 ,
264
+ 3.0 , // 2
155
265
- 3.0 ,
156
- 3.0 ,
266
+ 3.0 , // 1
157
267
- 5.0 ,
158
- 3.0
268
+ 3.0 // 0
159
269
] ) ;
160
270
161
271
t . deepEqual ( x0 , expected , 'deep equal' ) ;
@@ -181,11 +291,11 @@ tape( 'the function supports array-like objects', function test( t ) {
181
291
182
292
expected = {
183
293
'length' : 5 ,
184
- '0' : 3.0 ,
294
+ '0' : 3.0 , // 0
185
295
'1' : - 2.0 ,
186
- '2' : 3.0 ,
296
+ '2' : 3.0 , // 1
187
297
'3' : - 4.0 ,
188
- '4' : 3.0
298
+ '4' : 3.0 // 2
189
299
} ;
190
300
191
301
t . deepEqual ( x , expected , 'deep equal' ) ;
0 commit comments