Merge lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app

Proposed by Bartosz Kosiorek
Status: Merged
Approved by: Bartosz Kosiorek
Approved revision: 195
Merged at revision: 206
Proposed branch: lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number
Merge into: lp:ubuntu-calculator-app
Diff against target: 101 lines (+37/-9)
3 files modified
app/engine/formula.js (+10/-7)
app/ubuntu-calculator-app.qml (+6/-2)
tests/autopilot/ubuntu_calculator_app/tests/test_main.py (+21/-0)
To merge this branch: bzr merge lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Riccardo Padovani Needs Fixing
Niklas Wenzel (community) Needs Fixing
Alan Pope 🍺🐧🐱 πŸ¦„ (community) Approve
Review via email: mp+262273@code.launchpad.net

Commit message

Allow add comma without number

Description of the change

Allow add comma without number

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thanks. This is one of the features I always missed!

I have a few minor complaints though. ;)
There is an issue related to the removed code from couldAddDot() now. Typing in '4!.2' results in '4!0.2' while in my opinion it should be '4!*0.2'. The same applies to 'pi.2'.
Also try the following: Type in '23,4', place the cursor after the three and type in a plus. Shouldn't it insert a zero?

Check out my inline comment below as well. ;)

Thanks again!

review: Needs Fixing
Revision history for this message
Bartosz Kosiorek (gang65) wrote :

Please create new bug report regarding automatically adding "*" to formula.

With type '23,4': We could only parse/validate/modify formula before cursor, and in my opinion we shouldn't modify after. What if you would like to change something more in formula?
I would like to have full control of what I'm typing, and help user only when I'm 100% sure what is his intention.

Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Looks good to me.

review: Approve
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Doesn't work always.
Try to do 9+6*3+.3, 0 isn't added.

Please, also add a test case for this bug, and I agree with Niklas' inline comment, you shold add a comment to explain the code you added :-)

review: Needs Fixing
192. By Bartosz Kosiorek

Add comment to new code

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Bartosz, I filed the issue and thanks for adding the comment. ;)

193. By Bartosz Kosiorek

Fix issue with temporarly result

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Works really good now and it took like forever till I found an issue. ;)

1) Type in "8*8="
2) Type in "."

What happens:

The new input is "64.".

However, if we want to handle typing "." as "0.", we need to apply the same behaviour we apply to numbers here, i.e. clearing the input and inserting "0.".

Nevertheless, it works really well. Thanks. ;)

review: Needs Fixing
194. By Bartosz Kosiorek

Fixes after review

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

There are conflicts now, do you mind to fix them? :-)

review: Needs Fixing
195. By Bartosz Kosiorek

Merge with trunk

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/engine/formula.js'
2--- app/engine/formula.js 2015-03-26 21:16:14 +0000
3+++ app/engine/formula.js 2015-07-04 20:08:40 +0000
4@@ -90,14 +90,22 @@
5 return couldAddOperator(formula, stringToAddToFormula[0]);
6 }
7
8- if (stringToAddToFormula === ".") {
9+ // After decimal separator only number is allowed
10+ if (isNaN(stringToAddToFormula)) {
11+ if (formula.slice(-1) === ".") {
12+ return false;
13+ }
14+ }
15+
16+ // We are ckecking last char, because we want to handle "0." string
17+ if (stringToAddToFormula.slice(-1) === ".") {
18 return couldAddDot(formula);
19 }
20
21 if (stringToAddToFormula === ")") {
22 return couldAddCloseBracket(formula);
23 }
24-
25+
26 // Validate complex numbers
27 if ((stringToAddToFormula === "i") || (!isNaN(stringToAddToFormula))){
28 if (formula.slice(-1) === "i") {
29@@ -226,11 +234,6 @@
30 * @return bool: true if the dot could be added, false otherwhise
31 */
32 function couldAddDot(formulaToCheck) {
33- // A dot could be only after a number
34- if ((isNaN(formulaToCheck.slice(-1))) || (formulaToCheck === "")) {
35- return false;
36- }
37-
38 // If is after a number and it's the first dot of the calc it could be added
39 if (formulaToCheck.indexOf('.') === -1) {
40 return true;
41
42=== modified file 'app/ubuntu-calculator-app.qml'
43--- app/ubuntu-calculator-app.qml 2015-07-01 22:54:57 +0000
44+++ app/ubuntu-calculator-app.qml 2015-07-04 20:08:40 +0000
45@@ -136,10 +136,14 @@
46 });
47 // If the user press a number after the press of "=" we start a new
48 // formula, otherwise we continue with the old one
49- if (!isNaN(visual) && isLastCalculate) {
50+ if ((!isNaN(visual) || (visual === ".")) && isLastCalculate) {
51 isFormulaIsValidToCalculate = false;
52 longFormula = displayedInputText = shortFormula = "";
53 }
54+ // Add zero when decimal separator is not after number
55+ if ((visual === ".") && ((isNaN(displayedInputText.slice(textInputField.cursorPosition - 1, textInputField.cursorPosition))) || (longFormula === ""))) {
56+ visual = "0.";
57+ }
58 isLastCalculate = false;
59
60 if (visual === "()") {
61@@ -167,7 +171,7 @@
62 try {
63 shortFormula = formatBigNumber(mathJs.eval(shortFormula));
64 } catch(exception) {
65- console.log("Debug: Temp result: " + exception.toString() + " engine formula:" + shortFormula);
66+ console.log("Debug: Temp result: " + exception.toString() + " engine formula: " + shortFormula);
67 }
68
69 isFormulaIsValidToCalculate = false;
70
71=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
72--- tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-06-24 20:32:09 +0000
73+++ tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-07-04 20:08:40 +0000
74@@ -199,6 +199,27 @@
75 self.app.main_view.insert('-1=')
76 self._assert_result_is(u'0.666666666667')
77
78+ def test_adding_comma_without_number(self):
79+ # Validation of the decimal separator
80+ # We are trying to add several commas into one number
81+ # Only first comma in the number should be allowed
82+ self.app.main_view.insert('..1.3*.*5.=')
83+ self._assert_result_is(u'0.065')
84+ self._assert_history_contains(u'0.13Γ—0.5=0.065')
85+ self.app.main_view.insert('.7')
86+ self._assert_result_is(u'0.7')
87+
88+ def test_adding_comma_without_number_on_temp_result(self):
89+ self.app.main_view.insert('3+6*9')
90+ self._assert_result_is(u'3+6Γ—9')
91+ self.app.main_view.insert('+')
92+ self._assert_result_is(u'57+')
93+ self.app.main_view.insert('.0')
94+ self._assert_result_is(u'57+0.0')
95+ self.app.main_view.insert('=')
96+ self._assert_history_contains(u'3+6Γ—9+0.0=57')
97+ self._assert_result_is(u'57')
98+
99 def test_square(self):
100 self.app.main_view.insert('4')
101 self.app.main_view.show_scientific_keyboard()

Subscribers

People subscribed via source and target branches