Conversions Suggestion: (ANGLE) - Add Missing Units (#4224)

* added custom units for angle conversions

* added triggers for angle custom units

* added front-end tests for custom angle units

* Refactoring. Categorized queries by the quantity they represent

* minor update

* added trigger for the word - microarcseconds

* replaced exponent-based values with decimal-based ones

* Updated tests to use defined units

* added the missing commas

* removed duplicate e+12 from test spec
master
Parth Mehta 2017-06-04 00:35:10 +10:00 committed by PJ Hampton
parent 092124b817
commit db13126409
4 changed files with 352 additions and 227 deletions

View File

@ -52,6 +52,12 @@ DDH.conversions = DDH.conversions || {};
{name: 'sqcentimeter', factor: '0.0001 m2'},
{name: 'sqmillimeter', factor: '100 sqcentimeter'},
// CUSTOM DURATION UNITS
{name: "femtosecond", factor: "0.000000000000001 second"},
{name: "picosecond", factor: "0.000000000001 second"},
{name: "fortnight", factor: "2 week"},
{name: "siderealyear", factor: "1.00001741 year"},
// CUSTOM DIGITAL UNITS
{name: 'kbit', factor: '1000 b'},
{name: 'mbit', factor: '1000000 b'},
@ -62,12 +68,12 @@ DDH.conversions = DDH.conversions || {};
{name: 'GB', factor: '1000000000 B'},
{name: 'TB', factor: '1000 GB'},
{name: 'PB', factor: '1000 TB'},
// CUSTOM DURATION UNITS
{name: "femtosecond", factor: "0.000000000000001 second"},
{name: "picosecond", factor: "0.000000000001 second"},
{name: "fortnight", factor: "2 week"},
{name: "siderealyear", factor: "1.00001741 year"},
// CUSTOM ANGLE UNITS
{name: 'microarcsec', factor: '0.000000000004848 rad'},
{name: 'milliarcsec', factor: '0.000000004848 rad'},
{name: 'microrad', factor: '0.000001 rad'},
{name: 'rev', factor: '6.2832 rad'},
// CUSTOM ENERGY UNITS
{name: 'kilojoule', factor: '1000 joules'},
@ -243,13 +249,17 @@ DDH.conversions = DDH.conversions || {};
angle: {
name: "Angle",
units: [
{ symbol: 'rad', name: 'Radians' },
{ symbol: 'deg', name: 'Degrees' },
{ symbol: 'grad', name: 'Gradians' },
{ symbol: 'cycle', name: 'Cycles' },
{ symbol: 'arcsec', name: 'Arcsecond' },
{ symbol: 'arcmin', name: 'Arcminute' },
{ symbol: 'millirad', name: 'Milliradian' },
{ symbol: 'rad', name: 'Radians' },
{ symbol: 'deg', name: 'Degrees' },
{ symbol: 'grad', name: 'Gradians' },
{ symbol: 'cycle', name: 'Cycles' },
{ symbol: 'arcsec', name: 'Arcsecond' },
{ symbol: 'arcmin', name: 'Arcminute' },
{ symbol: 'millirad', name: 'Milliradian' },
{ symbol: 'microrad', name: 'Microradian' },
{ symbol: 'milliarcsec', name: 'Milliarcsecond' },
{ symbol: 'microarcsec', name: 'Microarcsecond' },
{ symbol: 'rev', name: 'Revolution' }
],
defaults: ['deg', 'rad']
},

View File

@ -1291,6 +1291,46 @@ aliases:
type: angle
unit: grad
---
aliases:
- microradian
- microradians
- micro-radian
- micro-radians
- microrad
- microrads
type: angle
unit: microrad
---
aliases:
- microarcsec
- microarcsecs
- microarcsecond
- microarcseconds
- micro-arcsec
- micro-arcsecs
- micro-arcsecond
- micro-arcseconds
type: angle
unit: microarcsec
---
aliases:
- milliarcsec
- milliarcsecond
- milli-arcsec
- milli-arcsecond
- milliarcsecs
- milli-arcsecs
type: angle
unit: milliarcsec
---
aliases:
- revolution
- revolutions
- rev
- revs
type: angle
unit: rev
---
aliases:
- newton
- newtons

View File

@ -127,9 +127,9 @@ describe("Conversion of Custom Units", function() {
expect(conversion).toEqual("2.00003482");
});
/**
* CUSTOM PRESSURE UNITS
*/
/**
* CUSTOM PRESSURE UNITS
*/
it("should convert barye to Satm", function() {
var conversion = stripUnit(math.eval("10132.5barye to Satm"));
expect(conversion).toEqual("0.009999999999999998");
@ -178,6 +178,49 @@ describe("Conversion of Custom Units", function() {
expect(conversion).toEqual("27375.912");
});
/**
* CUSTOM ANGLE UNITS
*/
it("should convert radians to microarcseconds", function() {
var conversion = stripUnit(math.eval("5rad to microarcsec"));
expect(conversion).toEqual("1.0313531353135312e+12");
});
it("should convert microarcseconds to radians", function() {
var conversion = stripUnit(math.eval("8microarcsec to rad"));
expect(conversion).toEqual("3.8784e-11");
});
it("should convert radians to milliarcseconds", function() {
var conversion = stripUnit(math.eval("12rad to milliarcsec"));
expect(conversion).toEqual("2.4752475247524753e+9");
});
it("should convert milliarcseconds to radians", function() {
var conversion = stripUnit(math.eval("9milliarcsec to rad"));
expect(conversion).toEqual("4.3631999999999997e-8");
});
it("should convert radians to microradians", function() {
var conversion = stripUnit(math.eval("4rad to microrad"));
expect(conversion).toEqual("4e+6");
});
it("should convert microradians to radians", function() {
var conversion = stripUnit(math.eval("26microrad to rad"));
expect(conversion).toEqual("2.6e-5");
});
it("should convert radians to revolutions", function() {
var conversion = stripUnit(math.eval("16rad to rev"));
expect(conversion).toEqual("2.546473134708429");
});
it("should convert revolutions to radians", function() {
var conversion = stripUnit(math.eval("7rev to rad"));
expect(conversion).toEqual("43.9824");
});
/**
* CUSTOM MASS UNITS
*/
@ -354,5 +397,4 @@ describe("Conversion of Custom Units", function() {
var conversion = stripUnit(math.eval("5zettaelectronvolt to yottaelectronvolt"));
expect(conversion).toEqual("0.005");
});
});

View File

@ -58,6 +58,7 @@ sub make_answer_with_base(%){
ddg_goodie_test(
['DDG::Goodie::Conversions'],
# Example queries
'convert 5 oz to grams' => test_zci(
'',
@ -84,7 +85,9 @@ ddg_goodie_test(
physical_quantity => 'mass'
})
),
# Explicit conversion requests
# MASS
'convert 158 ounce to lbm' => test_zci(
'', structured_answer => make_answer({
raw_input => '158',
@ -93,6 +96,23 @@ ddg_goodie_test(
physical_quantity => 'mass'
})
),
'convert 0.111 stone to pound' => test_zci(
'', structured_answer => make_answer({
raw_input => '0.111',
from_unit => 'stone',
to_unit => 'poundmass',
physical_quantity => 'mass'
})
),
'convert 1stone to lbs' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'stone',
to_unit => 'poundmass',
physical_quantity => 'mass'
})
),
# LENGTH
q`5' 7" in inches` => test_zci(
'', structured_answer => make_answer({
raw_input => '5.5833333333333333333333333333333333333333',
@ -133,14 +153,6 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
'convert 0.111 stone to pound' => test_zci(
'', structured_answer => make_answer({
raw_input => '0.111',
from_unit => 'stone',
to_unit => 'poundmass',
physical_quantity => 'mass'
})
),
'convert 5 feet to in' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
@ -157,14 +169,6 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
'convert 5 kelvin to fahrenheit' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
from_unit => 'kelvin',
to_unit => 'fahrenheit',
physical_quantity => 'temperature'
})
),
'convert 25 inches into feet' => test_zci(
'', structured_answer => make_answer({
raw_input => '25',
@ -173,6 +177,23 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
'convert km to cm' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'kilometer',
to_unit => 'cm',
physical_quantity => 'length'
})
),
# TEMPERATURE
'convert 5 kelvin to fahrenheit' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
from_unit => 'kelvin',
to_unit => 'fahrenheit',
physical_quantity => 'temperature'
})
),
'convert 5 f to celsius' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
@ -205,23 +226,9 @@ ddg_goodie_test(
physical_quantity => 'temperature'
})
),
'convert km to cm' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'kilometer',
to_unit => 'cm',
physical_quantity => 'length'
})
),
'convert 1stone to lbs' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'stone',
to_unit => 'poundmass',
physical_quantity => 'mass'
})
),
# Implicit conversion requests
# MASS
'3 kilogramme to pound' => test_zci(
'', structured_answer => make_answer({
raw_input => '3',
@ -246,14 +253,15 @@ ddg_goodie_test(
physical_quantity => 'mass'
})
),
'0.01933677566613741911668448550544 psi in mmHg' => test_zci(
'7 milligrams to micrograms' => test_zci(
'', structured_answer => make_answer({
raw_input => '0.01933677566613741911668448550544',
from_unit => 'psi',
to_unit => 'mmHg',
physical_quantity => 'pressure'
raw_input => '7',
from_unit => 'milligram',
to_unit => 'microgram',
physical_quantity => 'mass'
})
),
# LENGTH
'2 miles to km' => test_zci(
'', structured_answer => make_answer({
raw_input => '2',
@ -318,169 +326,6 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
'36 months to years' => test_zci(
'', structured_answer => make_answer({
raw_input => '36',
from_unit => 'month',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'43200 seconds in hours' => test_zci(
'', structured_answer => make_answer({
raw_input => '43200',
from_unit => 'second',
to_unit => 'hour',
physical_quantity => 'duration'
})
),
'4 hours to minutes' => test_zci(
'',
structured_answer => make_answer({
raw_input => '4',
from_unit => 'hour',
to_unit => 'minute',
physical_quantity => 'duration'
})
),
'5yrds to km' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
from_unit => 'yard',
to_unit => 'kilometer',
physical_quantity => 'length'
})
),
'12" to cm' => test_zci(
'', structured_answer => make_answer({
raw_input => '12',
from_unit => 'inch',
to_unit => 'cm',
physical_quantity => 'length'
})
),
'180 degrees in radians' => test_zci(
'', structured_answer => make_answer({
raw_input => '180',
from_unit => 'deg',
to_unit => 'rad',
physical_quantity => 'angle'
})
),
'180 degrees in grads' => test_zci(
'',
structured_answer => make_answer({
raw_input => '180',
from_unit => 'deg',
to_unit => 'grad',
physical_quantity => 'angle'
})
),
'45 newtons to pounds force' => test_zci(
'', structured_answer => make_answer({
raw_input => '45',
from_unit => 'newton',
to_unit => 'poundforce',
physical_quantity => 'force'
})
),
'10000 minutes in microseconds' => test_zci(
'', structured_answer => make_answer({
raw_input => '10000',
from_unit => 'minute',
to_unit => 'microsecond',
physical_quantity => 'duration'
})
),
'3 decades in years' => test_zci(
'', structured_answer => make_answer({
raw_input => '3',
from_unit => 'decade',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'2 centuries in years' => test_zci(
'', structured_answer => make_answer({
raw_input => '2',
from_unit => 'century',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'2 millennia in years' => test_zci(
'', structured_answer => make_answer({
raw_input => '2',
from_unit => 'millennium',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'16 years in months' => test_zci(
'', structured_answer => make_answer({
raw_input => '16',
from_unit => 'year',
to_unit => 'month',
physical_quantity => 'duration'
})
),
'1 year in months' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'year',
to_unit => 'month',
physical_quantity => 'duration'
})
),
'1 degree fahrenheit to celsius' => test_zci(
'',
structured_answer => make_answer({
raw_input => '1',
from_unit => 'fahrenheit',
to_unit => 'celsius',
physical_quantity => 'temperature'
})
),
'12 degrees Celsius to Fahrenheit' => test_zci(
'', structured_answer => make_answer({
raw_input => '12',
from_unit => 'celsius',
to_unit => 'fahrenheit',
physical_quantity => 'temperature'
})
),
'1 degrees Fahrenheit to celsius' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'fahrenheit',
to_unit => 'celsius',
physical_quantity => 'temperature'
})
),
'0 c in kelvin' => test_zci(
'', structured_answer => make_answer({
raw_input => '0',
from_unit => 'celsius',
to_unit => 'kelvin',
physical_quantity => 'temperature'
})
),
'234 f to c' => test_zci(
'', structured_answer => make_answer({
raw_input => '234',
from_unit => 'fahrenheit',
to_unit => 'celsius',
physical_quantity => 'temperature'
})
),
'234 f to kelvin' => test_zci(
'', structured_answer => make_answer({
raw_input => '234',
from_unit => 'fahrenheit',
to_unit => 'kelvin',
physical_quantity => 'temperature'
})
),
'metres from 20 yards' => test_zci(
'', structured_answer => make_answer({
raw_input => '20',
@ -489,14 +334,6 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
'7 milligrams to micrograms' => test_zci(
'', structured_answer => make_answer({
raw_input => '7',
from_unit => 'milligram',
to_unit => 'microgram',
physical_quantity => 'mass'
})
),
'inches in 5 meters' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
@ -561,7 +398,183 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
# Areas and volumes
'5yrds to km' => test_zci(
'', structured_answer => make_answer({
raw_input => '5',
from_unit => 'yard',
to_unit => 'kilometer',
physical_quantity => 'length'
})
),
'12" to cm' => test_zci(
'', structured_answer => make_answer({
raw_input => '12',
from_unit => 'inch',
to_unit => 'cm',
physical_quantity => 'length'
})
),
# TEMPERATURE
'1 degree fahrenheit to celsius' => test_zci(
'',
structured_answer => make_answer({
raw_input => '1',
from_unit => 'fahrenheit',
to_unit => 'celsius',
physical_quantity => 'temperature'
})
),
'12 degrees Celsius to Fahrenheit' => test_zci(
'', structured_answer => make_answer({
raw_input => '12',
from_unit => 'celsius',
to_unit => 'fahrenheit',
physical_quantity => 'temperature'
})
),
'1 degrees Fahrenheit to celsius' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'fahrenheit',
to_unit => 'celsius',
physical_quantity => 'temperature'
})
),
'0 c in kelvin' => test_zci(
'', structured_answer => make_answer({
raw_input => '0',
from_unit => 'celsius',
to_unit => 'kelvin',
physical_quantity => 'temperature'
})
),
'234 f to c' => test_zci(
'', structured_answer => make_answer({
raw_input => '234',
from_unit => 'fahrenheit',
to_unit => 'celsius',
physical_quantity => 'temperature'
})
),
'234 f to kelvin' => test_zci(
'', structured_answer => make_answer({
raw_input => '234',
from_unit => 'fahrenheit',
to_unit => 'kelvin',
physical_quantity => 'temperature'
})
),
# FORCE
'45 newtons to pounds force' => test_zci(
'', structured_answer => make_answer({
raw_input => '45',
from_unit => 'newton',
to_unit => 'poundforce',
physical_quantity => 'force'
})
),
# PRESSURE
'0.01933677566613741911668448550544 psi in mmHg' => test_zci(
'', structured_answer => make_answer({
raw_input => '0.01933677566613741911668448550544',
from_unit => 'psi',
to_unit => 'mmHg',
physical_quantity => 'pressure'
})
),
# DURATION
'36 months to years' => test_zci(
'', structured_answer => make_answer({
raw_input => '36',
from_unit => 'month',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'43200 seconds in hours' => test_zci(
'', structured_answer => make_answer({
raw_input => '43200',
from_unit => 'second',
to_unit => 'hour',
physical_quantity => 'duration'
})
),
'4 hours to minutes' => test_zci(
'',
structured_answer => make_answer({
raw_input => '4',
from_unit => 'hour',
to_unit => 'minute',
physical_quantity => 'duration'
})
),
'10000 minutes in microseconds' => test_zci(
'', structured_answer => make_answer({
raw_input => '10000',
from_unit => 'minute',
to_unit => 'microsecond',
physical_quantity => 'duration'
})
),
'3 decades in years' => test_zci(
'', structured_answer => make_answer({
raw_input => '3',
from_unit => 'decade',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'2 centuries in years' => test_zci(
'', structured_answer => make_answer({
raw_input => '2',
from_unit => 'century',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'2 millennia in years' => test_zci(
'', structured_answer => make_answer({
raw_input => '2',
from_unit => 'millennium',
to_unit => 'year',
physical_quantity => 'duration'
})
),
'16 years in months' => test_zci(
'', structured_answer => make_answer({
raw_input => '16',
from_unit => 'year',
to_unit => 'month',
physical_quantity => 'duration'
})
),
'1 year in months' => test_zci(
'', structured_answer => make_answer({
raw_input => '1',
from_unit => 'year',
to_unit => 'month',
physical_quantity => 'duration'
})
),
# ANGLE
'180 degrees in radians' => test_zci(
'', structured_answer => make_answer({
raw_input => '180',
from_unit => 'deg',
to_unit => 'rad',
physical_quantity => 'angle'
})
),
'180 degrees in grads' => test_zci(
'',
structured_answer => make_answer({
raw_input => '180',
from_unit => 'deg',
to_unit => 'grad',
physical_quantity => 'angle'
})
),
# AREAS & VOLUME
'0.001 litres in millilitres' => test_zci(
'', structured_answer => make_answer({
raw_input => '0.001',
@ -1326,6 +1339,7 @@ ddg_goodie_test(
physical_quantity => 'temperature'
})
),
#Question format:
'How to convert meters to inches' => test_zci(
'', structured_answer => make_answer({
@ -1343,6 +1357,7 @@ ddg_goodie_test(
physical_quantity => 'length'
})
),
# Representation (scientific notation)
'30000 km to m' => test_zci(
'', structured_answer => make_answer({
@ -1409,6 +1424,7 @@ ddg_goodie_test(
physical_quantity => 'mass'
})
),
# Flexible queries
'190 lb = ?kg' => test_zci(
'', structured_answer => make_answer({
@ -1482,6 +1498,22 @@ ddg_goodie_test(
physical_quantity => 'area'
})
),
# NATURAL LANGUAGE QUERIES
'unit converter' => test_zci(
'',
structured_answer => make_answer_lang()
),
'unit conversion' => test_zci(
'',
structured_answer => make_answer_lang()
),
'online converter' => test_zci(
'',
structured_answer => make_answer_lang()
),
# INTENTIONALLY UNTRIGGERED
'155 liters to millilitres' => test_zci(
'', structured_answer => make_answer({
raw_input => '155',
@ -1843,6 +1875,7 @@ ddg_goodie_test(
})
),
# Intentionally untriggered
'BTU to KwH' => undef,
'5 inches in 5 meters' => undef,
'convert 1 cm to 2 mm' => undef,
@ -1865,4 +1898,4 @@ ddg_goodie_test(
'1E300 miles in metres' => undef,
'5 pas.i to atm' => undef,
);
done_testing;
done_testing;