Commit Graph

51 Commits (194556f7388ca778528cde59aa8d4989e33e893f)

Author SHA1 Message Date
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
Matt Miller 39a9204689 Calculator: expand number availability.
This adds the ability for numbers to contian spaces or underscores.  It
also makes me recognize once more how brittle all of these
inter-relationships are.
2014-11-15 09:14:34 +02:00
Matt Miller 02adf60315 Calculator: better guard for no-ops.
The old gaurd was kinda whacky (and wrong) and inverted all the logic.
So we'll dump out early when we recognize that no operations will be
done.
2014-11-05 00:38:18 +02:00
Jag Talon 6b667ccede Merge pull request #586 from mwmiller/small_calc
Calculator: better display for very small floats.
2014-08-18 18:07:26 -04:00
Matt Miller aa150cf685 Calculator: better display for very small floats.
With the addition of the number styling role, we've improved the output
for very small floats.  We don't need to round them any longer, since
they produce comprehensible display values and don't break anything.
2014-08-14 08:54:33 -04:00
Matt Miller 4d28815513 Calculator: remove ! from trigger regex.
There appears to be no value in this beingincluded and it makes things
evaluate incorrectly, so we'll just remove it.
2014-08-12 15:00:05 -04:00
Rob Emery 93fc908a99 Merge branch 'master' into mintsoft/conversion_calcs 2014-08-01 23:37:02 +01:00
Rob Emery 17a15ebe1c Calculator: uses the correct classes 2014-07-30 19:43:54 +01:00
Matt Miller 65d6f76978 NumberStyle: tighten up check for exponentials.
Also, some adjustments to Calculator to allow its tests to pass.
Still clearly not properly factored, but at least everything "works"
for the moment.
2014-07-27 22:23:04 +08:00
Rob Emery eee3b51734 Merge remote-tracking branch mwmiller's 'style_role/style_role' into mintsoft/conversion_calcs
Conflicts:
	lib/DDG/Goodie/Calculator.pm
2014-07-26 22:52:49 +01:00
Matt Miller 239bdb9072 Calculator: ignore attempts at subnet notation.
This one is much harder to hit, because the dotted quads must have 3
digits in each of the last 3 positions and they tend to start zero-ing
the mask earlier, but might as well cover this better, too.

Thanks to @mintsoft for the heads-up.
2014-07-10 05:33:43 +08:00
Matt Miller 89b900c5b1 Calculator: ignore probable attempts at CIDR notation.
If we get a dotted quad, slash and a number in the range of 0-32, it
seems more likely this is talking about network addresses, than trying
to do a calculation.

I, personally, think it's unlikely we ever should be dealing with dotted
quads, but I want to leave in the possiblity of a pasted-in euro-style
value.

Fixes #541.
2014-07-10 05:05:04 +08:00
Matt Miller efad091e9d Calculator: ignore probable attempts at hex notation.
This regex overreaches a bit, because query_nowhitespace doesn't
guarantee we'll see word-breaks exactly where we might expect.  This is
sufficient for now, but this triggering needs a general rethink.

Addresses some concerns in issue #517.
2014-07-10 04:32:04 +08:00
Matt Miller cd1d480294 NumberStyler: add proof-of-concept
Considering how all of this works, I'm not sure roles are quite the
right fit. It seems like we might just want a shared "Utility" package
or namespace to let us have access to some common library functions.

DDG::GoodieRole::NumberStyle is a particularly horrible name because
it's not even a role!

Also, the comments suck.

But such is the nature of a proof-of-concept.
2014-06-28 04:27:57 +08:00
Matt Miller 13c9ea7f55 Calculator: superscripting for arbitrary terms.
This would be better with some proper parsing, but this resolves some
issues with the current HTML output, making it raise things to
arbitrarily high superscripting levels based on what it seems to look
like.
2014-06-28 04:22:37 +08:00
Matt Miller 41c070ba2b Calculator: fix mis-construed style for numbers with initial 0.
There should never be a thousands separator in that place, so don't
allow one.  This was a bit masked by taking all of the numbers in
combination which gave them more context.

Testing a number individually exposed the error.
2014-06-24 15:51:08 +08:00
Matt Miller bc2249abde Calculator: improve precision/accuracy trade-off.
This includes multiplication and division in things which should not be
rounded to our determined precision. While this doesn't break any
current tests, it might lead to some surprising floating-point issues.

On the other hand, the other way led to some surprising results where

418.10 / 2 != 418.1 / 2

Hopefully there exists a better long-term solution which we'll find soon
enough.

Addresses issue #509.
2014-06-24 13:22:58 +08:00
jagtalon 668d8556f1 Calculator: Fix failing tests. 2014-06-16 20:35:27 +00:00
Matt Miller a32f0f8c30 Calculator: add 'squared' and 'score'.
This is an attempt to add the requested "squared" operation without all
of the nasty trigger changes I introduced last time I tried.

Also added a constant for 'score' as both an attempt to better
understand that trigger regex and an historical oddity.

It's clear that if I want to continue with this I should make a lexer.
2014-06-15 04:57:02 +08:00
jagtalon adb6329a7c Revert "Calculator: improve triggers; add 'squared'"
This reverts commit 5e6c1abb9a.

Conflicts:
	t/Calculator.t
2014-06-13 20:38:58 +00:00
Matt Miller 300cba4744 Calculator: style up the answer a bit.
This mostly just adds style to the HTML answers to be more in line with
other IAs.

The test changes are because, in general, the HTML answer is exactly the
same as the text answer, just wrapped up in some HTML. We're mostly
concerned with if we get correct answers, not how they happen to be
wrapped for HTML display.

In cases where that's different (the <sup> regression) we do more
thorough testing on the contents.

Also, removed one repeated test.

I'm starting to think this "apply_css" and maybe even "wrap_html" should
be in a role somewhere.
2014-06-10 20:42:52 +08:00
Matt Miller 45175d18c8 Calculator: reset alarm when calculation is complete.
Total run time may well exceed 1 second with the pre- and post-
processing, but this makes it significantly less annoying to try things
out with `duckpan query`.

Also adds a test which shows the `duckpan query` parameters I was
trying, showing how `squared` is applied (and may result in confusion)
2014-06-10 09:30:22 +08:00
Matt Miller 2c855b6dad Calculator: improve superscript handling.
This fixes the problem of the simple case, but handling, say, expressions
in parens would require a lot more thought (a lexer would help!) I'll
leave that problem for another day.

Fixes #483.
2014-06-10 08:34:11 +08:00
Matt Miller 5e6c1abb9a Calculator: improve triggers; add 'squared'
Some of the problems inherent in the old trigger regex made themselves
obvious once the 'squared' operation was added. This simplification
should make maintenance a smidge easier.

Resolves #482.
2014-06-10 08:10:03 +08:00
Matt Miller 4d1443ae44 Calculator: give result for sin(pi)
Because of floating-point issues, sin(pi) does not come out to exactly
0. It looks like something we try to guard against a couple lines down.

So, if we don't have a defined precision (such that we can let sprintf
worry about the correct answer), we will set these very small values to
0.

This worked fine with things like '1 + sin(pi)' which made the whole thing
more confusing at the start. Thus, this commit also includes a passel of
new tests for things I considered as possible faults, plus one other thing
I wanted to demonstrate working [cos(2pi)].
2014-06-04 22:52:36 +08:00
Matt Miller 1aaf123351 Calculator: minor cleanups.
- Make ln alias more like others.
- Put named constants in a hash and generate the substitution list
  therefrom.
- Update test and comment text slightly for accuracy.

I had fixed a number of different problems iteratively and didn't
recognize that these changes were viable until now.
2014-05-31 18:29:11 +08:00
Matt Miller 75fa8f9888 Calculator: add support for ln and (mostly) arbitrary base logs
We're only actually doing logs up to base 999.. but I think
anything else is probably people goofing. I can be convinced otherwise,
though.
2014-05-23 09:10:50 +08:00
Matt Miller a5c2f85ffa Calculator: add another FP-related regression test.
In response to a known-bad production result.
2014-05-01 01:10:39 +08:00
Matt Miller b39a62547f Calculator: use Math::Trig for trig functions.
Also, to get the value of pi.

In service of this change, also add some additional available functions.
Not so much because I think people were clamoring for secants, but as a
way of expanding expectations for the nascent parser: fix replacement
issues with 'e', better description of what a "function" might look
like, etc.
2014-04-06 12:04:26 +08:00
Matt Miller 0c0dc9e102 Reconsider how precision is done.
We want the precision to be just like our input, except when there are
hidden factors in the functions which will cause us to want much more.

Because of how we do this (via `eval`) the func list is almost certainly
wrong. Precisely defining our input is (still) yet to come.

Added some tests to show how we handle very small floats and other
related issues, plus a recommended test from an early issue comment
which I somehow missed.
2014-03-30 20:52:56 +08:00
Matt Miller eea45b243d Iterate toward more formal query parsing.
This is mostly an attempt to make it easier (for me) to read and
identify everything which needs to be covered in any further
refactoring.

There is one funcational difference:  'c' is no longer an acceptable
constant. I was vaguely bothered that it was the only one with units,
anyway and once it made the parsing of 'cos' turn ugly, I just ripped
it out.

Also added a test for an identifiable regression from a former code
comment.
2014-03-30 20:52:03 +08:00
Matt Miller 7518ed81fe Calculator: deal with parenthesized query strings.
We want to make sure that we catch all of the numbers, even if they are
inside parens, so we add some extra spacing (on request) in `spacing` to
make sure we can find them. I think there may still be a problem with
1E2-style numbers, but that's always been there. :(

As part of this, also switched the "sub" versions back to strings so I
can concatenate for the "numbery" regex.  This is not a big deal
since all the functions are getting built early anyway.

And added some more tests to make sure this works as intended.
2014-03-29 13:51:59 +08:00
Matt Miller 13b223b87e Deal with number checking in a better way.
It passes all of the tests, but it's still wrong.. for example, parens
will not be "numbery" and so can help numbers evade format detection.

On the upside, it's now much simpler to read and understand. Plus,
rejects queries which have been marked bad in the issues this is intended
to address.
2014-03-28 15:00:21 +08:00
Matt Miller dfd2153bb9 Try to recognize mal-formed numbers.
Also includes some minor comment and layout fixups.

Once we have decided on a style which seems to fit all of the input
numbers, we proceed to confirm that all of the numbers (even the
ambiguous ones) make sense in this format.

So far, this means:
- Doesn't have any characters we don't understand.
- All supposed thousands breaks are followed by exactly three numbers
- If there's a decimal mark, there is only one and it never precedes a
  thousands break.

This is starting to look like something which should be in a library
somewhere.

Even better, it isn't even actually used yet, since the style-checker
happens on a whole expression instead of a term.  Someday.
2014-03-28 01:13:13 +08:00
Matt Miller 7f974169ba Add code and tests for number disambiguation.
This is still not properly factored, but progressing.
2014-03-24 21:33:54 +08:00
Matt Miller 175bce174c Apply tidy. 2014-03-24 21:28:54 +08:00
Matt Miller 9b7bf99cb7 Calculator: improve recognition of euro-style numbers.
Fixes #207.

- Add a check to try to determine if they entered more European-looking
  numbers.
- Adjust the output, if so, to make the output imply what happened and
  probably appear more familiar.
- Otherwise, treat any commas as noise to be ignored.

The euro-style check is pretty weak, by design. It only looks to see if
they used . before , thus implying an order for the separators.

Also adds an abstract to reduce `dzil test` scroll-spam
2014-02-15 23:06:53 +08:00
Matt Miller e3c4911842 Calculator: improve scientific notation support.
Fixes #270.

Scientific notation was not supported in all places.  This should fix
that. I admit the regex is a bit much for me to hold in my head, so I am
not sure if there are now incidentally misparsed queries.

All tests pass, including new ones to cover the broken cases mentioned
in the issue.
2014-02-15 21:59:07 +08:00
Eric Johnson 9c29b27338 Added tests for example queries which are not currently tested.
Conflicts:

	t/TimezoneConverter.t
2014-02-10 21:36:14 +00:00
Gabriel Weinberg 42a81dab94 Revert "use bignum in calculator for... precision."
This reverts commit 8b39e1e82a.

Conflicts:

	lib/DDG/Goodie/Calculator.pm
2013-12-25 20:05:37 -05:00
Michael Smith 8b39e1e82a use bignum in calculator for... precision. 2013-12-01 15:11:30 -07:00
Dylan Lloyd 8c2bbdbed6 add solve trigger to calculator 2013-06-28 18:56:27 -04:00
Dylan Lloyd 6c89f5e9f9 fixed erroneous exit on zero value calculations 2013-06-28 17:45:24 -04:00
Michael Smith d84bdbb1b7 Fix Calc some more, add another test 2013-06-08 13:51:33 -06:00
Michael Smith 4ef8cbad31 Kill the giant monster math regex of Doom. Fixes #196 and my headache. 2013-06-08 13:35:24 -06:00
Eskatrem eed8be5c0f added tests for calculator 2013-05-15 23:09:25 +00:00
Dylan Lloyd 0cd4e2749d fixed error parsing decimal exponentials
removed extraneous parentheses, added test cases
2013-05-12 20:22:54 -04:00
Dylan Lloyd d13f56dbb9 added "what is" to Calculator trigger regex
new test case "what is 2+2"
2013-05-04 16:10:30 -04:00