forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests to @stdlib/utils/compact-adjacency-matrix
added tests to @stdlib/utils/compact-adjacency-matrix Fixes stdlib-js#1330
- Loading branch information
1 parent
8314237
commit 04807ef
Showing
15 changed files
with
1,528 additions
and
0 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.add_edge.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* @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 CompactAdjacencyMatrix = require( '@stdlib/utils/compact-adjacency-matrix/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( expected instanceof CompactAdjacencyMatrix, true, 'returns expected value' ); | ||
} | ||
t.end(); | ||
}); |
64 changes: 64 additions & 0 deletions
64
lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.edges.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); |
65 changes: 65 additions & 0 deletions
65
lib/node_modules/@stdlib/utils/compact-adjacency-matrix/test/test.from_adjacency_list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( '@stdlib/utils/compact-adjacency-matrix/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(); | ||
}); |
Oops, something went wrong.