Skip to content

Commit 4566235

Browse files
committed
project setup
1 parent de17f06 commit 4566235

10 files changed

+235
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
.DS_Store
3+
thumbs.db
4+
*.log
5+
node_modules/
6+
.idea

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: node_js
2+
node_js:
3+
- "stable"
4+
5+
before_script:
6+
- npm install -g grunt-cli
7+
8+
after_success:
9+
- npm run coveralls

Gruntfile.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = function (grunt) {
2+
// Load the plugin that provides the "uglify" task.
3+
grunt.loadNpmTasks('grunt-contrib-uglify');
4+
grunt.loadNpmTasks('grunt-mocha-test');
5+
grunt.loadNpmTasks('grunt-eslint');
6+
7+
grunt.initConfig({
8+
pkg: grunt.file.readJSON('package.json'),
9+
uglify: {
10+
options: {
11+
preserveComments: 'some',
12+
},
13+
build: {
14+
src: 'src/jsgraphs.js',
15+
dest: 'build/jsgraphs.min.js',
16+
},
17+
},
18+
mochaTest: {
19+
test: {
20+
options: {
21+
reporter: 'spec',
22+
},
23+
src: ['tests/**/*.js'],
24+
},
25+
},
26+
});
27+
28+
// Default task(s).
29+
grunt.registerTask('default', ['uglify']);
30+
grunt.registerTask('test', ['mochaTest']);
31+
};

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./src/jsgraphs');

package.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "js-graph-algorithms",
3+
"version": "1.0.5",
4+
"description": "Package implements data structures and algorithms for processing various types of graphs",
5+
"author": "Xianshun Chen",
6+
"contributors": [
7+
"Xianshun Chen <[email protected]>"
8+
],
9+
"license": "MIT",
10+
"main": "index.js",
11+
"directories": {
12+
"test": "test"
13+
},
14+
"scripts": {
15+
"test": "mocha test",
16+
"cover": "istanbul cover _mocha",
17+
"coveralls": "npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"
18+
},
19+
"bin": {
20+
"js-graphs": "./src/jsgraphs.js"
21+
},
22+
"repository": {
23+
"type": "git",
24+
"url": "git+https://github.com/chen0040/js-graph-algorithms.git"
25+
},
26+
"keywords": [
27+
"graph",
28+
"weighted graph",
29+
"digraph",
30+
"directed graph",
31+
"connected components",
32+
"strongly connected components",
33+
"min cut",
34+
"max flow",
35+
"dijkstra",
36+
"bellman-ford",
37+
"minimum spanning tree",
38+
"depth first search",
39+
"breadth first search",
40+
"directed cycles",
41+
"topological sort",
42+
"ford-fulkerson",
43+
"prim",
44+
"kruskal"
45+
],
46+
"dependencies": {
47+
48+
},
49+
"devDependencies": {
50+
"chai": "^3.5.0",
51+
"coveralls": "^2.13.1",
52+
"grunt": "^1.0.1",
53+
"grunt-contrib-uglify": "^3.0.0",
54+
"grunt-eslint": "^19.0.0",
55+
"grunt-mocha-test": "^0.13.2",
56+
"istanbul": "^0.4.5",
57+
"mocha": "^3.4.1"
58+
},
59+
"bugs": {
60+
"url": "https://github.com/chen0040/js-graph-algorithms/issues"
61+
},
62+
"homepage": "https://github.com/chen0040/js-graph-algorithms#readme"
63+
}

src/jsgraphs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var jsgraphs = jsgraphs || {};
2+
3+
(function(jss){
4+
var Graph = function () {
5+
6+
};
7+
8+
jss.Graph = Graph;
9+
10+
})(jsgraphs);
11+
12+
if(module) {
13+
module.exports = jsgraphs;
14+
}

test/chi-square-distribution-spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var expect = require("chai").expect;
2+
var jsgraphs = require("../src/jsgraphs");
3+
4+
describe("Create chi square distribution", function() {
5+
describe("default constructor", function() {
6+
var distribution = new jsgraphs.ChiSquareDistribution(20);
7+
it("has df of 10.00", function() {
8+
expect(distribution.df).to.equal(20);
9+
10+
});
11+
});
12+
13+
describe('run cumulative probability', function(){
14+
var distribution = new jsgraphs.ChiSquareDistribution(20);
15+
it('has cumulativeProbability working', function(){
16+
for(var X=0.2; X < 10.0; X += 0.5){
17+
console.log(X + ': ' + distribution.cumulativeProbability(X));
18+
}
19+
});
20+
});
21+
22+
23+
});

test/f-distribution-spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var expect = require("chai").expect;
2+
var jsgraphs = require("../src/jsgraphs");
3+
4+
describe("Create f distribution", function() {
5+
describe("default constructor", function() {
6+
var distribution = new jsgraphs.FDistribution(10.0, 15.0);
7+
it("has df1 of 10.0 and df2 of 15.0", function() {
8+
expect(distribution.df1).to.equal(10.0);
9+
expect(distribution.df2).to.equal(15.0);
10+
11+
});
12+
});
13+
14+
describe('run cumulative probability', function(){
15+
var distribution = new jsgraphs.FDistribution(10.0, 15.0);
16+
it('has cumulativeProbability working', function(){
17+
for(var F=0.2; F < 10.0; F += 0.5){
18+
console.log(F + ': ' + distribution.cumulativeProbability(F));
19+
}
20+
});
21+
});
22+
23+
24+
});

test/normal-distribution-spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var expect = require("chai").expect;
2+
var jsgraphs = require("../src/jsgraphs");
3+
4+
describe("Create normal distribution", function() {
5+
describe("default constructor", function() {
6+
var distribution = new jsgraphs.NormalDistribution();
7+
it("has mean of 0.0 and sd of 1.0", function() {
8+
9+
console.log('lnconstant: ' + distribution.lnconstant);
10+
expect(distribution.mean).to.equal(0.0);
11+
expect(distribution.sd).to.equal(1.0);
12+
});
13+
14+
it("has 50% cumulative area at Z = 0", function(){
15+
expect(distribution.cumulativeProbability(0.0)).to.above(0.4999);
16+
expect(distribution.cumulativeProbability(0.0)).to.below(0.5001);
17+
});
18+
19+
it("has Z = 0 at 50%", function(){
20+
expect(distribution.invCumulativeProbability(0.5)).to.equal(0.0);
21+
});
22+
});
23+
24+
describe("Constructor with arguments", function() {
25+
it("has user-defined mean and sd", function() {
26+
var distribution = new jsgraphs.NormalDistribution(5.0, 12.0);
27+
expect(distribution.mean).to.equal(5.0);
28+
expect(distribution.sd).to.equal(12.0);
29+
});
30+
});
31+
});

test/t-distribution-spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var expect = require("chai").expect;
2+
var jsgraphs = require("../src/jsgraphs");
3+
4+
describe("Create t distribution", function() {
5+
describe("default constructor", function() {
6+
var distribution = new jsgraphs.TDistribution(10.0);
7+
it("has df of 10.0", function() {
8+
expect(distribution.df).to.equal(10.0);
9+
10+
});
11+
});
12+
13+
describe('run cumulative probability', function(){
14+
var distribution = new jsgraphs.TDistribution(10);
15+
it('has probability of 0.5 at t_df = 0', function(){
16+
expect(distribution.cumulativeProbability(0.0)).to.equal(0.5);
17+
});
18+
it('has t_df = 0 with probability of 0.5', function(){
19+
expect(distribution.invCumulativeProbability(0.5)).to.above(-0.001);
20+
expect(distribution.invCumulativeProbability(0.5)).to.below(+0.001);
21+
});
22+
it('should run correctly and ascendingly for Z on range p = 0 to p = 1.0', function(){
23+
var prevZ = -10000000;
24+
for(var p = 0.0; p < 1.0; p += 0.01) {
25+
var Z = distribution.invCumulativeProbability(p);
26+
expect(Z).to.above(prevZ);
27+
prevZ = Z;
28+
}
29+
})
30+
});
31+
32+
33+
});

0 commit comments

Comments
 (0)