Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,94 @@

// MODULES //

var tape = require( 'tape' );
var instanceOf = require( '@stdlib/assert/instance-of' );
var CompactAdjacencyMatrix = require( './../lib' );
var tape = require('tape');
Copy link
Member

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.

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, [
Copy link
Member

Choose a reason for hiding this comment

The 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 matrix attribute, and these tests are not written correctly.

// 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')
})