From c5314c2cd725d396af773d34a70c2cd970bf8c3d Mon Sep 17 00:00:00 2001 From: Simone Conti Date: Wed, 22 Mar 2017 17:19:10 -0700 Subject: [PATCH] [IMPROVEMENT] Add apparent power definition (VA) Signed-off-by: Simone Conti --- lib/definitions/apparentPower.js | 49 ++++++++++++++++++++++++ lib/index.js | 1 + test/apparentPower.js | 65 ++++++++++++++++++++++++++++++++ test/measures.js | 2 +- test/possibilities.js | 13 ++++++- 5 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 lib/definitions/apparentPower.js create mode 100644 test/apparentPower.js diff --git a/lib/definitions/apparentPower.js b/lib/definitions/apparentPower.js new file mode 100644 index 00000000..58d35c6f --- /dev/null +++ b/lib/definitions/apparentPower.js @@ -0,0 +1,49 @@ +var apparentPower; + +apparentPower = { + VA: { + name: { + singular: 'Volt-Ampere' + , plural: 'Volt-Amperes' + } + , to_anchor: 1 + } +, mVA: { + name: { + singular: 'Millivolt-Ampere' + , plural: 'Millivolt-Amperes' + } + , to_anchor: .001 + } +, kVA: { + name: { + singular: 'Kilovolt-Ampere' + , plural: 'Kilovolt-Amperes' + } + , to_anchor: 1000 + } +, MVA: { + name: { + singular: 'Megavolt-Ampere' + , plural: 'Megavolt-Amperes' + } + , to_anchor: 1000000 + } +, GVA: { + name: { + singular: 'Gigavolt-Ampere' + , plural: 'Gigavolt-Amperes' + } + , to_anchor: 1000000000 + } +}; + +module.exports = { + metric: apparentPower +, _anchors: { + metric: { + unit: 'VA' + , ratio: 1 + } + } +}; diff --git a/lib/index.js b/lib/index.js index cd9352ec..af04a7cf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,6 +17,7 @@ var convert , voltage: require('./definitions/voltage') , power: require('./definitions/power') , reactivePower: require('./definitions/reactivePower') + , apparentPower: require('./definitions/apparentPower') } , Converter; diff --git a/test/apparentPower.js b/test/apparentPower.js new file mode 100644 index 00000000..2145378a --- /dev/null +++ b/test/apparentPower.js @@ -0,0 +1,65 @@ +var convert = require('../lib') + , assert = require('assert') + , tests = {}; + +tests['VA to VA'] = function () { + assert.strictEqual( convert(1).from('VA').to('VA') , 1); +}; + +tests['mVA to mVA'] = function () { + assert.strictEqual( convert(1).from('mVA').to('mVA') , 1); +}; + +tests['kVA to kVA'] = function () { + assert.strictEqual( convert(1).from('kVA').to('kVA') , 1); +}; + +tests['MVA to MVA'] = function () { + assert.strictEqual( convert(1).from('MVA').to('MVA') , 1); +}; + +tests['GVA to GVA'] = function () { + assert.strictEqual( convert(1).from('GVA').to('GVA') , 1); +}; + +tests['VA to mVA'] = function () { + assert.strictEqual( convert(1).from('VA').to('mVA') , 1000); +}; + +tests['VA to kVA'] = function () { + assert.strictEqual( convert(1).from('VA').to('kVA') , 0.001); +}; + +tests['VA to MVA'] = function () { + assert.strictEqual( convert(1).from('VA').to('MVA') , 0.000001); +}; + +tests['VA to GVA'] = function () { + assert.strictEqual( convert(1).from('VA').to('GVA') , 0.000000001); +}; + +tests['GVA to mVA'] = function () { + assert.strictEqual( convert(1).from('GVA').to('mVA'), 1000000000000); +} + +tests['MVA to mVA'] = function () { + assert.strictEqual( convert(1).from('MVA').to('mVA'), 1000000000); +} + +tests['kVA to mVA'] = function () { + assert.strictEqual( convert(1).from('kVA').to('mVA'), 1000000); +} + +tests['mVA to kVA'] = function () { + assert.strictEqual( convert(1).from('mVA').to('kVA'), 0.000001); +} + +tests['mVA to VA'] = function () { + assert.strictEqual( convert(1).from('mVA').to('VA'), 0.001); +} + +tests['kVA to VA'] = function () { + assert.strictEqual( convert(1).from('kVA').to('VA'), 1000); +} + +module.exports = tests; diff --git a/test/measures.js b/test/measures.js index 6a14292c..698047a0 100644 --- a/test/measures.js +++ b/test/measures.js @@ -4,7 +4,7 @@ var convert = require('../lib') tests['measures'] = function () { var actual = convert().measures() - , expected = [ 'length', 'area', 'mass', 'volume', 'each', 'temperature', 'time', 'digital', 'partsPer', 'speed', 'pressure', 'current', 'voltage', 'power', 'reactivePower' ]; + , expected = [ 'length', 'area', 'mass', 'volume', 'each', 'temperature', 'time', 'digital', 'partsPer', 'speed', 'pressure', 'current', 'voltage', 'power', 'reactivePower', 'apparentPower' ]; assert.deepEqual(actual, expected); }; diff --git a/test/possibilities.js b/test/possibilities.js index 366c7875..7270da3d 100644 --- a/test/possibilities.js +++ b/test/possibilities.js @@ -106,6 +106,12 @@ tests['reactive power possibilities'] = function() { assert.deepEqual(actual.sort(), expected.sort()) }; +tests['apparent power possibilities'] = function() { + var actual = convert().possibilities('apparentPower') + , expected = [ 'VA', 'mVA', 'kVA', 'MVA', 'GVA']; + assert.deepEqual(actual.sort(), expected.sort()) +}; + tests['all possibilities'] = function () { var actual = convert().possibilities() // Please keep these sorted for maintainability @@ -145,6 +151,7 @@ tests['all possibilities'] = function () { , 'g' , 'gal' , 'glas' + , 'GVA' , 'GVAR' , 'GW' , 'h' @@ -167,8 +174,9 @@ tests['all possibilities'] = function () { , 'krm' , 'ksi' , 'kV' - , 'kW' + , 'kVA' , 'kVAR' + , 'kW' , 'l' , 'lb' , 'm' @@ -191,6 +199,8 @@ tests['all possibilities'] = function () { , 'msk' , 'mu' , 'mV' + , 'mVA' + , 'MVA' , 'mVAR' , 'MVAR' , 'mW' @@ -209,6 +219,7 @@ tests['all possibilities'] = function () { , 'tsk' , 'tsp' , 'V' + , 'VA' , 'VAR' , 'W' , 'week'