Skip to content

Commit 7862694

Browse files
committed
refactor: apply suggestions from code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent c57c298 commit 7862694

1 file changed

Lines changed: 65 additions & 19 deletions

File tree

  • lib/node_modules/@stdlib/blas/ext/base/ndarray/dcircshift/test

lib/node_modules/@stdlib/blas/ext/base/ndarray/dcircshift/test/test.js

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ var tape = require( 'tape' );
2424
var Float64Array = require( '@stdlib/array/float64' );
2525
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
2626
var getData = require( '@stdlib/ndarray/data-buffer' );
27-
var getDtype = require( '@stdlib/ndarray/dtype' );
28-
var getStrides = require( '@stdlib/ndarray/strides' );
29-
var getOffset = require( '@stdlib/ndarray/offset' );
30-
var getShape = require( '@stdlib/ndarray/shape' );
3127
var ndarray = require( '@stdlib/ndarray/base/ctor' );
3228
var dcircshift = require( './../lib' );
3329

@@ -40,6 +36,11 @@ tape( 'main export is a function', function test( t ) {
4036
t.end();
4137
});
4238

39+
tape( 'the function has an arity of 1', function test( t ) {
40+
t.strictEqual( dcircshift.length, 1, 'has expected arity' );
41+
t.end();
42+
});
43+
4344
tape( 'the function circularly shifts elements of a one-dimensional ndarray (right shift)', function test( t ) {
4445
var actual;
4546
var x;
@@ -52,11 +53,7 @@ tape( 'the function circularly shifts elements of a one-dimensional ndarray (rig
5253

5354
actual = dcircshift( [ x, k ] );
5455
t.strictEqual( actual, x, 'returns expected value' );
55-
t.strictEqual( getDtype( actual ), 'float64', 'returns expected value' );
5656
t.deepEqual( getData( actual ), new Float64Array( [ 4.0, 5.0, 1.0, 2.0, 3.0 ] ), 'returns expected value' );
57-
t.deepEqual( getShape( actual ), [ 5 ], 'returns expected value' );
58-
t.deepEqual( getStrides( actual ), [ 1 ], 'returns expected value' );
59-
t.strictEqual( getOffset( actual ), 0, 'returns expected value' );
6057

6158
t.end();
6259
});
@@ -73,16 +70,12 @@ tape( 'the function circularly shifts elements of a one-dimensional ndarray (lef
7370

7471
actual = dcircshift( [ x, k ] );
7572
t.strictEqual( actual, x, 'returns expected value' );
76-
t.strictEqual( getDtype( actual ), 'float64', 'returns expected value' );
7773
t.deepEqual( getData( actual ), new Float64Array( [ 3.0, 4.0, 5.0, 1.0, 2.0 ] ), 'returns expected value' );
78-
t.deepEqual( getShape( actual ), [ 5 ], 'returns expected value' );
79-
t.deepEqual( getStrides( actual ), [ 1 ], 'returns expected value' );
80-
t.strictEqual( getOffset( actual ), 0, 'returns expected value' );
8174

8275
t.end();
8376
});
8477

85-
tape( 'the function returns the input ndarray unchanged when k is zero', function test( t ) {
78+
tape( 'the function returns the input ndarray unchanged when the number of elements to shift is zero', function test( t ) {
8679
var actual;
8780
var x;
8881
var k;
@@ -99,7 +92,7 @@ tape( 'the function returns the input ndarray unchanged when k is zero', functio
9992
t.end();
10093
});
10194

102-
tape( 'the function returns the input ndarray unchanged when N is zero', function test( t ) {
95+
tape( 'the function returns the input ndarray unchanged when the input ndarray is empty', function test( t ) {
10396
var actual;
10497
var x;
10598
var k;
@@ -116,7 +109,7 @@ tape( 'the function returns the input ndarray unchanged when N is zero', functio
116109
t.end();
117110
});
118111

119-
tape( 'the function returns the input ndarray unchanged when N is one', function test( t ) {
112+
tape( 'the function returns the input ndarray unchanged when the input ndarray contains a single element', function test( t ) {
120113
var actual;
121114
var x;
122115
var k;
@@ -133,7 +126,7 @@ tape( 'the function returns the input ndarray unchanged when N is one', function
133126
t.end();
134127
});
135128

136-
tape( 'the function returns the input ndarray unchanged when k equals N', function test( t ) {
129+
tape( 'the function returns the input ndarray unchanged when the number of positions to shift equals the number of elements in the input ndarray (right shift)', function test( t ) {
137130
var actual;
138131
var x;
139132
var k;
@@ -150,7 +143,24 @@ tape( 'the function returns the input ndarray unchanged when k equals N', functi
150143
t.end();
151144
});
152145

153-
tape( 'the function supports a shift larger than N', function test( t ) {
146+
tape( 'the function returns the input ndarray unchanged when the number of positions to shift equals the number of elements in the input ndarray (left shift)', function test( t ) {
147+
var actual;
148+
var x;
149+
var k;
150+
151+
x = ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ), [ 5 ], [ 1 ], 0, 'row-major' );
152+
k = scalar2ndarray( -5, {
153+
'dtype': 'generic'
154+
});
155+
156+
actual = dcircshift( [ x, k ] );
157+
t.strictEqual( actual, x, 'returns expected value' );
158+
t.deepEqual( getData( actual ), new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ), 'returns expected value' );
159+
160+
t.end();
161+
});
162+
163+
tape( 'the function supports shifting elements in multiple cycles (right shift)', function test( t ) {
154164
var actual;
155165
var x;
156166
var k;
@@ -167,7 +177,24 @@ tape( 'the function supports a shift larger than N', function test( t ) {
167177
t.end();
168178
});
169179

170-
tape( 'the function supports a negative stride', function test( t ) {
180+
tape( 'the function supports shifting elements in multiple cycles (left shift)', function test( t ) {
181+
var actual;
182+
var x;
183+
var k;
184+
185+
x = ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ), [ 5 ], [ 1 ], 0, 'row-major' );
186+
k = scalar2ndarray( -7, {
187+
'dtype': 'generic'
188+
});
189+
190+
actual = dcircshift( [ x, k ] );
191+
t.strictEqual( actual, x, 'returns expected value' );
192+
t.deepEqual( getData( actual ), new Float64Array( [ 3.0, 4.0, 5.0, 1.0, 2.0 ] ), 'returns expected value' );
193+
194+
t.end();
195+
});
196+
197+
tape( 'the function supports an input ndarray having a negative stride', function test( t ) {
171198
var actual;
172199
var xbuf;
173200
var x;
@@ -186,7 +213,7 @@ tape( 'the function supports a negative stride', function test( t ) {
186213
t.end();
187214
});
188215

189-
tape( 'the function supports a non-zero offset', function test( t ) {
216+
tape( 'the function supports an input ndarray having a non-zero offset', function test( t ) {
190217
var actual;
191218
var xbuf;
192219
var x;
@@ -204,3 +231,22 @@ tape( 'the function supports a non-zero offset', function test( t ) {
204231

205232
t.end();
206233
});
234+
235+
tape( 'the function supports an input ndarray having a negative stride and non-zero offset', function test( t ) {
236+
var actual;
237+
var xbuf;
238+
var x;
239+
var k;
240+
241+
xbuf = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] );
242+
x = ndarray( 'float64', xbuf, [ 5 ], [ -2 ], 9, 'row-major' );
243+
k = scalar2ndarray( 2, {
244+
'dtype': 'generic'
245+
});
246+
247+
actual = dcircshift( [ x, k ] );
248+
t.strictEqual( actual, x, 'returns expected value' );
249+
t.deepEqual( getData( actual ), new Float64Array( [ 0.0, 5.0, 2.0, 7.0, 4.0, 9.0, 6.0, 1.0, 8.0, 3.0 ] ), 'returns expected value' );
250+
251+
t.end();
252+
});

0 commit comments

Comments
 (0)