From 1e539e2014b1834e2f929732f7a83f090984c217 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Thu, 18 Aug 2016 15:23:37 -0400 Subject: [PATCH] Add a build step --- .gitignore | 7 +- .npmignore | 2 + index.js | 1 - package.json | 13 +++- {lib => src}/index.js | 0 test/index.js | 170 +++++++++++++++++++++--------------------- 6 files changed, 100 insertions(+), 93 deletions(-) create mode 100644 .npmignore delete mode 100644 index.js rename {lib => src}/index.js (100%) diff --git a/.gitignore b/.gitignore index 057a577..fe95a8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -node_modules -temp.js -temp \ No newline at end of file +node_modules +temp.js +temp +lib diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..281df39 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +src +test diff --git a/index.js b/index.js deleted file mode 100644 index 6b1804c..0000000 --- a/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./lib/index.js'); \ No newline at end of file diff --git a/package.json b/package.json index 4bf5e6f..6fab1c7 100644 --- a/package.json +++ b/package.json @@ -16,13 +16,18 @@ }, "dependencies": {}, "devDependencies": { - "should": "", - "mocha": "" + "babel-preset-es2015": "^6.13.2", + "babelify": "^7.3.0", + "browserify": "^13.1.0", + "mocha": "^3.0.2", + "should": "^11.1.0" }, "scripts": { - "test": "make test" + "test": "make test", + "build": "mkdir -p lib && browserify src/index.js -t [ babelify --presets [ es2015 ] ] > lib/index.js", + "prepublish": "npm run build && npm run test" }, - "main": "index", + "main": "lib/index", "directories": { "test": "test" }, diff --git a/lib/index.js b/src/index.js similarity index 100% rename from lib/index.js rename to src/index.js diff --git a/test/index.js b/test/index.js index 97c56c5..1751131 100644 --- a/test/index.js +++ b/test/index.js @@ -1,85 +1,85 @@ -"use strict"; - -/** - * Module dependencies. - */ - -let Controller = require('../') - , should = require('should') - , assert = require('assert') - ; - -/** - * Tests - */ -describe('pid-controller', () => { - - let options = { - k_p: 0.5, - k_i: 0.1, - k_d: 0.2, - dt: 1 - }; - - // Create the controller - let ctr = new Controller(options.k_p, options.k_i, options.k_d, options.dt); - - it('should have set the coefficient', () => { - ctr.k_p.should.equal(options.k_p); - ctr.k_i.should.equal(options.k_i); - ctr.k_d.should.equal(options.k_d); - ctr.dt.should.equal(options.dt); - }); - - it('should have set the coefficient from an options object', () => { - let ctr = new Controller(options); - - ctr.k_p.should.equal(options.k_p); - ctr.k_i.should.equal(options.k_i); - ctr.k_d.should.equal(options.k_d); - ctr.dt.should.equal(options.dt); - }); - - it('should set the target', () => { - let v = 120; // 120km/h - ctr.setTarget(v); - ctr.target.should.equal(v); - }); - - it('should return the correction', () => { - let vt = 110; // current speed - let correction = ctr.update(vt); - correction.should.equal(8); - }); - - it('should reset the controller', () => { - ctr.reset(); - ctr.sumError.should.equal(0); - ctr.lastError.should.equal(0); - ctr.lastTime.should.equal(0); - }); - - it('should return the correction for the given update interval', () => { - ctr.dt = 2; // 2 seconds between updates - let correction = ctr.update(115); - correction.should.equal(4); - ctr.dt = options.dt; // Reset dt - }); - - it('should return the correction with sumError <= i_max', () => { - let ctr = new Controller(options); - ctr.i_max = 5; // sumError will be 10 - ctr.setTarget(120); - let correction = ctr.update(110); - correction.should.equal(7.5); - ctr.sumError.should.be.belowOrEqual(ctr.i_max); - }); - - it('should return a null correction', () => { - let ctr = new Controller(0, 0, 0); - ctr.setTarget(120); - let correction = ctr.update(110); - correction.should.equal(0); - }); - -}); +"use strict"; + +/** + * Module dependencies. + */ + +let Controller = require('../src') + , should = require('should') + , assert = require('assert') + ; + +/** + * Tests + */ +describe('pid-controller', () => { + + let options = { + k_p: 0.5, + k_i: 0.1, + k_d: 0.2, + dt: 1 + }; + + // Create the controller + let ctr = new Controller(options.k_p, options.k_i, options.k_d, options.dt); + + it('should have set the coefficient', () => { + ctr.k_p.should.equal(options.k_p); + ctr.k_i.should.equal(options.k_i); + ctr.k_d.should.equal(options.k_d); + ctr.dt.should.equal(options.dt); + }); + + it('should have set the coefficient from an options object', () => { + let ctr = new Controller(options); + + ctr.k_p.should.equal(options.k_p); + ctr.k_i.should.equal(options.k_i); + ctr.k_d.should.equal(options.k_d); + ctr.dt.should.equal(options.dt); + }); + + it('should set the target', () => { + let v = 120; // 120km/h + ctr.setTarget(v); + ctr.target.should.equal(v); + }); + + it('should return the correction', () => { + let vt = 110; // current speed + let correction = ctr.update(vt); + correction.should.equal(8); + }); + + it('should reset the controller', () => { + ctr.reset(); + ctr.sumError.should.equal(0); + ctr.lastError.should.equal(0); + ctr.lastTime.should.equal(0); + }); + + it('should return the correction for the given update interval', () => { + ctr.dt = 2; // 2 seconds between updates + let correction = ctr.update(115); + correction.should.equal(4); + ctr.dt = options.dt; // Reset dt + }); + + it('should return the correction with sumError <= i_max', () => { + let ctr = new Controller(options); + ctr.i_max = 5; // sumError will be 10 + ctr.setTarget(120); + let correction = ctr.update(110); + correction.should.equal(7.5); + ctr.sumError.should.be.belowOrEqual(ctr.i_max); + }); + + it('should return a null correction', () => { + let ctr = new Controller(0, 0, 0); + ctr.setTarget(120); + let correction = ctr.update(110); + correction.should.equal(0); + }); + +});