From e2845f68cc0405f0df9596fe423b76d2e08a36ed Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 24 Jan 2017 04:50:27 +0000 Subject: [PATCH 1/8] Removed alarm from calculator --- lib/DDG/Goodie/Calculator.pm | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/DDG/Goodie/Calculator.pm b/lib/DDG/Goodie/Calculator.pm index 0c393c50df7..29857c2cd1a 100644 --- a/lib/DDG/Goodie/Calculator.pm +++ b/lib/DDG/Goodie/Calculator.pm @@ -111,13 +111,7 @@ handle query_nowhitespace => sub { $tmp_expr =~ s/(Math::BigInt->new\((.*)\))/(Math::BigInt->new\($2\))->bfac()/g; #correct expression for fact # Using functions makes us want answers with more precision than our inputs indicate. my $precision = ($query =~ $funcy) ? undef : ($query =~ /^\$/) ? 2 : max(map { $style->precision_of($_) } @numbers); - my $tmp_result; - eval { - # e.g. sin(100000)/100000 completely makes this go haywire. - alarm(1); - $tmp_result = eval($tmp_expr); - alarm(0); # Assume the string processing will be "fast enough" - }; + my $tmp_result = eval($tmp_expr); # Guard against non-result results return unless (defined $tmp_result && $tmp_result ne 'inf' && $tmp_result ne ''); From 8bc90ae2db4b940f091aa361d57a1d59eb6f3014 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 24 Jan 2017 04:57:03 +0000 Subject: [PATCH 2/8] Removed alarm from PrimeFactors --- lib/DDG/Goodie/PrimeFactors.pm | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/DDG/Goodie/PrimeFactors.pm b/lib/DDG/Goodie/PrimeFactors.pm index b6bf854af65..0e656a789ca 100644 --- a/lib/DDG/Goodie/PrimeFactors.pm +++ b/lib/DDG/Goodie/PrimeFactors.pm @@ -92,14 +92,8 @@ handle remainder => sub { # TODO: We should accept different number formats. return unless /^\d+$/; - my $start_time = time(); - my @factors = (); + my @factors = factor_exp($_); - # Provide only one second for computing the factors. - eval { - alarm(1); - @factors = factor_exp($_); - }; # Exit if we didn't find anything. if(@factors == 0) { return; From 90eb4696a70e134a81294ece2f91bd7d10a82276 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 24 Jan 2017 23:23:56 +0000 Subject: [PATCH 3/8] Added more units, fixed existing ones --- share/goodie/conversions/ratios.yml | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/share/goodie/conversions/ratios.yml b/share/goodie/conversions/ratios.yml index fdd3ab90d2b..40ff3321aa2 100644 --- a/share/goodie/conversions/ratios.yml +++ b/share/goodie/conversions/ratios.yml @@ -892,6 +892,8 @@ plural: leap years aliases: - pa - pas + - pascal + - pascals factor: 1 type: pressure unit: pascal @@ -900,6 +902,8 @@ plural: pascals aliases: - kpa - kpas + - kilopascal + - kilopascals factor: 0.001 type: pressure unit: kilopascal @@ -908,6 +912,8 @@ plural: kilopascals aliases: - megapa - megapas + - mpa + - mpas factor: 1e-06 type: pressure unit: megapascal @@ -916,14 +922,16 @@ plural: megapascals aliases: - gpa - gpas + - gigapascal + - gigapascals factor: 1e-09 type: pressure unit: gigapascal plural: gigapascals --- aliases: - - pa - - pas + - bar + - bars factor: 1e-05 type: pressure unit: bar @@ -1638,3 +1646,23 @@ factor: 1.943844492440605 type: speed unit: knot plural: knots +--- +aliases: + - micrometre + - micrometres + - µm + - µms +factor: 1000000 +type: length +unit: micrometre +plural: micrometres +--- +aliases: + - picometre + - picometres + - pm + - pms +factor: 1000000000000 +type: length +unit: picometre +plural: picometres \ No newline at end of file From 576d6f0e74022375f81ae71121e7f87531357aed Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 24 Jan 2017 23:29:00 +0000 Subject: [PATCH 4/8] Added american spellings --- share/goodie/conversions/ratios.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/share/goodie/conversions/ratios.yml b/share/goodie/conversions/ratios.yml index 40ff3321aa2..3730df4df8d 100644 --- a/share/goodie/conversions/ratios.yml +++ b/share/goodie/conversions/ratios.yml @@ -1649,7 +1649,9 @@ plural: knots --- aliases: - micrometre + - micrometer - micrometres + - micrometers - µm - µms factor: 1000000 @@ -1659,7 +1661,9 @@ plural: micrometres --- aliases: - picometre + - picometer - picometres + - picometers - pm - pms factor: 1000000000000 From 97e4888dd408c9db53fcdf1daa02c42231fc022f Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 24 Jan 2017 23:40:06 +0000 Subject: [PATCH 5/8] Fixed spellings issue in pico and micro --- share/goodie/conversions/ratios.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/share/goodie/conversions/ratios.yml b/share/goodie/conversions/ratios.yml index 3730df4df8d..6de5e2a53c3 100644 --- a/share/goodie/conversions/ratios.yml +++ b/share/goodie/conversions/ratios.yml @@ -1649,24 +1649,20 @@ plural: knots --- aliases: - micrometre - - micrometer - micrometres - - micrometers - µm - µms factor: 1000000 type: length -unit: micrometre -plural: micrometres +unit: micrometer +plural: micrometers --- aliases: - picometre - - picometer - picometres - - picometers - pm - pms factor: 1000000000000 type: length -unit: picometre -plural: picometres \ No newline at end of file +unit: picometer +plural: picometers \ No newline at end of file From 7b0eae4d261ffdf582fde088f2cc0dfe9e2f7886 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Tue, 24 Jan 2017 23:44:39 +0000 Subject: [PATCH 6/8] cleaned up --- share/goodie/conversions/ratios.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/goodie/conversions/ratios.yml b/share/goodie/conversions/ratios.yml index 6de5e2a53c3..ceeacee3c07 100644 --- a/share/goodie/conversions/ratios.yml +++ b/share/goodie/conversions/ratios.yml @@ -1652,7 +1652,7 @@ aliases: - micrometres - µm - µms -factor: 1000000 +factor: 1e06 type: length unit: micrometer plural: micrometers @@ -1662,7 +1662,7 @@ aliases: - picometres - pm - pms -factor: 1000000000000 +factor: 1e12 type: length unit: picometer plural: picometers \ No newline at end of file From b0cc4c5ec737b221afde555c7402d43ffcaf0f52 Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Wed, 25 Jan 2017 15:50:29 +0000 Subject: [PATCH 7/8] Added nanometers, fixed others --- share/goodie/conversions/ratios.yml | 60 ++++++++++++++--------------- t/Conversions.t | 12 ++++++ 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/share/goodie/conversions/ratios.yml b/share/goodie/conversions/ratios.yml index ceeacee3c07..533171dbee8 100644 --- a/share/goodie/conversions/ratios.yml +++ b/share/goodie/conversions/ratios.yml @@ -244,6 +244,34 @@ type: length unit: millimeter plural: millimeters --- +aliases: + - micrometre + - micrometres + - µm + - µms +factor: 1e06 +type: length +unit: micrometer +plural: micrometers +--- +aliases: + - nanometre + - nanometres +factor: 1e09 +type: length +unit: nanometer +plural: nanometers +--- +aliases: + - picometre + - picometres + - pm + - pms +factor: 1e12 +type: length +unit: picometer +plural: picometers +--- aliases: - thou - thous @@ -892,8 +920,6 @@ plural: leap years aliases: - pa - pas - - pascal - - pascals factor: 1 type: pressure unit: pascal @@ -902,8 +928,6 @@ plural: pascals aliases: - kpa - kpas - - kilopascal - - kilopascals factor: 0.001 type: pressure unit: kilopascal @@ -922,16 +946,12 @@ plural: megapascals aliases: - gpa - gpas - - gigapascal - - gigapascals factor: 1e-09 type: pressure unit: gigapascal plural: gigapascals --- -aliases: - - bar - - bars +aliases: [] factor: 1e-05 type: pressure unit: bar @@ -1645,24 +1665,4 @@ aliases: factor: 1.943844492440605 type: speed unit: knot -plural: knots ---- -aliases: - - micrometre - - micrometres - - µm - - µms -factor: 1e06 -type: length -unit: micrometer -plural: micrometers ---- -aliases: - - picometre - - picometres - - pm - - pms -factor: 1e12 -type: length -unit: picometer -plural: picometers \ No newline at end of file +plural: knots \ No newline at end of file diff --git a/t/Conversions.t b/t/Conversions.t index 72434153818..c62d9be1f9c 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -1152,6 +1152,18 @@ ddg_goodie_test( physical_quantity => 'length' }) ), + 'mm in inch' => test_zci( + '1 inch = 25.400 millimeters', + structured_answer => make_answer({ + markup_input => '1', + raw_input => '1', + from_unit => 'inch', + styled_output => '25.400', + raw_answer => '25.400', + to_unit => 'millimeters', + physical_quantity => 'length' + }) + ), 'how many fl oz in a cup' => test_zci ( '1 us cup = 8 us fluid ounces', structured_answer => make_answer({ From 0baa2851c49175f4686d4898794548d47940129b Mon Sep 17 00:00:00 2001 From: Nalin Bhardwaj Date: Wed, 25 Jan 2017 16:07:24 +0000 Subject: [PATCH 8/8] Added tests --- t/Conversions.t | 50 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/t/Conversions.t b/t/Conversions.t index c62d9be1f9c..cce94b41dae 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -528,6 +528,42 @@ ddg_goodie_test( physical_quantity => 'length' }) ), + '500 nanometer to pm' => test_zci( + '500 nanometers = 500,000 picometers', + structured_answer => make_answer({ + markup_input => '500', + raw_input => '500', + from_unit => 'nanometers', + styled_output => '500,000', + raw_answer => '500000', + to_unit => 'picometers', + physical_quantity => 'length' + }) + ), + '500 nanometer to micrometer' => test_zci( + '500 nanometers = 0.500 micrometers', + structured_answer => make_answer({ + markup_input => '500', + raw_input => '500', + from_unit => 'nanometers', + styled_output => '0.500', + raw_answer => '0.500', + to_unit => 'micrometers', + physical_quantity => 'length' + }) + ), + '17 micrometer in mil' => test_zci( + '17 micrometers = 0.669 thousandths of an inch', + structured_answer => make_answer({ + markup_input => '17', + raw_input => '17', + from_unit => 'micrometers', + styled_output => '0.669', + raw_answer => '0.669', + to_unit => 'thousandths of an inch', + physical_quantity => 'length' + }) + ), '36 months to years' => test_zci( '36 months = 3 years', structured_answer => make_answer({ @@ -1152,18 +1188,6 @@ ddg_goodie_test( physical_quantity => 'length' }) ), - 'mm in inch' => test_zci( - '1 inch = 25.400 millimeters', - structured_answer => make_answer({ - markup_input => '1', - raw_input => '1', - from_unit => 'inch', - styled_output => '25.400', - raw_answer => '25.400', - to_unit => 'millimeters', - physical_quantity => 'length' - }) - ), 'how many fl oz in a cup' => test_zci ( '1 us cup = 8 us fluid ounces', structured_answer => make_answer({ @@ -2900,4 +2924,4 @@ ddg_goodie_test( '1E300 miles in metres' => undef, '5 pas.i to atm' => undef, ); -done_testing; +done_testing; \ No newline at end of file