Skip to content

Commit

Permalink
[IMPROVEMENT] Add apparent power definition (VA)
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Conti <s.conti@itnok.com>
  • Loading branch information
itnok committed Mar 23, 2017
1 parent 75c11b0 commit c5314c2
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
49 changes: 49 additions & 0 deletions 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
}
}
};
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -17,6 +17,7 @@ var convert
, voltage: require('./definitions/voltage')
, power: require('./definitions/power')
, reactivePower: require('./definitions/reactivePower')
, apparentPower: require('./definitions/apparentPower')
}
, Converter;

Expand Down
65 changes: 65 additions & 0 deletions 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;
2 changes: 1 addition & 1 deletion test/measures.js
Expand Up @@ -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);
};

Expand Down
13 changes: 12 additions & 1 deletion test/possibilities.js
Expand Up @@ -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
Expand Down Expand Up @@ -145,6 +151,7 @@ tests['all possibilities'] = function () {
, 'g'
, 'gal'
, 'glas'
, 'GVA'
, 'GVAR'
, 'GW'
, 'h'
Expand All @@ -167,8 +174,9 @@ tests['all possibilities'] = function () {
, 'krm'
, 'ksi'
, 'kV'
, 'kW'
, 'kVA'
, 'kVAR'
, 'kW'
, 'l'
, 'lb'
, 'm'
Expand All @@ -191,6 +199,8 @@ tests['all possibilities'] = function () {
, 'msk'
, 'mu'
, 'mV'
, 'mVA'
, 'MVA'
, 'mVAR'
, 'MVAR'
, 'mW'
Expand All @@ -209,6 +219,7 @@ tests['all possibilities'] = function () {
, 'tsk'
, 'tsp'
, 'V'
, 'VA'
, 'VAR'
, 'W'
, 'week'
Expand Down

0 comments on commit c5314c2

Please sign in to comment.