diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/README.md new file mode 100644 index 000000000000..a8106e7fa319 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/README.md @@ -0,0 +1,143 @@ + + +# gjoinBetween + +> Return a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' ); +``` + +#### gjoinBetween( arrays ) + +Returns a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements. + +```javascript +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = [ 1, 2, 3, 4 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var prefix = scalar2ndarray( 'op: ', { + 'dtype': 'generic' +}); + +var suffix = scalar2ndarray( '', { + 'dtype': 'generic' +}); + +var sbuf = [ ' + ', ' - ', ' != ' ]; +var separators = new ndarray( 'generic', sbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + +var out = gjoinBetween( [ x, prefix, suffix, separators ] ); +// returns 'op: 1 + 2 - 3 != 4' +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing a prefix string. + - a zero-dimensional ndarray containing a suffix string. + - a one-dimensional ndarray containing separator strings. + +
+ + + +
+ +## Notes + +- If the input ndarray is empty, the function returns the prefix and suffix joined together. +- The `separators` ndarray is assumed to have at least `N-1` elements (i.e., equal to the number of "gaps" between consecutive elements), where `N` is the number of elements in the input ndarray. +- If an array element is either `null` or `undefined`, the function serializes the element as an empty string. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var filled = require( '@stdlib/array/base/filled' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var prefix = scalar2ndarray( '[ ', { + 'dtype': 'generic' +}); + +var suffix = scalar2ndarray( ' ]', { + 'dtype': 'generic' +}); + +var sbuf = filled( ' | ', xbuf.length - 1 ); +var separators = new ndarray( 'generic', sbuf, [ sbuf.length ], [ 1 ], 0, 'row-major' ); + +var out = gjoinBetween( [ x, prefix, suffix, separators ] ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/benchmark/benchmark.js new file mode 100644 index 000000000000..01df7088339e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/benchmark/benchmark.js @@ -0,0 +1,126 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var filled = require( '@stdlib/array/base/filled' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gjoinBetween = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var separators; + var prefix; + var suffix; + var sbuf; + var xbuf; + var x; + + xbuf = uniform( len, 0.0, 100.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + prefix = scalar2ndarray( '[ ', { + 'dtype': 'generic' + }); + + suffix = scalar2ndarray( ' ]', { + 'dtype': 'generic' + }); + + sbuf = filled( ',', len - 1 ); + separators = new ndarray( 'generic', sbuf, [ sbuf.length ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gjoinBetween( [ x, prefix, suffix, separators ] ); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/repl.txt new file mode 100644 index 000000000000..d71cca40339c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/repl.txt @@ -0,0 +1,45 @@ + +{{alias}}( arrays ) + Returns a string by joining one-dimensional ndarray elements using a + specified separator for each pair of consecutive elements. + + If the input ndarray is empty, the function returns the prefix and suffix + joined together. + + If an array element is either `null` or `undefined`, the function serializes + the element as an empty string. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing a prefix string. + - a zero-dimensional ndarray containing a suffix string. + - a one-dimensional ndarray containing separator strings. + + Returns + ------- + out: string + Joined string. + + Examples + -------- + > var xbuf = [ 1, 2, 3, 4 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var p = {{alias:@stdlib/ndarray/from-scalar}}( '', { 'dtype': dt } ); + > var s = {{alias:@stdlib/ndarray/from-scalar}}( '', { 'dtype': dt } ); + > var sbuf = [ ',', '-', '|' ]; + > var sh2 = [ sbuf.length ]; + > var sep = new {{alias:@stdlib/ndarray/ctor}}( dt, sbuf, sh2, sx, ox, ord ); + > {{alias}}( [ x, p, s, sep ] ) + '1,2-3|4' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/types/index.d.ts new file mode 100644 index 000000000000..598d0bf3b598 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/types/index.d.ts @@ -0,0 +1,57 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Returns a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements. +* +* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing a prefix string, a zero-dimensional ndarray containing a suffix string, and a one-dimensional ndarray containing separator strings +* @returns joined string +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var xbuf = [ 1, 2, 3, 4 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var prefix = scalar2ndarray( 'op: ', { +* 'dtype': 'generic' +* }); +* +* var suffix = scalar2ndarray( '', { +* 'dtype': 'generic' +* }); +* +* var sbuf = [ ' + ', ' - ', ' != ' ]; +* var separators = new ndarray( 'generic', sbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var v = gjoinBetween( [ x, prefix, suffix, separators ] ); +* // returns 'op: 1 + 2 - 3 != 4' +*/ +declare function gjoinBetween( arrays: [ typedndarray, typedndarray, typedndarray, typedndarray ] ): string; + + +// EXPORTS // + +export = gjoinBetween; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/types/test.ts new file mode 100644 index 000000000000..d7911b31676c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/docs/types/test.ts @@ -0,0 +1,77 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import broadcastScalar = require( '@stdlib/ndarray/broadcast-scalar' ); +import gjoinBetween = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const prefix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + const suffix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + const separators = broadcastScalar( ',', [ 9 ], { + 'dtype': 'generic' + }); + + gjoinBetween( [ x, prefix, suffix, separators ] ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gjoinBetween( '10' ); // $ExpectError + gjoinBetween( 10 ); // $ExpectError + gjoinBetween( true ); // $ExpectError + gjoinBetween( false ); // $ExpectError + gjoinBetween( null ); // $ExpectError + gjoinBetween( undefined ); // $ExpectError + gjoinBetween( [] ); // $ExpectError + gjoinBetween( {} ); // $ExpectError + gjoinBetween( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const prefix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + const suffix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + const separators = zeros( [ 9 ], { + 'dtype': 'generic' + }); + + gjoinBetween(); // $ExpectError + gjoinBetween( [ x, prefix, suffix, separators ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/examples/index.js new file mode 100644 index 000000000000..3de7a99c03a3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/examples/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var filled = require( '@stdlib/array/base/filled' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gjoinBetween = require( './../lib' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var prefix = scalar2ndarray( '[ ', { + 'dtype': 'generic' +}); + +var suffix = scalar2ndarray( ' ]', { + 'dtype': 'generic' +}); + +var sbuf = filled( ' | ', xbuf.length - 1 ); +var separators = new ndarray( 'generic', sbuf, [ sbuf.length ], [ 1 ], 0, 'row-major' ); + +var out = gjoinBetween( [ x, prefix, suffix, separators ] ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/lib/index.js new file mode 100644 index 000000000000..9ef49bff545f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements. +* +* @module @stdlib/blas/ext/base/ndarray/gjoin-between +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' ); +* +* var xbuf = [ 1, 2, 3, 4 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var prefix = scalar2ndarray( 'op: ', { +* 'dtype': 'generic' +* }); +* +* var suffix = scalar2ndarray( '', { +* 'dtype': 'generic' +* }); +* +* var sbuf = [ ' + ', ' - ', ' != ' ]; +* var separators = new ndarray( 'generic', sbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var v = gjoinBetween( [ x, prefix, suffix, separators ] ); +* // returns 'op: 1 + 2 - 3 != 4' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/lib/main.js new file mode 100644 index 000000000000..28aa2e369940 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/lib/main.js @@ -0,0 +1,76 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/gjoin-between' ).ndarray; + + +// MAIN // + +/** +* Returns a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {string} joined string +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var xbuf = [ 1, 2, 3, 4 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var prefix = scalar2ndarray( 'op: ', { +* 'dtype': 'generic' +* }); +* +* var suffix = scalar2ndarray( '', { +* 'dtype': 'generic' +* }); +* +* var sbuf = [ ' + ', ' - ', ' != ' ]; +* var separators = new ndarray( 'generic', sbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +* +* var v = gjoinBetween( [ x, prefix, suffix, separators ] ); +* // returns 'op: 1 + 2 - 3 != 4' +*/ +function gjoinBetween( arrays ) { + var separators; + var prefix; + var suffix; + var x; + + x = arrays[ 0 ]; + prefix = ndarraylike2scalar( arrays[ 1 ] ); + suffix = ndarraylike2scalar( arrays[ 2 ] ); + separators = arrays[ 3 ]; + return strided( numelDimension( x, 0 ), prefix, suffix, getData( x ), getStride( x, 0 ), getOffset( x ), getData( separators ), getStride( separators, 0 ), getOffset( separators ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gjoinBetween; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/package.json new file mode 100644 index 000000000000..9b8491a36878 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/package.json @@ -0,0 +1,62 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gjoin-between", + "version": "0.0.0", + "description": "Return a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "blas", + "extended", + "array", + "join", + "between", + "separator", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/test/test.js new file mode 100644 index 000000000000..db93eebfb578 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gjoin-between/test/test.js @@ -0,0 +1,214 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gjoinBetween = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gjoinBetween, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a string by joining one-dimensional ndarray elements using specified separators', function test( t ) { + var separators; + var actual; + var prefix; + var suffix; + var x; + + x = vector( [ 1, 2, 3, 4 ], 4, 1, 0 ); + prefix = scalar2ndarray( 'op: ', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + separators = vector( [ ' + ', ' - ', ' != ' ], 3, 1, 0 ); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, 'op: 1 + 2 - 3 != 4', 'returns expected value' ); + + prefix = scalar2ndarray( '[', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( ']', { + 'dtype': 'generic' + }); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, '[1 + 2 - 3 != 4]', 'returns expected value' ); + + prefix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, '1 + 2 - 3 != 4', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the prefix and suffix joined together if the number of elements is zero', function test( t ) { + var separators; + var actual; + var prefix; + var suffix; + var x; + + x = vector( [ 1, 2, 3 ], 0, 1, 0 ); + prefix = scalar2ndarray( 'a', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( 'b', { + 'dtype': 'generic' + }); + separators = vector( [ ',', ',' ], 2, 1, 0 ); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, 'ab', 'returns expected value' ); + + prefix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a single element', function test( t ) { + var separators; + var actual; + var prefix; + var suffix; + var x; + + x = vector( [ 1 ], 1, 1, 0 ); + prefix = scalar2ndarray( '<', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( '>', { + 'dtype': 'generic' + }); + separators = vector( [ ',' ], 1, 1, 0 ); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, '<1>', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarray strides', function test( t ) { + var separators; + var actual; + var prefix; + var suffix; + var x; + + x = vector( [ 1, 2, 3, 4, 5, 6 ], 3, 2, 0 ); + prefix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + separators = vector( [ ',', 'a', '-', 'b' ], 2, 2, 0 ); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, '1,3-5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarray offsets', function test( t ) { + var separators; + var actual; + var prefix; + var suffix; + var x; + + x = vector( [ 1, 2, 3, 4, 5, 6 ], 3, 1, 3 ); + prefix = scalar2ndarray( '[ ', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( ' ]', { + 'dtype': 'generic' + }); + separators = vector( [ 'a', ' | ', ' | ' ], 2, 1, 1 ); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, '[ 4 | 5 | 6 ]', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var separators; + var actual; + var prefix; + var suffix; + var x; + + x = vector( [ 1, 2, 3, 4, 5, 6 ], 6, -1, 5 ); + prefix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + suffix = scalar2ndarray( '', { + 'dtype': 'generic' + }); + separators = vector( [ ',', '-', '|', '~', '=' ], 5, 1, 0 ); + + actual = gjoinBetween( [ x, prefix, suffix, separators ] ); + t.strictEqual( actual, '6,5-4|3~2=1', 'returns expected value' ); + + t.end(); +});