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..681ecb69386b 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 @@ -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, [ + // 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') +})