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

Commit

Permalink
Conversions: Adds missing units for Force conversion type (#4197)
Browse files Browse the repository at this point in the history
* adds kilonewton unit to force type

* adds remaining units

* formats the file and  comma correction

* fixing the test

* fixing the test 2

* fixing the test part 3

* fixing the test part 4 perhaps the final one

* fixing the test part 4 surely the final one

* fixing the test part 4 definetly the final one
  • Loading branch information
adityatandon007 authored and moollaza committed May 12, 2017
1 parent aed0d1a commit 07d1553
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 47 deletions.
100 changes: 56 additions & 44 deletions share/goodie/conversions/conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ DDH.conversions = DDH.conversions || {};

// CUSTOM ENERGY UNITS
{name: 'kilojoule', factor: '1000 joules'},
{name: 'gramcalorie', factor: '4.184 joules' },
{name: 'kilocalorie', factor: '4184 joules' },
{name: 'gramcalorie', factor: '4.184 joules'},
{name: 'kilocalorie', factor: '4184 joules'},

// CUSTOM DIGITAL UNITS
{name: 'kbit', factor: '1000 b'},
Expand All @@ -66,7 +66,14 @@ DDH.conversions = DDH.conversions || {};
{name: 'MB', factor: '1000000 B'},
{name: 'GB', factor: '1000000000 B'},
{name: 'TB', factor: '1000 GB'},
{name: 'PB', factor: '1000 TB'}
{name: 'PB', factor: '1000 TB'},

// CUSTOM FORCE UNITS
{name: 'kilonewton', factor: '1000 newton'},
{name: 'gramforce', factor: '0.00980665 newton'},
{name: 'ounceforce', factor: '0.0625 poundforce'},
{name: 'kilogramforce', factor: '1000 gramforce'},
{name: 'metrictonforce', factor: '1000 kilogramforce'}
],

// custom units that are not supported by math.js
Expand Down Expand Up @@ -196,13 +203,13 @@ DDH.conversions = DDH.conversions || {};
{ symbol: 'sqmi', name: 'Square Mile' },
{ symbol: 'acre', name: 'Acre' },
{ symbol: 'hectare', name: 'Hectare' },
{ symbol: 'barn', name: 'Barn'},
{ symbol: 'rood', name: 'Rood'},
{ symbol: 'squarerod', name: 'Square Rod'},
{ symbol: 'are', name: 'Are'},
{ symbol: 'sqdecimeter', name: 'Square Decimeter'},
{ symbol: 'sqcentimeter', name: 'Square Centimeter'},
{ symbol: 'sqmillimeter', name: 'Square Millimeter'},
{ symbol: 'barn', name: 'Barn' },
{ symbol: 'rood', name: 'Rood' },
{ symbol: 'squarerod', name: 'Square Rod' },
{ symbol: 'are', name: 'Are' },
{ symbol: 'sqdecimeter', name: 'Square Decimeter' },
{ symbol: 'sqcentimeter', name: 'Square Centimeter' },
{ symbol: 'sqmillimeter', name: 'Square Millimeter' },
],
defaults: ['m2', 'sqin']
},
Expand All @@ -212,14 +219,14 @@ DDH.conversions = DDH.conversions || {};
{ symbol: 'b', name: 'Bit' },
{ symbol: 'B', name: 'Byte' },
{ symbol: 'kbit', name: 'Kilobit' },
{ symbol: 'mbit', name: 'Megabit'},
{ symbol: 'gbit', name: 'Gigabit'},
{ symbol: 'tbit', name: 'Terrabit'},
{ symbol: 'KB', name: 'Kilobyte'},
{ symbol: 'MB', name: 'Megabyte'},
{ symbol: 'GB', name: 'Gigabyte'},
{ symbol: 'TB', name: 'Terabyte'},
{ symbol: 'PB', name: 'Petabyte'},
{ symbol: 'mbit', name: 'Megabit' },
{ symbol: 'gbit', name: 'Gigabit' },
{ symbol: 'tbit', name: 'Terrabit' },
{ symbol: 'KB', name: 'Kilobyte' },
{ symbol: 'MB', name: 'Megabyte' },
{ symbol: 'GB', name: 'Gigabyte' },
{ symbol: 'TB', name: 'Terabyte' },
{ symbol: 'PB', name: 'Petabyte' },
],
defaults: ['b', 'B']
},
Expand All @@ -234,7 +241,7 @@ DDH.conversions = DDH.conversions || {};
{ symbol: 'hour', name: 'Hours' },
{ symbol: 'day', name: 'Days' },
{ symbol: 'week', name: 'Weeks' },
{ symbol: 'month', name: 'Months'},
{ symbol: 'month', name: 'Months' },
{ symbol: 'year', name: 'Years' },
{ symbol: 'decade', name: 'Decade' },
{ symbol: 'century', name: 'Century' },
Expand All @@ -247,37 +254,42 @@ DDH.conversions = DDH.conversions || {};
units: [
{ symbol: 'joule', name: 'Joule' },
{ symbol: 'kilojoule', name: 'Kilojoule' },
{ symbol: 'gramcalorie', name: 'Gram Calorie'},
{ symbol: 'kilocalorie', name: 'Kilo Calorie'},
{ symbol: 'gramcalorie', name: 'Gram Calorie' },
{ symbol: 'kilocalorie', name: 'Kilo Calorie' },
{ symbol: 'Wh', name: 'Watt Hour' },
{ symbol: 'erg', name: 'Erg' },
{ symbol: 'BTU', name: 'BTU'},
{ symbol: 'electronvolt', name: 'Electronvolt'},
{ symbol: 'BTU', name: 'BTU' },
{ symbol: 'electronvolt', name: 'Electronvolt' },
],
defaults: ['joule', 'Wh']
},
force: {
name: "Force",
units: [
{ symbol: 'newton', name: 'Newton' },
{ symbol: 'dyne', name: 'Dyne'},
{ symbol: 'poundforce', name: 'Pound Force'},
{ symbol: 'kip', name: 'Kip'},
{ symbol: 'newton', name: 'Newton' },
{ symbol: 'dyne', name: 'Dyne' },
{ symbol: 'poundforce', name: 'Pound Force' },
{ symbol: 'kip', name: 'Kip' },
{ symbol: 'kilonewton', name: 'Kilo Newton' },
{ symbol: 'gramforce', name: 'Gram Force' },
{ symbol: 'ounceforce', name: 'Ounce Force' },
{ symbol: 'kilogramforce', name: 'Kilogram Force' },
{ symbol: 'metrictonforce', name: 'Ton Force Metric' },
],
defaults: ['newton', 'dyne']
},
frequency: {
name: "Frequency",
units: [
{ symbol: 'microhertz', name: 'Microhertz' },
{ symbol: 'millihertz', name: 'Millihertz'},
{ symbol: 'hertz', name: 'Hertz'},
{ symbol: 'kilohertz', name: 'Kilohertz'},
{ symbol: 'megahertz', name: 'Megahertz'},
{ symbol: 'gigahertz', name: 'Gigahertz'},
{ symbol: 'terahertz', name: 'Terahertz'},
{ symbol: 'petahertz', name: 'Petahertz'},
{ symbol: 'exahertz', name: 'Exahertz'},
{ symbol: 'millihertz', name: 'Millihertz' },
{ symbol: 'hertz', name: 'Hertz' },
{ symbol: 'kilohertz', name: 'Kilohertz' },
{ symbol: 'megahertz', name: 'Megahertz' },
{ symbol: 'gigahertz', name: 'Gigahertz' },
{ symbol: 'terahertz', name: 'Terahertz' },
{ symbol: 'petahertz', name: 'Petahertz' },
{ symbol: 'exahertz', name: 'Exahertz' },
],
defaults: ['hertz', 'megahertz']
},
Expand All @@ -302,7 +314,7 @@ DDH.conversions = DDH.conversions || {};
{ symbol: 'link', name: 'Link' },
{ symbol: 'rod', name: 'Rod' },
{ symbol: 'angstrom', name: 'Angstrom' },
{ symbol: 'mil', name: 'Mil'}
{ symbol: 'mil', name: 'Mil' },
],
defaults: ['meter', 'cm']
},
Expand All @@ -314,13 +326,13 @@ DDH.conversions = DDH.conversions || {};
{ symbol: 'fluidounce', name: 'Fluid Ounce' },
{ symbol: 'gill', name: 'Gill' },
{ symbol: 'cup', name: 'Cup' },
{ symbol: 'pint', name: 'Pint'},
{ symbol: 'quart', name: 'Quart'},
{ symbol: 'gallon', name: 'Gallon'},
{ symbol: 'beerbarrel', name: 'Beerbarrel'},
{ symbol: 'oilbarrel', name: 'Oilbarrel'},
{ symbol: 'hogshead', name: 'Hogshead'},
{ symbol: 'drop', name: 'Drop'},
{ symbol: 'pint', name: 'Pint' },
{ symbol: 'quart', name: 'Quart' },
{ symbol: 'gallon', name: 'Gallon' },
{ symbol: 'beerbarrel', name: 'Beerbarrel' },
{ symbol: 'oilbarrel', name: 'Oilbarrel' },
{ symbol: 'hogshead', name: 'Hogshead' },
{ symbol: 'drop', name: 'Drop' },
],
defaults: ['minim', 'fluiddram']
},
Expand All @@ -345,7 +357,7 @@ DDH.conversions = DDH.conversions || {};
power: {
name: "Power",
units: [
{ symbol: 'watt', name: 'Watt'},
{ symbol: 'watt', name: 'Watt' },
{ symbol: 'hp', name: 'HP' }
],
defaults: ['watt', 'hp']
Expand Down
79 changes: 79 additions & 0 deletions share/goodie/conversions/triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,85 @@ aliases:
type: force
unit: poundforce
---
aliases:
- kilonewton
- kilonewtons
- kilo newton
- kilo newtons
- kilo-newton
- kilo-newtons
- kN
type: force
unit: kilonewton
symbols: [kN]
---
aliases:
- gramforce
- gram force
- gf
- gram-force
type: force
unit: gramforce
symbols: [gf]
---
aliases:
- ounceforce
- ounce force
- ounce-force
- ozf
type: force
unit: ounceforce
---
aliases:
- kilogramforce
- kilogram force
- kilo gram force
- kilogram-force
- kilo-gram force
- kilo-grams force
- kilograms force
- kilo grams force
- kilo-gram-force
- kgf
type: force
unit: kilogramforce
symbols: [kgf]
---
aliases:
- ton force metric
- tons force metric
- tonns force metric
- tonne force metric
- tonnes force metric
- ton-force metric
- tons-force metric
- tonns-force metric
- tonne-force metric
- tonnes-force metric
- metrictonforce
- metric ton force
- metric tons force
- metric tonns force
- metric tonne force
- metric tonnes force
- metric ton-force
- metric tons-force
- metric tonns-force
- metric tonne-force
- metric tonnes-force
- ton force
- tons force
- tonns force
- tonne force
- tonnes force
- ton-force
- tons-force
- tonns-force
- tonne-force
- tonnes-force
type: force
unit: metrictonforce
---
aliases:
- f
- farenheit
Expand Down
30 changes: 29 additions & 1 deletion spec/conversions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,33 @@ describe("Conversion of Custom Units", function() {
var conversion = stripUnit(math.eval("6543kilocalorie to kilojoule"));
expect(conversion).toEqual("27375.912");
});


/**
* CUSTOM FORCE UNITS
*/
it("should convert kilonewton to newton", function() {
var conversion = stripUnit(math.eval("22kilonewton to newton"));
expect(conversion).toEqual("22000");
});

it("should convert gramforce to newton", function() {
var conversion = stripUnit(math.eval("1100gramforce to newton"));
expect(conversion).toEqual("10.787315");
});

it("should convert ounceforce to poundforce", function() {
var conversion = stripUnit(math.eval("10ounceforce to poundforce"));
expect(conversion).toEqual("0.625");
});

it("should convert kilogramforce to gramforce", function() {
var conversion = stripUnit(math.eval("500kilogramforce to gramforce"));
expect(conversion).toEqual("5e+5");
});

it("should convert metrictonforce to kilogramforce", function() {
var conversion = stripUnit(math.eval("50metrictonforce to kilogramforce"));
expect(conversion).toEqual("50000");
});

});
43 changes: 41 additions & 2 deletions t/Conversions.t
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ ddg_goodie_test(
to_unit => 'celsius',
physical_quantity => 'temperature'
})
),,
),
'0 rankine in celsius' => test_zci(
'', structured_answer => make_answer({
raw_input => '0',
Expand Down Expand Up @@ -1465,7 +1465,46 @@ ddg_goodie_test(
physical_quantity => 'area'
})
),

'5 kilonewtons to newton' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
from_unit => 'kilonewton',
to_unit => 'newton',
physical_quantity => 'force'
})
),
'10 gram force to newton' => test_zci(
'', structured_answer => make_answer({
raw_input => '10',
from_unit => 'gramforce',
to_unit => 'newton',
physical_quantity => 'force'
})
),
'50 ounce-force to gram force' => test_zci(
'', structured_answer => make_answer({
raw_input => '50',
from_unit => 'ounceforce',
to_unit => 'gramforce',
physical_quantity => 'force'
})
),
'15 kilogram-force to gram-force' => test_zci(
'', structured_answer => make_answer({
raw_input => '15',
from_unit => 'kilogramforce',
to_unit => 'gramforce',
physical_quantity => 'force'
})
),
'5 metric tonne force to kilogram force' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
from_unit => 'metrictonforce',
to_unit => 'kilogramforce',
physical_quantity => 'force'
})
),
'10 hertz to exahertz' => test_zci(
'', structured_answer => make_answer({
raw_input => '10',
Expand Down

0 comments on commit 07d1553

Please sign in to comment.