Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Conversions: Add missing units (POWER) (#4185)
Browse files Browse the repository at this point in the history
* Add power custom unit and some tests

* Update triggering

* Fix spec

* Add missing comma

* Amend symbols

* Fix specs

* Fix kilowatt symbol

* Use unit value from yml file

* Amend units
  • Loading branch information
futtetennista authored and pjhampton committed May 15, 2017
1 parent 1ce7de6 commit 479aaa3
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
18 changes: 16 additions & 2 deletions share/goodie/conversions/conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ DDH.conversions = DDH.conversions || {};
{name: 'GB', factor: '1000000000 B'},
{name: 'TB', factor: '1000 GB'},
{name: 'PB', factor: '1000 TB'},

// CUSTOM POWER UNIT
{name: 'kilowatt', factor: '1000 watt'},
{name: 'megawatt', factor: '1000 kilowatt'},
{name: 'gigawatt', factor: '1000 megawatt'},
{name: 'terawatt', factor: '1000 gigawatt'},
{name: 'petawatt', factor: '1000 terawatt'},
{name: 'exawatt', factor: '1000 petawatt'},

// CUSTOM FORCE UNITS
{name: 'kilonewton', factor: '1000 newton'},
Expand Down Expand Up @@ -367,8 +375,14 @@ DDH.conversions = DDH.conversions || {};
power: {
name: "Power",
units: [
{ symbol: 'watt', name: 'Watt' },
{ symbol: 'hp', name: 'HP' }
{ symbol: 'watt', name: 'Watt'},
{ symbol: 'hp', name: 'HP' },
{ symbol: 'kilowatt', name: 'Kilowatt' },
{ symbol: 'megawatt', name: 'Megawatt' },
{ symbol: 'gigawatt', name: 'Gigawatt' },
{ symbol: 'terawatt', name: 'Terawatt' },
{ symbol: 'petawatt', name: 'Petawatt' },
{ symbol: 'exawatt', name: 'Exawatt' },
],
defaults: ['watt', 'hp']
},
Expand Down
42 changes: 42 additions & 0 deletions share/goodie/conversions/triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,48 @@ type: power
unit: watt
symbols: [W]
---
aliases:
- kilowatt
- kilowatts
type: power
unit: kilowatt
symbols: [kW]
---
aliases:
- megawatt
- megawatts
type: power
unit: megawatt
symbols: [MW]
---
aliases:
- gigawatt
- gigawatts
type: power
unit: gigawatt
symbols: [GW]
---
aliases:
- terawatt
- terawatts
type: power
unit: terawatt
symbols: [TW]
---
aliases:
- petawatt
- petawatts
type: power
unit: petawatt
symbols: [PW]
---
aliases:
- exawatt
- exawatts
type: power
unit: exawatt
symbols: [EW]
---
aliases:
- metric horsepowers
- mhp
Expand Down
35 changes: 34 additions & 1 deletion spec/conversions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,39 @@ describe("Conversion of Custom Units", function() {
var conversion = stripUnit(math.eval("6543kilocalorie to kilojoule"));
expect(conversion).toEqual("27375.912");
});

/**
* CUSTOM POWER UNITS
*/
it("should convert watt to kilowatt", function() {
var conversion = stripUnit(math.eval("12345watt to kilowatt"));
expect(conversion).toEqual("12.345");
});

it("should convert watt to megawatt", function() {
var conversion = stripUnit(math.eval("12345000watt to megawatt"));
expect(conversion).toEqual("12.345");
});

it("should convert gigawatt to kilowatt", function() {
var conversion = stripUnit(math.eval("12345gigawatt to kilowatt"));
expect(conversion).toEqual("1.2345e+10");
});

it("should convert terawatt to gigawatt", function() {
var conversion = stripUnit(math.eval("12345terawatt to gigawatt"));
expect(conversion).toEqual("1.2345e+7");
});

it("should convert terawatt to petawatt", function() {
var conversion = stripUnit(math.eval("12345000terawatt to petawatt"));
expect(conversion).toEqual("12345");
});

it("should convert petawatt to exawatt", function() {
var conversion = stripUnit(math.eval("12345petawatt to exawatt"));
expect(conversion).toEqual("12.345");
});

/**
* CUSTOM FORCE UNITS
Expand Down Expand Up @@ -177,5 +210,5 @@ describe("Conversion of Custom Units", function() {
var conversion = stripUnit(math.eval("50metrictonforce to kilogramforce"));
expect(conversion).toEqual("50000");
});

});
9 changes: 9 additions & 0 deletions t/Conversions.t
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,14 @@ ddg_goodie_test(
physical_quantity => 'area'
})
),
'1000 watts to kilowatts' => test_zci(
'', structured_answer => make_answer({
raw_input => '1000',
from_unit => 'watt',
to_unit => 'kilowatt',
physical_quantity => 'power'
})
),
'fortnight to days' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
Expand Down Expand Up @@ -1561,6 +1569,7 @@ ddg_goodie_test(
physical_quantity => 'frequency'
})
),

# natural language queries
'unit converter' => test_zci(
'',
Expand Down

0 comments on commit 479aaa3

Please sign in to comment.