-
-
Notifications
You must be signed in to change notification settings - Fork 907
test: add additional tests to utils/compact-adjacency-matrix
#1373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -20,31 +20,94 @@ | |
|
||
// MODULES // | ||
|
||
var tape = require( 'tape' ); | ||
var instanceOf = require( '@stdlib/assert/instance-of' ); | ||
var CompactAdjacencyMatrix = require( './../lib' ); | ||
var tape = require('tape'); | ||
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' ); | ||
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( 'the function is a constructor', function test( t ) { | ||
var mat = new CompactAdjacencyMatrix( 4 ); | ||
t.strictEqual( instanceOf( mat, CompactAdjacencyMatrix ), true, 'returns an instance' ); | ||
tape('the function is a constructor', function test(t) { | ||
var mat = new CompactAdjacencyMatrix(4); | ||
t.strictEqual(instanceOf(mat, CompactAdjacencyMatrix), true, 'returns an instance'); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the constructor does not require the `new` keyword', function test( t ) { | ||
tape('the constructor does not require the `new` keyword', function test(t) { | ||
var compactAdjacencyMatrix; | ||
var mat; | ||
|
||
compactAdjacencyMatrix = CompactAdjacencyMatrix; | ||
mat = compactAdjacencyMatrix( 4 ); | ||
t.strictEqual( instanceOf( mat, CompactAdjacencyMatrix ), true, 'returns an instance' ); | ||
mat = compactAdjacencyMatrix(4); | ||
t.strictEqual(instanceOf(mat, CompactAdjacencyMatrix), true, 'returns an instance'); | ||
t.end(); | ||
}); | ||
|
||
// adjacency Matrix can be depicted in form of undirected graph representation,directed graph represnetation and weighted graph representation | ||
|
||
tape('initialize the matrix correctly', function test(t) { | ||
var mat = new CompactAdjacencyMatrix(4); | ||
t.deepEqual(mat.matrix, [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @uchiha-vivek Did you run these tests? Based on what you have here, it does not appear so. There is no |
||
// mat.matrix --> mat.matrix property for mat which is object of var! | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0] | ||
// test case for 4*4 matrix | ||
], 'matrix initialised') | ||
}) | ||
// function to add edge and upating matrix! | ||
|
||
tape('adding edge and updating matrix', function test(t) { | ||
var mat = new CompactAdjacencyMatrix(3); | ||
//a[i][j]=1 presence of edge between two vertices i and j | ||
//a[i][j]=0 absence of edge between two vertices i and j | ||
mat.addEdge(0, 1); | ||
t.deepEqual(mat.matrix, [ | ||
[0, 1, 0], | ||
[0, 0, 0], | ||
[0, 0, 0] | ||
], 'matrix updated') | ||
|
||
// another instance | ||
mat.addEdge(1, 1); | ||
t.deepEqual(mat.matrix, [ | ||
[0, 1, 0], | ||
[0, 1, 0], | ||
[0, 0, 0] | ||
], 'matrix updated') | ||
// another instance | ||
mat.addEdge(2, 2); | ||
t.deepEqual(mat.matrix, [ | ||
[0, 1, 0], | ||
[0, 1, 0], | ||
[0, 0, 1] | ||
], 'matrix updated') | ||
// ##NOTE## --> Every time the matrix is updated it holds the previous updated value. | ||
// The above test case is checked for 3*3 matrix | ||
} | ||
) | ||
// test case to check whether adjacency matrix has any edges between vertices i and j | ||
// a[i][j] traverse over the whole matrix | ||
|
||
|
||
tape('Looking for edge and it is present', function test(t) { | ||
var mat = new CompactAdjacencyMatrix(3); | ||
mat.addEdge(0, 2) | ||
mat.addEdge(2, 1) | ||
t.equal(mat.hasEdge(0, 2), true, 'edge present between 0 and 2') | ||
t.equal(mat.hasEdge(2, 1), true, 'has edge between 2 and 1') | ||
|
||
|
||
}) | ||
tape('Looking for edge and it is not present', function test(t) { | ||
var mat = new CompactAdjacencyMatrix(3) | ||
mat.addEdge(2, 2) | ||
t.equal(mat.hasEdge(2, 2), false, 'dont have edge between 2 and 2') | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these style changes should not have been made. Please revert and ensure that you follow project conventions.