ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #02864
[Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
Bartosz Kosiorek has proposed merging lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app.
Commit message:
Allow add comma without number
Requested reviews:
Ubuntu Calculator Developers (ubuntu-calculator-dev)
Related bugs:
Bug #1465979 in Ubuntu Calculator App: "Period doesn't work as in a calculator"
https://bugs.launchpad.net/ubuntu-calculator-app/+bug/1465979
For more details, see:
https://code.launchpad.net/~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number/+merge/262273
Allow add comma without number
--
Your team Ubuntu Calculator Developers is requested to review the proposed merge of lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app.
=== modified file 'app/engine/formula.js'
--- app/engine/formula.js 2015-03-26 21:16:14 +0000
+++ app/engine/formula.js 2015-06-17 21:13:40 +0000
@@ -90,14 +90,21 @@
return couldAddOperator(formula, stringToAddToFormula[0]);
}
- if (stringToAddToFormula === ".") {
+ // After decimal separator only number is allowed
+ if (isNaN(stringToAddToFormula)) {
+ if (formula.slice(-1) === ".") {
+ return false;
+ }
+ }
+
+ if (stringToAddToFormula.slice(-1) === ".") {
return couldAddDot(formula);
}
if (stringToAddToFormula === ")") {
return couldAddCloseBracket(formula);
}
-
+
// Validate complex numbers
if ((stringToAddToFormula === "i") || (!isNaN(stringToAddToFormula))){
if (formula.slice(-1) === "i") {
@@ -226,11 +233,6 @@
* @return bool: true if the dot could be added, false otherwhise
*/
function couldAddDot(formulaToCheck) {
- // A dot could be only after a number
- if ((isNaN(formulaToCheck.slice(-1))) || (formulaToCheck === "")) {
- return false;
- }
-
// If is after a number and it's the first dot of the calc it could be added
if (formulaToCheck.indexOf('.') === -1) {
return true;
=== modified file 'app/ubuntu-calculator-app.qml'
--- app/ubuntu-calculator-app.qml 2015-06-11 15:40:14 +0000
+++ app/ubuntu-calculator-app.qml 2015-06-17 21:13:40 +0000
@@ -137,6 +137,10 @@
if (!isNaN(visual) && isLastCalculate) {
longFormula = displayedInputText = shortFormula = "";
}
+ // Add zero when decimal separator is not after number
+ if ((visual === ".") && ((isNaN(longFormula.slice(textInputField.cursorPosition - 1, textInputField.cursorPosition))) || (longFormula === ""))) {
+ visual = "0.";
+ }
isLastCalculate = false;
if (visual === "()") {
=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
--- tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-26 22:41:49 +0000
+++ tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-06-17 21:13:40 +0000
@@ -192,6 +192,16 @@
self.app.main_view.insert('-1=')
self._assert_result_is(u'0.666666666667')
+ def test_comma_without_number_validation(self):
+ # Validation of the decimal separator
+ # We are trying to add several commas into one number
+ # Only first comma in the number should be allowed
+ self.app.main_view.insert('..1.3*.*5.=')
+ self._assert_result_is(u'0.065')
+ self._assert_history_contains(u'0.13×0.5=0.065')
+ self.app.main_view.insert('.7')
+ self._assert_result_is(u'0.0657')
+
def test_square(self):
self.app.main_view.insert('4')
self.app.main_view.show_scientific_keyboard()
Follow ups
-
[Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: noreply, 2015-07-05
-
[Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Bartosz Kosiorek, 2015-07-05
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-07-04
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Riccardo Padovani, 2015-07-02
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-07-01
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Niklas Wenzel, 2015-06-28
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-06-23
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Niklas Wenzel, 2015-06-21
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-06-21
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Riccardo Padovani, 2015-06-21
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Alan Pope , 2015-06-19
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Bartosz Kosiorek, 2015-06-18
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Niklas Wenzel, 2015-06-18
-
Re: [Merge] lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-comma-without-number into lp:ubuntu-calculator-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-06-17