Commit Graph

98 Commits (master)

Author SHA1 Message Date
Nalin Bhardwaj 4768a4d882 fix file extension regex (#4510) 2017-09-28 18:40:31 +01:00
PJ Hampton 95214cc055 Calculator: Divide bug (#4483)
* Add edge case.

* Fix rouge regex.
2017-09-11 15:57:42 -04:00
PJ Hampton 74fb241903 Fix over triggering on dates. (#4463) 2017-08-29 15:33:26 -04:00
PJ Hampton d0b3a242db Fix overtriggering. (#4457) 2017-08-28 12:14:07 -04:00
PJ Hampton 138cfc5959 Calculator: patch overtriggering (#4439)
* Fix overtrigger on phone numbers.

* Prevent car model overtriggering.

* Stop ambigious overtriggering.

* Add extra test (mintsoft request)

* More handling of car searches

* Strip trailing spaces
2017-08-21 14:44:20 -04:00
PJ Hampton 9c581d9564 Calculator: Various Fixes (#4349)
* Fix weird error message.

* Stop algebra overtriggering.

* Fix overflow error.

* Fixed tests.

* Conclude big patch.

* Patch review bugs.
2017-07-13 18:04:32 -04:00
PJ Hampton af0a70222d Calculator: Fixes up trig functions. (#4339)
* Fixes up trig functions.

Replace regex.

* Fixed 1/(x) issues.

* Update dodgy lookahead.
2017-07-10 18:15:49 -04:00
PJ Hampton 8e5cd3f431 Add factorial support. (#4331)
Support factorials. Fix - remove bug.

Fixed a couple of iafd data issues.
2017-07-03 14:02:33 -04:00
PJ Hampton 65f69dab27 Calculator: Various improvements. (#4318)
* Various improvements.

query_nowhitespace removal workaround.

Updated code.

Update code.

Fix exponential state when squaring/cubing

Fix calculator bugs.

* Fix log.

* Various improvements.

* Update variable name.

* Remove debug statements.

* Fix logs/lns on front-end.
2017-06-29 16:55:27 -04:00
Philip Kirkbride db93ca9b76 Don't trigger log or lg without brackets (as these don't work) (#4249)
* Add sed command example

* Move to file section

* Don't trigger log without brackets. 

Quick fix for issue #4246

* Remove test that uses log(10)

* Update Calculator.t

* dont trigger ln without brackets either

* remove ln and log without bracket tests

* previously removed wrong test bring it back
2017-06-22 16:01:58 +01:00
Billy Barbaro 9a401b5caf Calculator: Comma in Floating Point Numbers (#4199)
* Using detected number style to make sure queries use a . for a decimal and a , to seperate thousands

* Now using method in number styler to prepare numbers for computation.
2017-06-22 15:46:49 +01:00
PJ Hampton 72729b7c16 Calculator: (URGENT) Fix math.js log|ln simplify issue. (#4183)
* Fix math.js simplify issue.

* Remove debug statements.

* Adds fact to the mix.

* Stash

* Fix greedy quantifier in trig and log/ln

* Don't trigger on anything with stuff after =

* allow triggering on <func> <number>

* Both sides of =

* Fix expressions.

* Tighten up triggering based on valid expressions.

* Remove dumper obj

* Tighten up word triggering.

* Allow only one currency through.

* Kill off symbols in js if allowed through.

* Allow negative numbers.

* Add support for negated numbers.

* Fix initialize issue.

* Refactor code slightly

* Tightened regexs

* Require space between log and input
2017-05-24 17:44:13 -04:00
PJ Hampton 137f98c31b Calculator: Add square root support from search bar. (#4182) 2017-05-09 16:53:43 -04:00
Zaahir Moolla f1142a6b21 tighten calculator regex, update tests (#4128) 2017-04-25 10:43:32 +01:00
PJ Hampton 3ea2787742 Added PercentOf logic to calculator. (#4122) 2017-04-24 12:59:03 -04:00
PJ Hampton 2e6590e29f Calculator: [Phase 4] Deprecate Perl Backend (#4110)
* Begin deprecating perl backend.

* Deprecate backend [skip ci]

* Routine checkin of code.

* Added docs + preprocessing.

* Deprecate perl eval backend.

* Checking in some code.'

* Handle bad search expressions by defaulting to 0

* Add ability to recover with grace from bad expressions from search bar.

* Removed unnessesary perl code.

* Add support for factorials with !

* cleanup trailing spaces

* Removed trig constants.

* Support tau in expression.

* Removed ln preprocess.

* Support leading =. Removed moot code.

* Add support for euro and pound.

* Removed nat lang query parsing from js.

* strip duplicate operators

* Fixed legacy spacing issue in tests.

* Remove empty exponent.

* Bail on hex looking entries.

* better handling of repeated operators

* Remove max import

* revert back to old check for 3+ operators

* relax phone number regex for now

* remove silly test
2017-04-21 13:12:41 -04:00
PJ Hampton 0abd6a6554 Calculator: [Phase 2] Add Scientific calculator (#4067)
* Phase 1: Add basic calculator

* Updated tests.

* change template name, use base template, prefill calc with answer

* fix test

* Added backlog features.

* Updated js.

* Light refactoring work

* Refactored keycodes.

* Updated C button.

* Rewrote (+/-)% Expressions

* Updated the spacing dertermination

* Added expression to UI by default.

* Update tests.

* Updated formatting.

* Rewrite percent queries.

* Pushing updated codebase.

* Add calculator as trigger word

* Update tests for new triggers

* Stop initializing expression if 0

* add precision support to math eval object.

* Removed scientific buttons / history for Phase 1

* Updated math type.

* Prevents duplicate OPERADNS

* Add duplicate functionality.

* Updated unicode.

* Removed es6 feature.

* Stop first entry being an operand.

* Add operator flipping.

* Added Precision support.

* Handle numpad operator keys

* Set and maintain focus, Improved event handling

* Bind click handler in loop, stopPropgation of keydown

* Cleanup trailing spaces

* Fixed broken assignment.

* Prevent multiple commas.

* Fixed calculator stalling when trying to enter a new operator

* Initial refactor.

* Refactored out expression array.

* Refactored out display var.

* reintroduced matheval object for precision.

* Cleaned up formatting.

* Removed commify.

* Initial PR for Phase 2

* Add support for brackets.

* Added support for Pi

* Add support for sin, tan, cos

* Added factorial support

* Add support for squared / cubed functions

* Add support for natural log

* Support log_10 function.

* Add support for square roots.

* Add eulers number.

* Implement Engineers Exponent / Formatted Funcs.

* Add sci-tab id to handlebars.

* Removed positioning for mobile display.

* Custom exponents 🚀

* Implemented Euler exponent

* Support 1/x button.

* Interactified deg/rad toggle.

* Add support for degrees / radians

* Fix radians bug.

* Zaahirs / Mintsofts syntactic changes.

* Fixed regex for exponents

* Removed blue from toggle.

* Allow backspacing through functions.

* Allow backspacing through exponents.

* Fix +99% bug.

* Allow flipping of keypads.

* Stop ! being entered first.

* Stop EE being entered at start or multiple.

* Allow step back through EE

* Disallow multiple periods. [skip ci]

* Rewrote query to handle natural language.

* Addressed phase 1 feedback.

* Fixed backspace bug.

* Allow backspacing through constants.

* Add auto paren support for funcs.

* Started the commenting 💥

* Add some comments.

* Updated PercentNormalizer comment.

* Fix 0/0 Error.

* Add 'c' key support

* Fix back spacing.

* Positioned deg / rad toggle.

* Refactoring code. Stage 1.

* Added high signal.

* Add funcs for Initite/NaN

* Moved eval info into separate function.

* Abstracted clear function.

* Add paren manager.

* Refactored out paren state.

* Refactored out parenState global

* Removed meta.

* Backspace through functions.

* Set signal to high.

* Fixed signal

* Pushing updated code.

* Refactored backspacing.

* Fix up messy code / document.

* Fixed + percent bug.

* Support EE on mobile.

* opens pseudo paren for 1/(x)

* Fix large factorial issue.

* Allow pi | e as exponent.

* use exponents on π and e.

* Removed +-3 issue.

* Natural log and log now work as exponents

* nit: cleaned up expression.

* Fixed percent error.

* Add phase 3 ledger span (hidden)

* Disabled add digits.

* Check in UX fixes.

* Some light refactoring.

* Swap functions.

* Fixed shoddy regex.

* Add ledger object for phase 3.

* Updated percentage / trig regex

* Add blank expression if error.

* Allow factorial on decimals.

* Update code + comments.

* Add in calc trigger word. Fixed Backspace.

* All backspacing fixed.

* Try to recover from open/unfinished exponent

* Add high signal for

* Update comments.

* Updated comments.

* improve calculator regex

* Strip trailing spaces`

* Updated signal code.

* Fixed backspacing issue.

* swap id for class (ParenManger)

* Remove console logs.

* Update comment.

* Fix bug in regex replacement.

* Calculator: [Phase 3] Add History / Calc reloading (#4081)

* Set up UI.

* Phase 3 implemented.

* Remove array. Replace with handlebars.

* strip commas by default.

* Fixed html interpolation

* Add g flag to replacement regex

* Strip trailing spaces

* remove unneeded option from perl

* Added comments to backspace.

* Removed ledger properties. Updated using state.

* Addressed Zaahir's p2 feedback
2017-04-12 15:31:12 -04:00
PJ Hampton dc12d569c6 Calculator: [Phase 1] Add basic calculator (#4051)
* Phase 1: Add basic calculator

* Updated tests.

* change template name, use base template, prefill calc with answer

* fix test

* Added backlog features.

* Updated js.

* Light refactoring work

* Refactored keycodes.

* Updated C button.

* Rewrote (+/-)% Expressions

* Updated the spacing dertermination

* Added expression to UI by default.

* Update tests.

* Updated formatting.

* Rewrite percent queries.

* Pushing updated codebase.

* Add calculator as trigger word

* Update tests for new triggers

* Stop initializing expression if 0

* add precision support to math eval object.

* Removed scientific buttons / history for Phase 1

* Updated math type.

* Prevents duplicate OPERADNS

* Add duplicate functionality.

* Updated unicode.

* Removed es6 feature.

* Stop first entry being an operand.

* Add operator flipping.

* Added Precision support.

* Handle numpad operator keys

* Set and maintain focus, Improved event handling

* Bind click handler in loop, stopPropgation of keydown

* Cleanup trailing spaces

* Fixed broken assignment.

* Prevent multiple commas.

* Fixed calculator stalling when trying to enter a new operator

* Initial refactor.

* Refactored out expression array.

* Refactored out display var.

* reintroduced matheval object for precision.

* Cleaned up formatting.

* Removed commify.

* Removed positioning for mobile display.

* Don't set focus on Calc automatically when displayed

* Add touchstart support.

* Prevent zooming.

* ensure button text is not selectable

* Add right borders to calc, ensure same border colour

* Cleanup code style

* Only apply hover state css to desktop
2017-04-06 16:40:56 -04:00
Zaahir Moolla 5f7329fc67 Calculator: Switch to canonical structured answer (#3916)
* Switch Calculator to canoncial structured answer

* Add Goodie Template
2017-02-06 16:06:33 -05:00
Zaahir Moolla 0ad6eba28a Calculator: Prevent anything but allowed ops in the query (#3903)
* prevent anything but allowed ops in the query
no negative nums

* Uncomment neg catch and move after garbage is removed

* Add more tests

* The hex check can be simplified since the trigger isn't allowing most of it
Allow expressions like 1e9 to pass

* Allow = in query
decimal/negatives with e

* Remove debug

* add test for 1e9 query
2017-01-30 17:46:21 -05:00
Zaahir Moolla 3309758c1d Calculator: More fixes -- Trigger regex contained a bug (#3898)
* Restrict some other stuff

* Don't require digit

* Restrict multiple ops to two or less

* reject empty parens/multiple ops

* No @, or $ not followed by a number or .

* combine char class

* add more negative tests

* Add ops back, case-insensitive subs, require two ops again

* Case-insensitive on multiple ops too

* Allow leading negatives

* Move the leading neg sub

* Better regex for hex input

* update tests
2017-01-28 14:07:00 -05:00
Zaahir Moolla 9322e7b34c Calculator: Improve triggering and execution (#3894)
* Update trigger
Use Safe for evaluation with the minimum functions
Removed unnecessary capturing, redundant function calls

* Add some tests

* Remove eval since we don't allow die
Add comment about debugging failed reval

* Add rv2gv from :base_orig to allow compat with Safe 2.35
Remove prtf since that was in :base_orig which was removed

* Remove unneeded opsets

* Silence all of reval's warnings

* Add STRICT
2017-01-26 10:45:49 -05:00
Zaahir Moolla a8d92e3cb5 Revert "ignore reval's warnings" (#3893) 2017-01-25 18:19:31 -05:00
Zach Thompson 369c894439 ignore reval's warnings (#3892)
* Update trigger
Use Safe for evaluation with the minimum functions
Removed unnecessary capturing, redundant function calls

* Add some tests

* Remove eval since we don't allow die
Add comment about debugging failed reval

* Add rv2gv from :base_orig to allow compat with Safe 2.35
Remove prtf since that was in :base_orig which was removed

* Remove unneeded opsets

* Silence all of reval's warnings
2017-01-25 17:35:25 -05:00
Zaahir Moolla 840cdc99a1 Revert "calculator: trigger/safe" (#3890) 2017-01-25 15:00:10 -05:00
Zach Thompson 2113d41a79 calculator: trigger/safe (#3878)
* Update trigger
Use Safe for evaluation with the minimum functions
Removed unnecessary capturing, redundant function calls

* Add some tests

* Remove eval since we don't allow die
Add comment about debugging failed reval

* Add rv2gv from :base_orig to allow compat with Safe 2.35
Remove prtf since that was in :base_orig which was removed

* Remove unneeded opsets
2017-01-24 15:00:37 -05:00
Zaahir Moolla 06196e98b5 Revert "Calculator: Dumb down the trigger" (#3868) 2017-01-20 15:49:16 -05:00
Zach Thompson 8e5d7b46e8 Calculator: Dumb down the trigger (#3866)
* Dumb down the calculator regex

* No interpolation

* Add tests to ensure changes work
2017-01-18 13:23:49 -05:00
Ben Moon 83b9bbd6b7 Fix newline at end of file 2016-05-16 14:19:39 +01:00
Ben Moon 5f85cf4121 Update Goodies to use Test::Deep
* Ensure Test::Deep is imported.

* Replace '-ANY-' with ignore()

* Replace regexes with re(...)
2016-05-16 14:07:57 +01:00
Ben Moon 204de9cb2e Fix spacing around minus sign
Previous fix introduced a small bug with spacing: things like
`1 + e - 3` were being expanded to `1 + e-3`. This fixes the
expansion.
2015-12-09 15:47:10 +00:00
Ben Moon e4865eb3cb Improve test coverage 2015-12-08 20:16:18 +00:00
Ben Moon a6573a7b2c Fix issue #1694
Fixes issue with expressions such as `1 + 2e-7` treating `e` as
the mathematical constant rather than `* 10 ^`.
2015-12-08 19:17:52 +00:00
Mailkov c86c1b0665 Issue 1418 - Factorial: Move integration into Calculator.pm; Calculate factorial with Math::BigInt bfac() 2015-11-23 15:47:31 +00:00
codetheweb 600bc22061 Add common US formating examples 2015-10-14 20:40:47 +00:00
codetheweb affb687f15 Add more test coverage 2015-10-12 19:21:36 +00:00
codetheweb ab15e8cc4e Fix phone number regex 2015-10-09 15:32:22 +00:00
codetheweb 645e237cc1 Add more test coverage 2015-10-01 18:14:58 +00:00
codetheweb b3fd5bb893 Ignore phone numbers 2015-09-25 23:28:28 +00:00
Daniel Smith 960f007888 Calculator.t: Added use utf8 2015-07-20 13:08:55 +00:00
Daniel Smith f517b5b80f Added support and tests for several multiplication symbols and obelus (÷) 2015-07-09 15:47:02 +00:00
Rob Emery a0410b9c52 Merge branch 'master' into mintsoft/calc-you-later
Conflicts:
	lib/DDG/Goodie/Calculator.pm
2015-03-29 23:14:44 +01:00
Rob Emery 563cb2909c Calculator: Updating tests with accurate output 2015-03-29 23:07:12 +01:00
Rob Emery 04f698bb5c Calculator: Adding failing tests for 2pi; currently implicit multiplication isn't supported 2015-03-29 22:49:43 +01:00
Rob Emery 145684d96c Calculator: Adding failing test for https://github.com/duckduckgo/zeroclickinfo-goodies/issues/1026 2015-03-29 22:37:07 +01:00
Jay Kamat 0a2c16861b Added more tests 2015-03-23 15:47:10 +00:00
jgkamat a983ece55d Added sqrt to the goodie caclulator 2015-03-21 05:22:53 +00:00
Chris Wilson 2f11d6cc76 Update Binary IA to Uppercase. Fix All Test Cases for Uppercase Changes. 2015-01-09 19:46:54 +11:00
Pattarawat Chormai fc9f44cb88 Fix test 2014-12-14 11:02:36 +07:00
Matt Miller fe1729edf1 Calculator: add structured answer. 2014-11-15 21:35:39 +02:00