Conversions: Fixed spelling of cmH2O and Cups, Fixes FE-Tests (#4160)
* Fixed spelling of cmH2O * Add working tests. * Try jasmine-node. * Added init package file. * Install mathjs. * Refactored custom units. * Finish up tests. * Update package.json. * Fix cups spelling.master
parent
54533e63cf
commit
512d0c49e8
|
@ -16,7 +16,8 @@ before_install:
|
||||||
- git config --global user.name "Dist Zilla Plugin TravisCI"
|
- git config --global user.name "Dist Zilla Plugin TravisCI"
|
||||||
- git config --global user.email $HOSTNAME":not-for-mail@travis-ci.org"
|
- git config --global user.email $HOSTNAME":not-for-mail@travis-ci.org"
|
||||||
install:
|
install:
|
||||||
- npm install -g uglify-js handlebars mathjs jasmine
|
- npm install -g uglify-js handlebars jasmine-node
|
||||||
|
- npm install mathjs
|
||||||
- cpanm --quiet --notest Dist::Zilla
|
- cpanm --quiet --notest Dist::Zilla
|
||||||
- dzil authordeps | grep -ve '^\W' | xargs -n 5 -P 10 cpanm --quiet --notest --mirror http://www.cpan.org/ --mirror http://duckpan.org
|
- dzil authordeps | grep -ve '^\W' | xargs -n 5 -P 10 cpanm --quiet --notest --mirror http://www.cpan.org/ --mirror http://duckpan.org
|
||||||
- dzil listdeps | grep -ve '^\W' | cpanm --quiet --notest --mirror http://www.cpan.org/ --mirror http://duckpan.org
|
- dzil listdeps | grep -ve '^\W' | cpanm --quiet --notest --mirror http://www.cpan.org/ --mirror http://duckpan.org
|
||||||
|
@ -24,5 +25,5 @@ language: perl
|
||||||
perl:
|
perl:
|
||||||
- 5.16
|
- 5.16
|
||||||
script:
|
script:
|
||||||
- jasmine
|
- jasmine-node --test-dir spec/
|
||||||
- prove -lr -j1 t
|
- prove -lr -j1 t
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"name": "zeroclickinfo-goodies",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "DuckDuckGo Goodies - Perl Backed IAs",
|
||||||
|
"main": "",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/duckduckgo/zeroclickinfo-goodies.git"
|
||||||
|
},
|
||||||
|
"author": "DuckDuckGo",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/duckduckgo/zeroclickinfo-goodies/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/duckduckgo/zeroclickinfo-goodies#readme"
|
||||||
|
}
|
|
@ -42,24 +42,32 @@ DDH.conversions = DDH.conversions || {};
|
||||||
leftValue: "",
|
leftValue: "",
|
||||||
rightValue: "",
|
rightValue: "",
|
||||||
|
|
||||||
// custom units that are not supported by math.js
|
customUnits: [
|
||||||
setUpCustomUnits: function() {
|
|
||||||
|
|
||||||
// CUSTOM ENERGY UNITS
|
// CUSTOM ENERGY UNITS
|
||||||
math.createUnit('kilojoule', '1000 joules');
|
{name: 'kilojoule', factor: '1000 joules'},
|
||||||
math.createUnit('gramcalorie', '4.184 joules');
|
{name: 'gramcalorie', factor: '4.184 joules' },
|
||||||
math.createUnit('kilocalorie', '4184 joules');
|
{name: 'kilocalorie', factor: '4184 joules' },
|
||||||
|
|
||||||
// CUSTOM DIGITAL UNITS
|
// CUSTOM DIGITAL UNITS
|
||||||
math.createUnit('kbit', '1000 b');
|
{name: 'kbit', factor: '1000 b'},
|
||||||
math.createUnit('mbit', '1000000 b');
|
{name: 'mbit', factor: '1000000 b'},
|
||||||
math.createUnit('gbit', '1000000000 b');
|
{name: 'gbit', factor: '1000000000 b'},
|
||||||
math.createUnit('tbit', '1000000000000 b');
|
{name: 'tbit', factor: '1000000000000 b'},
|
||||||
math.createUnit('KB', '1000 B');
|
{name: 'KB', factor: '1000 B'},
|
||||||
math.createUnit('MB', '1000000 B');
|
{name: 'MB', factor: '1000000 B'},
|
||||||
math.createUnit('GB', '1000000000 B');
|
{name: 'GB', factor: '1000000000 B'},
|
||||||
math.createUnit('TB', '1000 GB');
|
{name: 'TB', factor: '1000 GB'},
|
||||||
math.createUnit('PB', '1000 TB');
|
{name: 'PB', factor: '1000 TB'}
|
||||||
|
],
|
||||||
|
|
||||||
|
// custom units that are not supported by math.js
|
||||||
|
setUpCustomUnits: function() {
|
||||||
|
for (var i = 0 ; i < this.customUnits.length ; i++) {
|
||||||
|
math.createUnit(
|
||||||
|
this.customUnits[i].name,
|
||||||
|
this.customUnits[i].factor
|
||||||
|
)
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
setValues: function() {
|
setValues: function() {
|
||||||
|
@ -320,7 +328,7 @@ DDH.conversions = DDH.conversions || {};
|
||||||
{ symbol: 'torr', name: 'Torr' },
|
{ symbol: 'torr', name: 'Torr' },
|
||||||
{ symbol: 'mmHg', name: 'mmHg' },
|
{ symbol: 'mmHg', name: 'mmHg' },
|
||||||
{ symbol: 'mmH2O', name: 'mmH2O' },
|
{ symbol: 'mmH2O', name: 'mmH2O' },
|
||||||
{ symbol: 'cmH20', name: 'cmH20' },
|
{ symbol: 'cmH2O', name: 'cmH2O' },
|
||||||
{ symbol: 'bar', name: 'Bars' },
|
{ symbol: 'bar', name: 'Bars' },
|
||||||
],
|
],
|
||||||
defaults: ['Pa', 'psi']
|
defaults: ['Pa', 'psi']
|
||||||
|
|
|
@ -506,7 +506,7 @@ aliases:
|
||||||
- cups
|
- cups
|
||||||
- cup
|
- cup
|
||||||
type: volume
|
type: volume
|
||||||
unit: cup
|
unit: cups
|
||||||
---
|
---
|
||||||
aliases:
|
aliases:
|
||||||
- metric tsp
|
- metric tsp
|
||||||
|
|
|
@ -1,74 +1,93 @@
|
||||||
GLOBAL.DDH = {};
|
GLOBAL.DDH = {};
|
||||||
|
|
||||||
var math = require("mathjs");
|
var math = require('mathjs');
|
||||||
|
|
||||||
var Converter = require("../share/goodie/conversions/conversions.js");
|
var Converter = require("../share/goodie/conversions/conversions.js");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* conversions_spec.js
|
||||||
|
*
|
||||||
|
* This file is for testing custom units defined in Converter.customUnits
|
||||||
|
*/
|
||||||
|
|
||||||
|
// custom units that are not supported by math.js
|
||||||
|
function setUpCustomUnits() {
|
||||||
|
for (var i = 0 ; i < Converter.customUnits.length ; i++) {
|
||||||
|
math.createUnit(
|
||||||
|
Converter.customUnits[i].name,
|
||||||
|
Converter.customUnits[i].factor
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// removes the unit
|
||||||
|
function stripUnit( string ) {
|
||||||
|
return string.toString().split(" ")[0];
|
||||||
|
}
|
||||||
|
|
||||||
describe("Conversion of Custom Units", function() {
|
describe("Conversion of Custom Units", function() {
|
||||||
|
|
||||||
// set up the custom units
|
setUpCustomUnits();
|
||||||
Converter.setUpCustomUnits();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CUSTOM DIGITAL UNITS
|
* CUSTOM DIGITAL UNITS
|
||||||
*/
|
*/
|
||||||
it("should convert gb to mb", function() {
|
it("should convert gb to mb", function() {
|
||||||
var conversion = Converter.eval("2GB to MB");
|
var conversion = stripUnit(math.eval("2GB to MB"));
|
||||||
expect(conversion).toEqual("2000");
|
expect(conversion).toEqual("2000");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert TB to MB", function() {
|
it("should convert TB to MB", function() {
|
||||||
var conversion = Converter.eval("8TB to MB");
|
var conversion = stripUnit(math.eval("8TB to MB"));
|
||||||
expect(conversion).toEqual("8e+6");
|
expect(conversion).toEqual("8e+6");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert GB to TB", function() {
|
it("should convert GB to TB", function() {
|
||||||
var conversion = Converter.eval("1000GB to TB");
|
var conversion = stripUnit(math.eval("1000GB to TB"));
|
||||||
expect(conversion).toEqual("1");
|
expect(conversion).toEqual("1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert GB to TB", function() {
|
it("should convert GB to TB", function() {
|
||||||
var conversion = Converter.eval("100GB to TB");
|
var conversion = stripUnit(math.eval("100GB to TB"));
|
||||||
expect(conversion).toEqual("0.1");
|
expect(conversion).toEqual("0.1");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert TB to GB", function() {
|
it("should convert TB to GB", function() {
|
||||||
var conversion = Converter.eval("1TB to GB");
|
var conversion = stripUnit(math.eval("1TB to GB"));
|
||||||
expect(conversion).toEqual("1000");
|
expect(conversion).toEqual("1000");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert MB to TB", function() {
|
it("should convert MB to TB", function() {
|
||||||
var conversion = Converter.eval("3500MB to TB");
|
var conversion = stripUnit(math.eval("3500MB to TB"));
|
||||||
expect(conversion).toEqual("0.0035");
|
expect(conversion).toEqual("0.0035");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert PB to TB", function() {
|
it("should convert PB to TB", function() {
|
||||||
var conversion = Converter.eval("5PB to TB");
|
var conversion = stripUnit(math.eval("5PB to TB"));
|
||||||
expect(conversion).toEqual("5000");
|
expect(conversion).toEqual("5000");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert PB to GB", function() {
|
it("should convert PB to GB", function() {
|
||||||
var conversion = Converter.eval("7PB to GB");
|
var conversion = stripUnit(math.eval("7PB to GB"));
|
||||||
expect(conversion).toEqual("7e+6");
|
expect(conversion).toEqual("7e+6");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert PB to GB", function() {
|
it("should convert PB to GB", function() {
|
||||||
var conversion = Converter.eval("7PB to GB");
|
var conversion = stripUnit(math.eval("7PB to GB"));
|
||||||
expect(conversion).toEqual("7e+6");
|
expect(conversion).toEqual("7e+6");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert MB to gbits", function() {
|
it("should convert MB to gbits", function() {
|
||||||
var conversion = Converter.eval("6500MB to gbit");
|
var conversion = stripUnit(math.eval("6500MB to gbit"));
|
||||||
expect(conversion).toEqual("52");
|
expect(conversion).toEqual("52");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert mbits to gbits", function() {
|
it("should convert mbits to gbits", function() {
|
||||||
var conversion = Converter.eval("100000mbit to gbit");
|
var conversion = stripUnit(math.eval("100000mbit to gbit"));
|
||||||
expect(conversion).toEqual("100");
|
expect(conversion).toEqual("100");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert tbits to mbits", function() {
|
it("should convert tbits to mbits", function() {
|
||||||
var conversion = Converter.eval(".5tbit to mbit");
|
var conversion = stripUnit(math.eval(".5tbit to mbit"));
|
||||||
expect(conversion).toEqual("5e+5");
|
expect(conversion).toEqual("5e+5");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -76,23 +95,23 @@ describe("Conversion of Custom Units", function() {
|
||||||
* CUSTOM ENERGY UNITS
|
* CUSTOM ENERGY UNITS
|
||||||
*/
|
*/
|
||||||
it("should convert joules to kilojoules", function() {
|
it("should convert joules to kilojoules", function() {
|
||||||
var conversion = Converter.eval("8888joules to kilojoule");
|
var conversion = stripUnit(math.eval("8888joules to kilojoule"));
|
||||||
expect(conversion).toEqual("8.888");
|
expect(conversion).toEqual("8.888");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert joules to kilojoules", function() {
|
it("should convert joules to kilojoules", function() {
|
||||||
var conversion = Converter.eval("34311joules to kilojoule");
|
var conversion = stripUnit(math.eval("34311joules to kilojoule"));
|
||||||
expect(conversion).toEqual("34.311");
|
expect(conversion).toEqual("34.311");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert gram calories to kilojoules", function() {
|
it("should convert gram calories to kilojoules", function() {
|
||||||
var conversion = Converter.eval("34311323gramcalorie to kilojoule");
|
var conversion = stripUnit(math.eval("34311323gramcalorie to kilojoule"));
|
||||||
expect(conversion).toEqual("1.43559e+5");
|
expect(conversion).toEqual("1.43558575432e+5");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert kilocalorie to kilojoules", function() {
|
it("should convert kilocalorie to kilojoules", function() {
|
||||||
var conversion = Converter.eval("6543kilocalorie to kilojoule");
|
var conversion = stripUnit(math.eval("6543kilocalorie to kilojoule"));
|
||||||
expect(conversion).toEqual("27375.9");
|
expect(conversion).toEqual("27375.912");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue