Skip to content

Commit 4aeff37

Browse files
committed
undirected unweighted graph
1 parent 4566235 commit 4aeff37

File tree

7 files changed

+43
-113
lines changed

7 files changed

+43
-113
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# js-graph-algorithms
22
Package provides javascript implementation of algorithms for graph processing
3+
4+
[![Build Status](https://travis-ci.org/chen0040/js-graph-algorithms.svg?branch=master)](https://travis-ci.org/chen0040/js-graph-algorithms) [![Coverage Status](https://coveralls.io/repos/github/chen0040/js-graph-algorithms/badge.svg?branch=master)](https://coveralls.io/github/chen0040/js-graph-algorithms?branch=master)

src/jsgraphs.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
var jsgraphs = jsgraphs || {};
22

33
(function(jss){
4-
var Graph = function () {
5-
4+
var Graph = function (V) {
5+
this.V = V;
6+
this.adjList = [];
7+
for (var i = 0; i < V; ++i) {
8+
this.adjList.push([]);
9+
}
10+
};
11+
12+
Graph.prototype.addEdge = function(v, w){
13+
this.adjList[v].push(w);
14+
this.adjList[w].push(v);
15+
};
16+
17+
Graph.prototype.adj = function(v) {
18+
return this.adjList[v];
619
};
720

821
jss.Graph = Graph;

test/chi-square-distribution-spec.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/f-distribution-spec.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/graph-spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var expect = require("chai").expect;
2+
var jsgraphs = require("../src/jsgraphs");
3+
4+
describe("Create various types of Graphs", function() {
5+
describe("Create unweighted undirected graph", function() {
6+
var g = new jsgraphs.Graph(6);
7+
g.addEdge(0, 5);
8+
g.addEdge(2, 4);
9+
g.addEdge(2, 3);
10+
g.addEdge(1, 2);
11+
g.addEdge(0, 1);
12+
g.addEdge(3, 4);
13+
g.addEdge(3, 5);
14+
g.addEdge(0, 2);
15+
it("should has 6 vertices", function() {
16+
expect(g.V).to.equal(6);
17+
});
18+
it("should be undirected", function() {
19+
expect(g.adj(0)).to.contains(5);
20+
expect(g.adj(5)).to.contains(0);
21+
});
22+
});
23+
24+
25+
26+
});

test/normal-distribution-spec.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/t-distribution-spec.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)