elementary / applications-menu

Applications Menu for elementary OS and the Pantheon desktop environment
https://elementary.io
GNU General Public License v3.0
103 stars 35 forks source link

Improve calculator plugin #539

Closed jeremypw closed 2 years ago

jeremypw commented 2 years ago

Fixes #474 Fixes #439

It is still rarely possible to enter strings that are not mathematical expressions that get passed to bc and give a spurious result but to completely prevent this while allowing a wide range of valid expressions is too complex to be worthwhile (at least not in this PR).

jeremypw commented 2 years ago

Simple arithmetic Screenshot from 2022-07-17 10 05 38

Hexadecimal to Binary Screenshot from 2022-07-17 09 49 37

Binary to decimal Screenshot from 2022-07-17 09 55 31

Square root function Screenshot from 2022-07-17 09 50 02

Arctangent function Screenshot from 2022-07-17 10 04 43

jeremypw commented 2 years ago

Use of variables

Screenshot from 2022-07-17 10 18 54

tintou commented 2 years ago

I think that we need to introduce tests to ensure that this won't regress

jeremypw commented 2 years ago

@tintou I did think about how to set up tests but left it until the basic concept was approved. I do not think regressions are likely in the sense that correct single expressions that are handled correctly in main are not handled correctly here (they are still just passed to bc) - more likely that new types of expressions or combinations of expressions are not handled correctly.

jeremypw commented 2 years ago

Presumably we would need to introduce testing into master first in order to confirm regressions.

jeremypw commented 2 years ago

Essentially all this PR does is relax the filtering on expressions passed to bc - it does not change the expressions so it is still delegated to bc to either give a correct answer or an error. Theoretically the worst that can happen is that it allows through an expression that bc handles incorrectly.

jeremypw commented 2 years ago

Testing framework now merged in.

jeremypw commented 2 years ago

@tintou I have now incorporated tests for the new functionality. Are you able to review?