2222
2323var tape = require ( 'tape' ) ;
2424var isndarrayLike = require ( '@stdlib/assert/is-ndarray-like' ) ;
25+ var isEqualDataType = require ( '@stdlib/ndarray/base/assert/is-equal-data-type' ) ;
2526var zeroTo = require ( '@stdlib/array/zero-to' ) ;
2627var ndarray = require ( '@stdlib/ndarray/ctor' ) ;
2728var array = require ( '@stdlib/ndarray/array' ) ;
2829var getShape = require ( '@stdlib/ndarray/shape' ) ;
2930var getDType = require ( '@stdlib/ndarray/dtype' ) ;
31+ var getData = require ( '@stdlib/ndarray/data-buffer' ) ;
3032var ndarray2array = require ( '@stdlib/ndarray/to-array' ) ;
3133var toUnflattened = require ( './../lib' ) ;
3234
@@ -100,7 +102,7 @@ tape( 'the function throws an error if provided a second argument which is not a
100102 }
101103} ) ;
102104
103- tape ( 'the function throws an error if provided a third argument which is not a collection of numbers ' , function test ( t ) {
105+ tape ( 'the function throws an error if provided a third argument which is not an array of nonnegative integers ' , function test ( t ) {
104106 var values ;
105107 var x ;
106108 var i ;
@@ -117,6 +119,7 @@ tape( 'the function throws an error if provided a third argument which is not a
117119 void 0 ,
118120 [ '1' , '2' ] ,
119121 [ 1.5 , 2.5 ] ,
122+ [ - 1 , 6 ] ,
120123 { } ,
121124 function noop ( ) { }
122125 ] ;
@@ -177,7 +180,8 @@ tape( 'the function returns a new ndarray with the unflattened dimension (1D inp
177180
178181 y = toUnflattened ( x , 0 , [ 2 , 3 ] ) ;
179182 t . deepEqual ( getShape ( y ) , [ 2 , 3 ] , 'returns expected shape' ) ;
180- t . strictEqual ( String ( getDType ( y ) ) , String ( getDType ( x ) ) , 'returns expected dtype' ) ;
183+ t . strictEqual ( isEqualDataType ( getDType ( y ) , getDType ( x ) ) , true , 'returns expected dtype' ) ;
184+ t . notEqual ( getData ( y ) , getData ( x ) , 'does not share the same data buffer' ) ;
181185 t . deepEqual ( ndarray2array ( y ) , expected , 'returns expected value' ) ;
182186
183187 t . end ( ) ;
@@ -199,7 +203,8 @@ tape( 'the function returns a new ndarray with the unflattened dimension (1D inp
199203
200204 y = toUnflattened ( x , 0 , [ 2 , 2 , 3 ] ) ;
201205 t . deepEqual ( getShape ( y ) , [ 2 , 2 , 3 ] , 'returns expected shape' ) ;
202- t . strictEqual ( String ( getDType ( y ) ) , String ( getDType ( x ) ) , 'returns expected dtype' ) ;
206+ t . strictEqual ( isEqualDataType ( getDType ( y ) , getDType ( x ) ) , true , 'returns expected dtype' ) ;
207+ t . notEqual ( getData ( y ) , getData ( x ) , 'does not share the same data buffer' ) ;
203208 t . deepEqual ( ndarray2array ( y ) , expected , 'returns expected value' ) ;
204209
205210 t . end ( ) ;
@@ -221,6 +226,8 @@ tape( 'the function supports negative dimension indices', function test( t ) {
221226
222227 y = toUnflattened ( x , - 1 , [ 2 , 3 ] ) ;
223228 t . deepEqual ( getShape ( y ) , [ 2 , 3 ] , 'returns expected shape' ) ;
229+ t . strictEqual ( isEqualDataType ( getDType ( y ) , getDType ( x ) ) , true , 'returns expected dtype' ) ;
230+ t . notEqual ( getData ( y ) , getData ( x ) , 'does not share the same data buffer' ) ;
224231 t . deepEqual ( ndarray2array ( y ) , expected , 'returns expected value' ) ;
225232
226233 t . end ( ) ;
@@ -237,25 +244,8 @@ tape( 'the function returns a new ndarray that is ndarray-like', function test(
237244
238245 y = toUnflattened ( x , 0 , [ 2 , 3 ] ) ;
239246 t . strictEqual ( isndarrayLike ( y ) , true , 'returns ndarray-like object' ) ;
240-
241- t . end ( ) ;
242- } ) ;
243-
244- tape ( 'the function returns a new ndarray with the same dtype' , function test ( t ) {
245- var dtypes ;
246- var buf ;
247- var x ;
248- var y ;
249- var i ;
250-
251- dtypes = [ 'float32' , 'float64' , 'int32' , 'uint8' ] ;
252-
253- for ( i = 0 ; i < dtypes . length ; i ++ ) {
254- buf = zeroTo ( 6 ) ;
255- x = ndarray ( dtypes [ i ] , buf , [ 6 ] , [ 1 ] , 0 , 'row-major' ) ;
256- y = toUnflattened ( x , 0 , [ 2 , 3 ] ) ;
257- t . strictEqual ( String ( getDType ( y ) ) , dtypes [ i ] , 'returns expected dtype for ' + dtypes [ i ] ) ;
258- }
247+ t . strictEqual ( isEqualDataType ( getDType ( y ) , getDType ( x ) ) , true , 'returns expected dtype' ) ;
248+ t . notEqual ( getData ( y ) , getData ( x ) , 'does not share the same data buffer' ) ;
259249
260250 t . end ( ) ;
261251} ) ;
@@ -276,6 +266,8 @@ tape( 'the function supports column-major order', function test( t ) {
276266
277267 y = toUnflattened ( x , 0 , [ 2 , 3 ] ) ;
278268 t . deepEqual ( getShape ( y ) , [ 2 , 3 ] , 'returns expected shape' ) ;
269+ t . strictEqual ( isEqualDataType ( getDType ( y ) , getDType ( x ) ) , true , 'returns expected dtype' ) ;
270+ t . notEqual ( getData ( y ) , getData ( x ) , 'does not share the same data buffer' ) ;
279271 t . deepEqual ( ndarray2array ( y ) , expected , 'returns expected value' ) ;
280272
281273 t . end ( ) ;
@@ -298,6 +290,8 @@ tape( 'the function unflattens a middle dimension in a multidimensional input',
298290
299291 y = toUnflattened ( x , 1 , [ 2 , 2 ] ) ;
300292 t . deepEqual ( getShape ( y ) , [ 3 , 2 , 2 ] , 'returns expected shape' ) ;
293+ t . strictEqual ( isEqualDataType ( getDType ( y ) , getDType ( x ) ) , true , 'returns expected dtype' ) ;
294+ t . notEqual ( getData ( y ) , getData ( x ) , 'does not share the same data buffer' ) ;
301295 t . deepEqual ( ndarray2array ( y ) , expected , 'returns expected value' ) ;
302296
303297 t . end ( ) ;
0 commit comments