Merge lp:~gang65/ubuntu-calculator-app/ubuntu-calculator-app-temporarly-result-fix into lp:ubuntu-calculator-app
- ubuntu-calculator-app-temporarly-result-fix
- Merge into trunk
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 |
Related bugs: |
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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:173
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:174
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:175
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:177
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Alan Pope πΊπ§π± π¦ (popey) wrote : | # |
Looks good! Thanks for fixing this.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Alan Pope πΊπ§π± π¦ (popey) wrote : | # |
Are you re-running and expecting it to pass? Seems to fail randomly?
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Alan Pope πΊπ§π± π¦ (popey) wrote : | # |
Have run the calculation manually on the phone as per this test:-
def test_operation_
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.
Bartosz Kosiorek (gang65) wrote : | # |
Thanks Alan.
Unfortunately we cannot do much with that.
The bug was reported on bignumber.
https:/
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Preview Diff
1 | === modified file 'app/ubuntu-calculator-app.qml' | |||
2 | --- app/ubuntu-calculator-app.qml 2015-04-24 16:22:05 +0000 | |||
3 | +++ app/ubuntu-calculator-app.qml 2015-04-26 22:42:08 +0000 | |||
4 | @@ -101,10 +101,36 @@ | |||
5 | 101 | displayedInputText = ""; | 101 | displayedInputText = ""; |
6 | 102 | } | 102 | } |
7 | 103 | 103 | ||
8 | 104 | /** | ||
9 | 105 | * Format bigNumber | ||
10 | 106 | */ | ||
11 | 107 | function formatBigNumber(bigNumberToFormat) { | ||
12 | 108 | |||
13 | 109 | // Maximum length of the result number | ||
14 | 110 | var NUMBER_LENGTH_LIMIT = 14; | ||
15 | 111 | |||
16 | 112 | if (mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}}).length > NUMBER_LENGTH_LIMIT) { | ||
17 | 113 | if (bigNumberToFormat.toExponential().length > NUMBER_LENGTH_LIMIT) { | ||
18 | 114 | // long format like: "1.2341322e+22" | ||
19 | 115 | var resultLenth = mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}, | ||
20 | 116 | precision: NUMBER_LENGTH_LIMIT}).length; | ||
21 | 117 | |||
22 | 118 | return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}, | ||
23 | 119 | precision: (NUMBER_LENGTH_LIMIT - resultLenth + NUMBER_LENGTH_LIMIT)}); | ||
24 | 120 | } else { | ||
25 | 121 | // short format like: "1e-10" | ||
26 | 122 | return bigNumberToFormat.toExponential(); | ||
27 | 123 | } | ||
28 | 124 | } else { | ||
29 | 125 | // exponential: Object An object containing two parameters, {Number} lower and {Number} upper, | ||
30 | 126 | // used by notation 'auto' to determine when to return exponential notation. | ||
31 | 127 | return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}}); | ||
32 | 128 | } | ||
33 | 129 | } | ||
34 | 130 | |||
35 | 104 | function formulaPush(visual) { | 131 | function formulaPush(visual) { |
36 | 105 | mathJs.config({ | 132 | mathJs.config({ |
39 | 106 | number: 'bignumber', // Choose 'number' (default) or 'bignumber' | 133 | number: 'bignumber' |
38 | 107 | precision: 64 | ||
40 | 108 | }); | 134 | }); |
41 | 109 | // If the user press a number after the press of "=" we start a new | 135 | // If the user press a number after the press of "=" we start a new |
42 | 110 | // formula, otherwise we continue with the old one | 136 | // formula, otherwise we continue with the old one |
43 | @@ -136,7 +162,7 @@ | |||
44 | 136 | // we display a temporary result instead the all operation | 162 | // we display a temporary result instead the all operation |
45 | 137 | if (isNaN(visual) && (visual.toString() !== ".") && isFormulaIsValidToCalculate) { | 163 | if (isNaN(visual) && (visual.toString() !== ".") && isFormulaIsValidToCalculate) { |
46 | 138 | try { | 164 | try { |
48 | 139 | shortFormula = mathJs.eval(shortFormula); | 165 | shortFormula = formatBigNumber(mathJs.eval(shortFormula)); |
49 | 140 | } catch(exception) { | 166 | } catch(exception) { |
50 | 141 | console.log("Error: math.js " + exception.toString() + " engine formula:" + shortFormula); | 167 | console.log("Error: math.js " + exception.toString() + " engine formula:" + shortFormula); |
51 | 142 | } | 168 | } |
52 | @@ -148,14 +174,16 @@ | |||
53 | 148 | if (textInputField.cursorPosition === textInputField.length ) { | 174 | if (textInputField.cursorPosition === textInputField.length ) { |
54 | 149 | longFormula += visual.toString(); | 175 | longFormula += visual.toString(); |
55 | 150 | shortFormula += visual.toString(); | 176 | shortFormula += visual.toString(); |
56 | 177 | displayedInputText = shortFormula; | ||
57 | 151 | } else { | 178 | } else { |
58 | 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); |
59 | 153 | shortFormula = longFormula; | 180 | shortFormula = longFormula; |
60 | 181 | var preservedCursorPosition = textInputField.cursorPosition; | ||
61 | 182 | displayedInputText = shortFormula; | ||
62 | 183 | textInputField.cursorPosition = preservedCursorPosition + visual.length; | ||
63 | 154 | } | 184 | } |
64 | 155 | 185 | ||
68 | 156 | var preservedCursorPosition = textInputField.cursorPosition; | 186 | |
66 | 157 | displayedInputText = shortFormula; | ||
67 | 158 | textInputField.cursorPosition = preservedCursorPosition + visual.length; | ||
69 | 159 | 187 | ||
70 | 160 | // Add here operators that have always priority | 188 | // Add here operators that have always priority |
71 | 161 | if ((visual.toString() === "*") || (visual.toString() === ")")) { | 189 | if ((visual.toString() === "*") || (visual.toString() === ")")) { |
72 | @@ -165,8 +193,7 @@ | |||
73 | 165 | 193 | ||
74 | 166 | function calculate() { | 194 | function calculate() { |
75 | 167 | mathJs.config({ | 195 | mathJs.config({ |
78 | 168 | number: 'bignumber', // Choose 'number' (default) or 'bignumber' | 196 | number: 'bignumber' |
77 | 169 | precision: 64 | ||
79 | 170 | }); | 197 | }); |
80 | 171 | if ((longFormula === '') || (isLastCalculate === true)) { | 198 | if ((longFormula === '') || (isLastCalculate === true)) { |
81 | 172 | errorAnimation.restart(); | 199 | errorAnimation.restart(); |
82 | @@ -184,20 +211,8 @@ | |||
83 | 184 | try { | 211 | try { |
84 | 185 | var result = mathJs.eval(longFormula); | 212 | var result = mathJs.eval(longFormula); |
85 | 186 | 213 | ||
88 | 187 | // Maximum length of the result number | 214 | result = formatBigNumber(result) |
87 | 188 | var NUMBER_LENGTH_LIMIT = 12; | ||
89 | 189 | 215 | ||
90 | 190 | if (mathJs.format(result).toString().length > NUMBER_LENGTH_LIMIT) { | ||
91 | 191 | if (result.toExponential().toString().length > NUMBER_LENGTH_LIMIT) { | ||
92 | 192 | // long format like: "1.2341322e+22" | ||
93 | 193 | result = mathJs.format(result, {notation: 'auto', precision: NUMBER_LENGTH_LIMIT}); | ||
94 | 194 | } else { | ||
95 | 195 | // short format like: "1e-10" | ||
96 | 196 | result = result.toExponential(); | ||
97 | 197 | } | ||
98 | 198 | } else { | ||
99 | 199 | result = mathJs.format(result) | ||
100 | 200 | } | ||
101 | 201 | } catch(exception) { | 216 | } catch(exception) { |
102 | 202 | // If the formula isn't right and we added brackets, we remove them | 217 | // If the formula isn't right and we added brackets, we remove them |
103 | 203 | for (var i = 0; i < numberOfOpenedBrackets; i++) { | 218 | for (var i = 0; i < numberOfOpenedBrackets; i++) { |
104 | @@ -208,8 +223,6 @@ | |||
105 | 208 | return false; | 223 | return false; |
106 | 209 | } | 224 | } |
107 | 210 | 225 | ||
108 | 211 | result = result.toString() | ||
109 | 212 | |||
110 | 213 | isLastCalculate = true; | 226 | isLastCalculate = true; |
111 | 214 | if (result === longFormula) { | 227 | if (result === longFormula) { |
112 | 215 | errorAnimation.restart(); | 228 | errorAnimation.restart(); |
113 | @@ -582,9 +595,9 @@ | |||
114 | 582 | textInputField.forceActiveFocus(); | 595 | textInputField.forceActiveFocus(); |
115 | 583 | if (editedCalculationIndex >= 0) { | 596 | if (editedCalculationIndex >= 0) { |
116 | 584 | calculationHistory.updateCalculationInDatabase(editedCalculationIndex, | 597 | calculationHistory.updateCalculationInDatabase(editedCalculationIndex, |
120 | 585 | calculationHistory.getContents().get(editedCalculationIndex).dbId, | 598 | calculationHistory.getContents().get(editedCalculationIndex).dbId, |
121 | 586 | true, | 599 | true, |
122 | 587 | favouriteTextField.text); | 600 | favouriteTextField.text); |
123 | 588 | favouriteTextField.text = ""; | 601 | favouriteTextField.text = ""; |
124 | 589 | editedCalculationIndex = -1; | 602 | editedCalculationIndex = -1; |
125 | 590 | } | 603 | } |
126 | @@ -657,7 +670,7 @@ | |||
127 | 657 | width: parent.width | 670 | width: parent.width |
128 | 658 | source: scrollableView.width > scrollableView.height ? "ui/LandscapeKeyboard.qml" : "ui/PortraitKeyboard.qml" | 671 | source: scrollableView.width > scrollableView.height ? "ui/LandscapeKeyboard.qml" : "ui/PortraitKeyboard.qml" |
129 | 659 | opacity: ((y + height) >= scrollableView.contentY) && | 672 | opacity: ((y + height) >= scrollableView.contentY) && |
131 | 660 | (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0 | 673 | (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0 |
132 | 661 | } | 674 | } |
133 | 662 | } | 675 | } |
134 | 663 | } | 676 | } |
135 | 664 | 677 | ||
136 | === modified file 'tests/autopilot/ubuntu_calculator_app/tests/test_main.py' | |||
137 | --- tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-24 19:58:17 +0000 | |||
138 | +++ tests/autopilot/ubuntu_calculator_app/tests/test_main.py 2015-04-26 22:42:08 +0000 | |||
139 | @@ -95,15 +95,15 @@ | |||
140 | 95 | self._assert_history_contains(u'9Γ9=81') | 95 | self._assert_history_contains(u'9Γ9=81') |
141 | 96 | 96 | ||
142 | 97 | def test_small_numbers(self): | 97 | def test_small_numbers(self): |
146 | 98 | self.app.main_view.insert('0.000000001+1=') | 98 | self.app.main_view.insert('0.0000000001+1=') |
147 | 99 | self._assert_result_is(u'1.000000001') | 99 | self._assert_result_is(u'1.0000000001') |
148 | 100 | self._assert_history_contains(u'0.000000001+1=1.000000001') | 100 | self._assert_history_contains(u'0.0000000001+1=1.0000000001') |
149 | 101 | 101 | ||
150 | 102 | self.app.main_view.delete() | 102 | self.app.main_view.delete() |
151 | 103 | 103 | ||
155 | 104 | self.app.main_view.insert('0.000000001/10=') | 104 | self.app.main_view.insert('0.0000000001/10=') |
156 | 105 | self._assert_result_is(u'1eβ10') | 105 | self._assert_result_is(u'1eβ11') |
157 | 106 | self._assert_history_contains(u'0.000000001Γ·10=1eβ10') | 106 | self._assert_history_contains(u'0.0000000001Γ·10=1eβ11') |
158 | 107 | 107 | ||
159 | 108 | def test_operation_on_large_numbers(self): | 108 | def test_operation_on_large_numbers(self): |
160 | 109 | self.app.main_view.insert('99999999999*99999999999=') | 109 | self.app.main_view.insert('99999999999*99999999999=') |
FAILED: Continuous integration, rev:172 91.189. 93.70:8080/ job/ubuntu- calculator- app-ci/ 311/ 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 2646 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 2646/artifact/ work/output/ *zip*/output. zip 91.189. 93.70:8080/ job/ubuntu- calculator- app-utopic- amd64-ci/ 90 91.189. 93.70:8080/ job/ubuntu- calculator- app-vivid- amd64-ci/ 33
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/ubuntu- calculator- app-ci/ 311/rebuild
http://