diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.add_edge.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.add_edge.js new file mode 100644 index 000000000000..943f8551e905 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.add_edge.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `addEdge` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'addEdge' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.addEdge ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value where both arguments are not a non negative number', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + [ '5', 2 ], + [ 'abcde', -1 ], + [ -1, 5 ], + [ NaN, NaN ], + [ true, 2 ], + [ false, '2' ], + [ null, 0 ], + [ void 0, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i][0], values[i][1] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return adj.addEdge( arg1, arg2 ); + }; + } +}); + +tape( 'the method throws an Range error if invoked with value where both arguments exceeds matrix dimensions', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + [ 6, 2 ], + [ 0, 5 ], + [ 7, 8 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i][0], values[i][1] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return adj.addEdge( arg1, arg2 ); + }; + } +}); + +tape( 'the method returns an instance of adjcency matrix upon invoking by a valid input', function test( t ) { + var expected; + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + [ 0, 3], + [ 1, 0], + [ 0, 2] + ]; + for ( i = 0; i < values.length; i++ ) { + expected = adj.addEdge( values[i][0], values[i][1] ); + t.strictEqual( instanceOf( expected, CompactAdjacencyMatrix ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.edges.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.edges.js new file mode 100644 index 000000000000..fa2d61a71422 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.edges.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEmptyArray = require( '@stdlib/assert/is-empty-array' ); +var isArray = require( '@stdlib/assert/is-array' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `edges` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'edges' ), true, 'has property' ); + t.end(); +}); + +tape( 'the method returns a list of array when there exists vertices and edges', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + t.strictEqual( isArray( adj.edges ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty array in case of vertices but no edges', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + t.strictEqual( isEmptyArray( adj.edges ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.from_edges.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.from_edges.js new file mode 100644 index 000000000000..9c92342cf7c0 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.from_edges.js @@ -0,0 +1,179 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `fromEdges` method', function test( t ) { + var arr; + + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix, 'fromEdges' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.fromEdges ), true, 'has method' ); + + arr = CompactAdjacencyMatrix.fromEdges( 2, [] ); + t.strictEqual( instanceOf( arr, CompactAdjacencyMatrix ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value which is not a non negative number', function test( t ) { + var values; + var edges; + var i; + + edges = [ [ 0, 1 ], [ 0, 2 ], [ 1, 2 ], [ 2, 3 ] ]; + + values = [ + '5', + 'abcde', + -1, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i], edges ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return CompactAdjacencyMatrix.fromEdges( arg1, arg2 ); + }; + } +}); + +tape( 'the method throws an error if invoked with a value which is not an array like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 'abcde', + -1, + NaN, + true, + false, + null, + void 0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( 4, values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return CompactAdjacencyMatrix.fromEdges( arg1, arg2 ); + }; + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object (callback)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( 4, values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return CompactAdjacencyMatrix.fromEdges( arg1, arg2, clbk ); + }; + } + + function clbk() { + return [ 1.0, 1.0 ]; + } +}); + +tape( 'the method throws an error if not provided an iterable or array-like object (callback, thisArg)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return CompactAdjacencyMatrix.fromEdges( arg1, arg2, clbk, {} ); + }; + } + + function clbk() { + return [ 1.0, 1.0 ]; + } +}); + +tape( 'the method returns an instance of adjcency matrix upon invoking by a valid input', function test( t ) { + var values; + var i; + + values = [ + [ [ 0, 1 ], [ 2, 3 ] ], + [ [ 1, 3 ], [ 0, 3 ], [ 2, 0 ] ], + [ [ 1, 2 ], [ 0, 1 ] ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( instanceOf( CompactAdjacencyMatrix.fromEdges( 4, values[ i ] ), CompactAdjacencyMatrix ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.has_edge.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.has_edge.js new file mode 100644 index 000000000000..4c18c240d7c9 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.has_edge.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `hasEdge` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'hasEdge' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.hasEdge ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value where both arguments are not a non negative number', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + [ '5', 2 ], + [ 'abcde', -1 ], + [ -1, 5 ], + [ NaN, NaN ], + [ true, 2 ], + [ false, '2' ], + [ null, 0 ], + [ void 0, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i][0], values[i][1] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return adj.hasEdge( arg1, arg2 ); + }; + } +}); + +tape( 'the method throws an Range error if invoked with value where both arguments exceeds matrix dimensions', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + [ 6, 2 ], + [ 0, 5 ], + [ 7, 8 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i][0], values[i][1] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return adj.hasEdge( arg1, arg2 ); + }; + } +}); + +tape( 'the method returns a boolean value upon invoking by a valid input', function test( t ) { + var expected; + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.hasEdge( 1, 0 ); + adj.hasEdge( 1, 2 ); + adj.hasEdge( 0, 2 ); + adj.hasEdge( 2, 3 ); + + values = [ + [ 0, 3], + [ 1, 0], + [ 0, 2] + ]; + for ( i = 0; i < values.length; i++ ) { + expected = adj.hasEdge( values[i][0], values[i][1] ); + t.strictEqual( isBoolean( expected ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.indegree.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.indegree.js new file mode 100644 index 000000000000..8e88307e6a44 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.indegree.js @@ -0,0 +1,150 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `inDegree` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'inDegree' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.inDegree ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value which is not a non negative number', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + '5', + 'abcde', + -1, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.inDegree( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with value which exceeds matrix dimensions', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 5, + 6, + 8 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.inDegree( value ); + }; + } +}); + +tape( 'the method returns a non negative value upon invoking by a valid input', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 0, + 1, + 2, + 3 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isNonNegativeInteger( adj.inDegree( values[i] ) ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the method returns 0 in case of vertices but no edges', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + 0, + 1, + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( adj.inDegree( values[i] ), 0, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.inedges.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.inedges.js new file mode 100644 index 000000000000..09a01180e909 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.inedges.js @@ -0,0 +1,150 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isEmptyArray = require( '@stdlib/assert/is-empty-array' ); +var isArray = require( '@stdlib/assert/is-array' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `inEdges` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'inEdges' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.inEdges ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value which is not a non negative number', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + '5', + 'abcde', + -1, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.inEdges( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with value which exceeds matrix dimensions', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 5, + 6, + 8 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.inEdges( value ); + }; + } +}); + +tape( 'the method returns an array upon invoking by a valid input', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 0, + 1, + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isArray( adj.inEdges( values[i] ) ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the method returns an empty array in case of vertices but no edges', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + 0, + 1, + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isEmptyArray( adj.inEdges( values[i] ) ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.js index 115fd7545421..9db03b65c4b5 100644 --- a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.js +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.js @@ -48,3 +48,21 @@ tape( 'the constructor does not require the `new` keyword', function test( t ) { t.strictEqual( instanceOf( mat, CompactAdjacencyMatrix ), true, 'returns an instance' ); t.end(); }); + +tape( 'the constructor returns an instance of compact adjacency matrix (length)', function test( t ) { + var arr = new CompactAdjacencyMatrix( 10 ); + t.strictEqual( instanceOf( arr, CompactAdjacencyMatrix ), true, 'returns an instance' ); + t.end(); +}); + +tape( 'the constructor returns an instance of compact adjacency matrix (length, no new)', function test( t ) { + var ctor; + var arr; + + ctor = CompactAdjacencyMatrix; + + arr = ctor( 10 ); + t.strictEqual( instanceOf( arr, CompactAdjacencyMatrix ), true, 'returns an instance' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.nedges.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.nedges.js new file mode 100644 index 000000000000..4a27c9ebd1fb --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.nedges.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `nedges` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'nedges' ), true, 'has property' ); + t.end(); +}); + +tape( 'the method returns a non negative value denoting number of edges', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + t.strictEqual( isNonNegativeInteger( adj.nedges ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns 0 in case of vertices but no edges', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + t.strictEqual( adj.nedges, 0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.nvertices.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.nvertices.js new file mode 100644 index 000000000000..aa8a13783fa2 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.nvertices.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `nvertices` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'nvertices' ), true, 'has property' ); + t.end(); +}); + +tape( 'the method returns a non negative value denoting number of vertices', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + t.strictEqual( isNonNegativeInteger( adj.nvertices ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.out_degree.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.out_degree.js new file mode 100644 index 000000000000..df6a3ae710c1 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.out_degree.js @@ -0,0 +1,149 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `outDegree` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'outDegree' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.outDegree ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value which is not a non negative number', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + '5', + 'abcde', + -1, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.outDegree( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with value which exceeds matrix dimensions', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 5, + 6, + 8 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.outDegree( value ); + }; + } +}); + +tape( 'the method returns a non negative value upon invoking by a valid input', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 0, + 1, + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isNonNegativeInteger( adj.outDegree( values[i] ) ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the method returns 0 in case of vertices but no edges', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + 0, + 1, + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( adj.outDegree( values[i] ), 0, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.out_edges.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.out_edges.js new file mode 100644 index 000000000000..3f10ebb95212 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.out_edges.js @@ -0,0 +1,150 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isEmptyArray = require( '@stdlib/assert/is-empty-array' ); +var isArray = require( '@stdlib/assert/is-array' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `outEdges` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'outEdges' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.outEdges ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value which is not a non negative number', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + '5', + 'abcde', + -1, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.outEdges( value ); + }; + } +}); + +tape( 'the method throws an error if invoked with value which exceeds matrix dimensions', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 5, + 6, + 8 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return adj.outEdges( value ); + }; + } +}); + +tape( 'the method returns an array upon invoking by a valid input', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + 0, + 1, + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isArray( adj.outEdges( values[i] ) ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the method returns an empty array in case of vertices but no edges', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + 0, + 1, + 2 + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isEmptyArray( adj.outEdges( values[i] ) ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.remove_edge.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.remove_edge.js new file mode 100644 index 000000000000..a8dffb4b8c21 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.remove_edge.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `removeEdge` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'removeEdge' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.removeEdge ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a value where both arguments are not a non negative number', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + [ '5', 2 ], + [ 'abcde', -1 ], + [ -1, 5 ], + [ NaN, NaN ], + [ true, 2 ], + [ false, '2' ], + [ null, 0 ], + [ void 0, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i][0], values[i][1] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return adj.removeEdge.call( arg1, arg2 ); + }; + } +}); + +tape( 'the method throws an Range error if invoked with value where both arguments exceeds matrix dimensions', function test( t ) { + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + values = [ + [ 6, 2 ], + [ 0, 5 ], + [ 7, 8 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i][0], values[i][1] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( arg1, arg2 ) { + return function badValue() { + return adj.removeEdge( arg1, arg2 ); + }; + } +}); + +tape( 'the method returns an instance of adjcency matrix upon removing an edge', function test( t ) { + var expected; + var values; + var adj; + var i; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + values = [ + [ 2, 3], + [ 1, 0], + [ 0, 2] + ]; + for ( i = 0; i < values.length; i++ ) { + expected = adj.removeEdge( values[i][0], values[i][1] ); + t.strictEqual( instanceOf( expected, CompactAdjacencyMatrix ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.to_adjacency_list.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.to_adjacency_list.js new file mode 100644 index 000000000000..13d0de63f61f --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.to_adjacency_list.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isArray = require( '@stdlib/assert/is-array' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toAdjacencyList` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'toAdjacencyList' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.toAdjacencyList ), true, 'has method' ); + t.end(); +}); + +tape( 'the method returns a list of array when there exists vertices and edges', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + t.strictEqual( isArray( adj.toAdjacencyList() ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an empty array in case of vertices but no edges', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + t.strictEqual( isArray( adj.toAdjacencyList() ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.toposort.js b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.toposort.js new file mode 100644 index 000000000000..6a5b1972d329 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.toposort.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isArray = require( '@stdlib/assert/is-array' ); +var CompactAdjacencyMatrix = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof CompactAdjacencyMatrix, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is a `toposort` method', function test( t ) { + t.strictEqual( hasOwnProp( CompactAdjacencyMatrix.prototype, 'toposort' ), true, 'has property' ); + t.strictEqual( isFunction( CompactAdjacencyMatrix.prototype.toposort ), true, 'has method' ); + t.end(); +}); + +tape( 'the method returns an array when there exists vertices and toposort', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + adj.addEdge( 1, 0 ); + adj.addEdge( 1, 2 ); + adj.addEdge( 0, 2 ); + adj.addEdge( 2, 3 ); + + t.strictEqual( isArray( adj.toposort() ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method returns an non-empty array in case of vertices but no edges', function test( t ) { + var adj; + + adj = new CompactAdjacencyMatrix( 4 ); + + t.strictEqual( isArray( adj.toposort() ), true, 'returns expected value' ); + t.end(); +});