Skip to content

Commit 1393caf

Browse files
committed
test: add ndarray tests
1 parent d81786b commit 1393caf

31 files changed

Lines changed: 25895 additions & 0 deletions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 Float64Array = require( '@stdlib/array/float64' );
25+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
26+
var hasProp = require( '@stdlib/assert/has-property' );
27+
var isFunction = require( '@stdlib/assert/is-function' );
28+
var FancyArray = require( './../lib' );
29+
30+
31+
// TESTS //
32+
33+
tape( 'main export is a function', function test( t ) {
34+
t.ok( true, __filename );
35+
t.strictEqual( typeof FancyArray, 'function', 'main export is a function' );
36+
t.end();
37+
});
38+
39+
tape( 'a FancyArray constructor returns an instance which has a `get` method', function test( t ) {
40+
var strides;
41+
var buffer;
42+
var offset;
43+
var dtype;
44+
var order;
45+
var shape;
46+
var arr;
47+
48+
dtype = 'float64';
49+
buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
50+
shape = [ 1, 1, 1, 2, 2 ];
51+
order = 'row-major';
52+
strides = [ 2, 1, 1, 1, 1 ];
53+
offset = 0;
54+
55+
arr = new FancyArray( dtype, buffer, shape, strides, offset, order );
56+
57+
t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' );
58+
t.strictEqual( hasProp( arr, 'get' ), true, 'has property' );
59+
t.strictEqual( isFunction( arr.get ), true, 'has method' );
60+
t.end();
61+
});
62+
63+
tape( 'a FancyArray constructor returns an instance which has a `get` method (0d)', function test( t ) {
64+
var strides;
65+
var buffer;
66+
var offset;
67+
var dtype;
68+
var order;
69+
var shape;
70+
var arr;
71+
72+
dtype = 'float64';
73+
buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] );
74+
shape = [];
75+
order = 'row-major';
76+
strides = [ 0 ];
77+
offset = 1;
78+
79+
arr = new FancyArray( dtype, buffer, shape, strides, offset, order );
80+
81+
t.strictEqual( hasOwnProp( arr, 'get' ), false, 'does not have own property' );
82+
t.strictEqual( hasProp( arr, 'get' ), true, 'has property' );
83+
t.strictEqual( isFunction( arr.get ), true, 'has method' );
84+
t.end();
85+
});
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 Float64Array = require( '@stdlib/array/float64' );
25+
var Complex64Array = require( '@stdlib/array/complex64' );
26+
var realf = require( '@stdlib/complex/realf' );
27+
var imagf = require( '@stdlib/complex/imagf' );
28+
var FancyArray = require( './../lib' );
29+
30+
31+
// TESTS //
32+
33+
tape( 'main export is a function', function test( t ) {
34+
t.ok( true, __filename );
35+
t.strictEqual( typeof FancyArray, 'function', 'main export is a function' );
36+
t.end();
37+
});
38+
39+
tape( 'a FancyArray constructor returns an instance which has a `get` method which throws an error if provided any arguments (0d)', function test( t ) {
40+
var strides;
41+
var values;
42+
var buffer;
43+
var offset;
44+
var dtype;
45+
var order;
46+
var shape;
47+
var arr;
48+
var i;
49+
50+
dtype = 'float64';
51+
buffer = new Float64Array( [ 1.0 ] );
52+
shape = [];
53+
order = 'row-major';
54+
strides = [ 0 ];
55+
offset = 0;
56+
57+
arr = new FancyArray( dtype, buffer, shape, strides, offset, order );
58+
59+
values = [
60+
'5',
61+
0,
62+
3.14,
63+
NaN,
64+
true,
65+
false,
66+
null,
67+
void 0,
68+
[],
69+
{},
70+
function noop() {}
71+
];
72+
for ( i = 0; i < values.length; i++ ) {
73+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
74+
}
75+
t.end();
76+
77+
function badValue( value ) {
78+
return function badValue() {
79+
arr.get( value );
80+
};
81+
}
82+
});
83+
84+
tape( 'a FancyArray constructor returns an instance which has a `get` method for retrieving an array element (0d)', function test( t ) {
85+
var strides;
86+
var buffer;
87+
var offset;
88+
var dtype;
89+
var order;
90+
var shape;
91+
var arr;
92+
93+
dtype = 'float64';
94+
buffer = new Float64Array( [ 1.0, 2.0, 3.0 ] );
95+
shape = [];
96+
order = 'row-major';
97+
strides = [ 0 ];
98+
offset = 1;
99+
100+
arr = new FancyArray( dtype, buffer, shape, strides, offset, order );
101+
102+
t.strictEqual( arr.get(), 2.0, 'returns expected value' );
103+
104+
t.end();
105+
});
106+
107+
tape( 'a FancyArray constructor returns an instance which has a `get` method for retrieving an array element (0d; complex typed)', function test( t ) {
108+
var strides;
109+
var buffer;
110+
var offset;
111+
var dtype;
112+
var order;
113+
var shape;
114+
var arr;
115+
var v;
116+
117+
dtype = 'complex64';
118+
buffer = new Complex64Array( [ 1.0, 2.0 ] );
119+
shape = [];
120+
order = 'row-major';
121+
strides = [ 0 ];
122+
offset = 0;
123+
124+
arr = new FancyArray( dtype, buffer, shape, strides, offset, order );
125+
126+
v = arr.get();
127+
t.strictEqual( realf( v ), 1.0, 'returns expected value' );
128+
t.strictEqual( imagf( v ), 2.0, 'returns expected value' );
129+
130+
t.end();
131+
});

0 commit comments

Comments
 (0)