Merge lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-temporarly-result-fix into lp:ubuntu-calculator-app

Proposed by Bartosz Kosiorek
Status: Merged
Approved by: Bartosz Kosiorek
Approved revision: 177
Merged at revision: 172
Proposed branch: lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-temporarly-result-fix
Merge into: lp:ubuntu-calculator-app
Diff against target: 160 lines (+46/-33)
2 files modified
app/ubuntu-calculator-app.qml (+40/-27)
tests/autopilot/ubuntu_calculator_app/tests/test_main.py (+6/-6)
To merge this branch: bzr merge lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-temporarly-result-fix
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Alan Pope 🍺🐧🐱 πŸ¦„ (community) Approve
Review via email: mp+257447@code.launchpad.net

Commit message

Temporary result fix

Description of the change

Temporary result fix

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: Needs Fixing (continuous-integration)
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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Looks good! Thanks for fixing this.

review: Approve
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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Are you re-running and expecting it to pass? Seems to fail randomly?

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
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Have run the calculation manually on the phone as per this test:-

    def test_operation_on_large_numbers(self):
        self.app.main_view.insert('99999999999*99999999999=')
        self._assert_result_is(u'9.9999999998e+21')
        self._assert_history_contains(u'99999999999Γ—99999999999='
                                      '9.9999999998e+21')

        self.app.main_view.insert('*100=')

        self._assert_result_is(u'9.9999999998e+23')
        self._assert_history_contains(u'9.9999999998e+21Γ—100='
                                      '9.9999999998e+23')

I get 9.9999999998e+23 on the calculator in the store on my mx4.
I get 9.0000000998e+23 on this branch in on my bq phone.

So it seems the new library is a bit broken still.

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

Thanks Alan.
Unfortunately we cannot do much with that.
The bug was reported on bignumber.js/decimal.js, here
https://github.com/MikeMcl/decimal.js/issues/15

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'app/ubuntu-calculator-app.qml'
--- app/ubuntu-calculator-app.qml 2015-04-24 16:22:05 +0000
+++ app/ubuntu-calculator-app.qml 2015-04-26 22:42:08 +0000
@@ -101,10 +101,36 @@
101 displayedInputText = "";101 displayedInputText = "";
102 }102 }
103103
104 /**
105 * Format bigNumber
106 */
107 function formatBigNumber(bigNumberToFormat) {
108
109 // Maximum length of the result number
110 var NUMBER_LENGTH_LIMIT = 14;
111
112 if (mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}}).length > NUMBER_LENGTH_LIMIT) {
113 if (bigNumberToFormat.toExponential().length > NUMBER_LENGTH_LIMIT) {
114 // long format like: "1.2341322e+22"
115 var resultLenth = mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
116 precision: NUMBER_LENGTH_LIMIT}).length;
117
118 return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10},
119 precision: (NUMBER_LENGTH_LIMIT - resultLenth + NUMBER_LENGTH_LIMIT)});
120 } else {
121 // short format like: "1e-10"
122 return bigNumberToFormat.toExponential();
123 }
124 } else {
125 // exponential: Object An object containing two parameters, {Number} lower and {Number} upper,
126 // used by notation 'auto' to determine when to return exponential notation.
127 return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}});
128 }
129 }
130
104 function formulaPush(visual) {131 function formulaPush(visual) {
105 mathJs.config({132 mathJs.config({
106 number: 'bignumber', // Choose 'number' (default) or 'bignumber'133 number: 'bignumber'
107 precision: 64
108 });134 });
109 // If the user press a number after the press of "=" we start a new135 // If the user press a number after the press of "=" we start a new
110 // formula, otherwise we continue with the old one136 // formula, otherwise we continue with the old one
@@ -136,7 +162,7 @@
136 // we display a temporary result instead the all operation162 // we display a temporary result instead the all operation
137 if (isNaN(visual) && (visual.toString() !== ".") && isFormulaIsValidToCalculate) {163 if (isNaN(visual) && (visual.toString() !== ".") && isFormulaIsValidToCalculate) {
138 try {164 try {
139 shortFormula = mathJs.eval(shortFormula);165 shortFormula = formatBigNumber(mathJs.eval(shortFormula));
140 } catch(exception) {166 } catch(exception) {
141 console.log("Error: math.js " + exception.toString() + " engine formula:" + shortFormula);167 console.log("Error: math.js " + exception.toString() + " engine formula:" + shortFormula);
142 }168 }
@@ -148,14 +174,16 @@
148 if (textInputField.cursorPosition === textInputField.length ) {174 if (textInputField.cursorPosition === textInputField.length ) {
149 longFormula += visual.toString();175 longFormula += visual.toString();
150 shortFormula += visual.toString();176 shortFormula += visual.toString();
177 displayedInputText = shortFormula;
151 } else {178 } else {
152 longFormula = longFormula.slice(0, textInputField.cursorPosition) + visual.toString() + longFormula.slice(textInputField.cursorPosition, longFormula.length);179 longFormula = longFormula.slice(0, textInputField.cursorPosition) + visual.toString() + longFormula.slice(textInputField.cursorPosition, longFormula.length);
153 shortFormula = longFormula;180 shortFormula = longFormula;
181 var preservedCursorPosition = textInputField.cursorPosition;
182 displayedInputText = shortFormula;
183 textInputField.cursorPosition = preservedCursorPosition + visual.length;
154 }184 }
155185
156 var preservedCursorPosition = textInputField.cursorPosition;186
157 displayedInputText = shortFormula;
158 textInputField.cursorPosition = preservedCursorPosition + visual.length;
159187
160 // Add here operators that have always priority188 // Add here operators that have always priority
161 if ((visual.toString() === "*") || (visual.toString() === ")")) {189 if ((visual.toString() === "*") || (visual.toString() === ")")) {
@@ -165,8 +193,7 @@
165193
166 function calculate() {194 function calculate() {
167 mathJs.config({195 mathJs.config({
168 number: 'bignumber', // Choose 'number' (default) or 'bignumber'196 number: 'bignumber'
169 precision: 64
170 });197 });
171 if ((longFormula === '') || (isLastCalculate === true)) {198 if ((longFormula === '') || (isLastCalculate === true)) {
172 errorAnimation.restart();199 errorAnimation.restart();
@@ -184,20 +211,8 @@
184 try {211 try {
185 var result = mathJs.eval(longFormula);212 var result = mathJs.eval(longFormula);
186213
187 // Maximum length of the result number214 result = formatBigNumber(result)
188 var NUMBER_LENGTH_LIMIT = 12;
189215
190 if (mathJs.format(result).toString().length > NUMBER_LENGTH_LIMIT) {
191 if (result.toExponential().toString().length > NUMBER_LENGTH_LIMIT) {
192 // long format like: "1.2341322e+22"
193 result = mathJs.format(result, {notation: 'auto', precision: NUMBER_LENGTH_LIMIT});
194 } else {
195 // short format like: "1e-10"
196 result = result.toExponential();
197 }
198 } else {
199 result = mathJs.format(result)
200 }
201 } catch(exception) {216 } catch(exception) {
202 // If the formula isn't right and we added brackets, we remove them217 // If the formula isn't right and we added brackets, we remove them
203 for (var i = 0; i < numberOfOpenedBrackets; i++) {218 for (var i = 0; i < numberOfOpenedBrackets; i++) {
@@ -208,8 +223,6 @@
208 return false;223 return false;
209 }224 }
210225
211 result = result.toString()
212
213 isLastCalculate = true;226 isLastCalculate = true;
214 if (result === longFormula) {227 if (result === longFormula) {
215 errorAnimation.restart();228 errorAnimation.restart();
@@ -582,9 +595,9 @@
582 textInputField.forceActiveFocus();595 textInputField.forceActiveFocus();
583 if (editedCalculationIndex >= 0) {596 if (editedCalculationIndex >= 0) {
584 calculationHistory.updateCalculationInDatabase(editedCalculationIndex,597 calculationHistory.updateCalculationInDatabase(editedCalculationIndex,
585 calculationHistory.getContents().get(editedCalculationIndex).dbId,598 calculationHistory.getContents().get(editedCalculationIndex).dbId,
586 true,599 true,
587 favouriteTextField.text);600 favouriteTextField.text);
588 favouriteTextField.text = "";601 favouriteTextField.text = "";
589 editedCalculationIndex = -1;602 editedCalculationIndex = -1;
590 }603 }
@@ -657,7 +670,7 @@
657 width: parent.width670 width: parent.width
658 source: scrollableView.width > scrollableView.height ? "ui/LandscapeKeyboard.qml" : "ui/PortraitKeyboard.qml"671 source: scrollableView.width > scrollableView.height ? "ui/LandscapeKeyboard.qml" : "ui/PortraitKeyboard.qml"
659 opacity: ((y + height) >= scrollableView.contentY) &&672 opacity: ((y + height) >= scrollableView.contentY) &&
660 (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0673 (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0
661 }674 }
662 }675 }
663 }676 }
664677
=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_main.py'
--- tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-24 19:58:17 +0000
+++ tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-26 22:42:08 +0000
@@ -95,15 +95,15 @@
95 self._assert_history_contains(u'9Γ—9=81')95 self._assert_history_contains(u'9Γ—9=81')
9696
97 def test_small_numbers(self):97 def test_small_numbers(self):
98 self.app.main_view.insert('0.000000001+1=')98 self.app.main_view.insert('0.0000000001+1=')
99 self._assert_result_is(u'1.000000001')99 self._assert_result_is(u'1.0000000001')
100 self._assert_history_contains(u'0.000000001+1=1.000000001')100 self._assert_history_contains(u'0.0000000001+1=1.0000000001')
101101
102 self.app.main_view.delete()102 self.app.main_view.delete()
103103
104 self.app.main_view.insert('0.000000001/10=')104 self.app.main_view.insert('0.0000000001/10=')
105 self._assert_result_is(u'1eβˆ’10')105 self._assert_result_is(u'1eβˆ’11')
106 self._assert_history_contains(u'0.000000001Γ·10=1eβˆ’10')106 self._assert_history_contains(u'0.0000000001Γ·10=1eβˆ’11')
107107
108 def test_operation_on_large_numbers(self):108 def test_operation_on_large_numbers(self):
109 self.app.main_view.insert('99999999999*99999999999=')109 self.app.main_view.insert('99999999999*99999999999=')

Subscribers

People subscribed via source and target branches