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 | displayedInputText = ""; |
6 | } |
7 | |
8 | + /** |
9 | + * Format bigNumber |
10 | + */ |
11 | + function formatBigNumber(bigNumberToFormat) { |
12 | + |
13 | + // Maximum length of the result number |
14 | + var NUMBER_LENGTH_LIMIT = 14; |
15 | + |
16 | + if (mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}}).length > NUMBER_LENGTH_LIMIT) { |
17 | + if (bigNumberToFormat.toExponential().length > NUMBER_LENGTH_LIMIT) { |
18 | + // long format like: "1.2341322e+22" |
19 | + var resultLenth = mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}, |
20 | + precision: NUMBER_LENGTH_LIMIT}).length; |
21 | + |
22 | + return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}, |
23 | + precision: (NUMBER_LENGTH_LIMIT - resultLenth + NUMBER_LENGTH_LIMIT)}); |
24 | + } else { |
25 | + // short format like: "1e-10" |
26 | + return bigNumberToFormat.toExponential(); |
27 | + } |
28 | + } else { |
29 | + // exponential: Object An object containing two parameters, {Number} lower and {Number} upper, |
30 | + // used by notation 'auto' to determine when to return exponential notation. |
31 | + return mathJs.format(bigNumberToFormat, {exponential: {lower: 1e-10, upper: 1e10}}); |
32 | + } |
33 | + } |
34 | + |
35 | function formulaPush(visual) { |
36 | mathJs.config({ |
37 | - number: 'bignumber', // Choose 'number' (default) or 'bignumber' |
38 | - precision: 64 |
39 | + number: 'bignumber' |
40 | }); |
41 | // If the user press a number after the press of "=" we start a new |
42 | // formula, otherwise we continue with the old one |
43 | @@ -136,7 +162,7 @@ |
44 | // we display a temporary result instead the all operation |
45 | if (isNaN(visual) && (visual.toString() !== ".") && isFormulaIsValidToCalculate) { |
46 | try { |
47 | - shortFormula = mathJs.eval(shortFormula); |
48 | + shortFormula = formatBigNumber(mathJs.eval(shortFormula)); |
49 | } catch(exception) { |
50 | console.log("Error: math.js " + exception.toString() + " engine formula:" + shortFormula); |
51 | } |
52 | @@ -148,14 +174,16 @@ |
53 | if (textInputField.cursorPosition === textInputField.length ) { |
54 | longFormula += visual.toString(); |
55 | shortFormula += visual.toString(); |
56 | + displayedInputText = shortFormula; |
57 | } else { |
58 | longFormula = longFormula.slice(0, textInputField.cursorPosition) + visual.toString() + longFormula.slice(textInputField.cursorPosition, longFormula.length); |
59 | shortFormula = longFormula; |
60 | + var preservedCursorPosition = textInputField.cursorPosition; |
61 | + displayedInputText = shortFormula; |
62 | + textInputField.cursorPosition = preservedCursorPosition + visual.length; |
63 | } |
64 | |
65 | - var preservedCursorPosition = textInputField.cursorPosition; |
66 | - displayedInputText = shortFormula; |
67 | - textInputField.cursorPosition = preservedCursorPosition + visual.length; |
68 | + |
69 | |
70 | // Add here operators that have always priority |
71 | if ((visual.toString() === "*") || (visual.toString() === ")")) { |
72 | @@ -165,8 +193,7 @@ |
73 | |
74 | function calculate() { |
75 | mathJs.config({ |
76 | - number: 'bignumber', // Choose 'number' (default) or 'bignumber' |
77 | - precision: 64 |
78 | + number: 'bignumber' |
79 | }); |
80 | if ((longFormula === '') || (isLastCalculate === true)) { |
81 | errorAnimation.restart(); |
82 | @@ -184,20 +211,8 @@ |
83 | try { |
84 | var result = mathJs.eval(longFormula); |
85 | |
86 | - // Maximum length of the result number |
87 | - var NUMBER_LENGTH_LIMIT = 12; |
88 | + result = formatBigNumber(result) |
89 | |
90 | - if (mathJs.format(result).toString().length > NUMBER_LENGTH_LIMIT) { |
91 | - if (result.toExponential().toString().length > NUMBER_LENGTH_LIMIT) { |
92 | - // long format like: "1.2341322e+22" |
93 | - result = mathJs.format(result, {notation: 'auto', precision: NUMBER_LENGTH_LIMIT}); |
94 | - } else { |
95 | - // short format like: "1e-10" |
96 | - result = result.toExponential(); |
97 | - } |
98 | - } else { |
99 | - result = mathJs.format(result) |
100 | - } |
101 | } catch(exception) { |
102 | // If the formula isn't right and we added brackets, we remove them |
103 | for (var i = 0; i < numberOfOpenedBrackets; i++) { |
104 | @@ -208,8 +223,6 @@ |
105 | return false; |
106 | } |
107 | |
108 | - result = result.toString() |
109 | - |
110 | isLastCalculate = true; |
111 | if (result === longFormula) { |
112 | errorAnimation.restart(); |
113 | @@ -582,9 +595,9 @@ |
114 | textInputField.forceActiveFocus(); |
115 | if (editedCalculationIndex >= 0) { |
116 | calculationHistory.updateCalculationInDatabase(editedCalculationIndex, |
117 | - calculationHistory.getContents().get(editedCalculationIndex).dbId, |
118 | - true, |
119 | - favouriteTextField.text); |
120 | + calculationHistory.getContents().get(editedCalculationIndex).dbId, |
121 | + true, |
122 | + favouriteTextField.text); |
123 | favouriteTextField.text = ""; |
124 | editedCalculationIndex = -1; |
125 | } |
126 | @@ -657,7 +670,7 @@ |
127 | width: parent.width |
128 | source: scrollableView.width > scrollableView.height ? "ui/LandscapeKeyboard.qml" : "ui/PortraitKeyboard.qml" |
129 | opacity: ((y + height) >= scrollableView.contentY) && |
130 | - (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0 |
131 | + (y <= (scrollableView.contentY + scrollableView.height)) ? 1 : 0 |
132 | } |
133 | } |
134 | } |
135 | |
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 | self._assert_history_contains(u'9Γ9=81') |
141 | |
142 | def test_small_numbers(self): |
143 | - self.app.main_view.insert('0.000000001+1=') |
144 | - self._assert_result_is(u'1.000000001') |
145 | - self._assert_history_contains(u'0.000000001+1=1.000000001') |
146 | + self.app.main_view.insert('0.0000000001+1=') |
147 | + self._assert_result_is(u'1.0000000001') |
148 | + self._assert_history_contains(u'0.0000000001+1=1.0000000001') |
149 | |
150 | self.app.main_view.delete() |
151 | |
152 | - self.app.main_view.insert('0.000000001/10=') |
153 | - self._assert_result_is(u'1eβ10') |
154 | - self._assert_history_contains(u'0.000000001Γ·10=1eβ10') |
155 | + self.app.main_view.insert('0.0000000001/10=') |
156 | + self._assert_result_is(u'1eβ11') |
157 | + self._assert_history_contains(u'0.0000000001Γ·10=1eβ11') |
158 | |
159 | def test_operation_on_large_numbers(self): |
160 | 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://