Merge lp:~f-riccardo87/ubuntu-calculator-app/new-formula-structure into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
- new-formula-structure
- Merge into old_trunk
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Gustavo Pichorim Boiko | ||||||||
Approved revision: | 48 | ||||||||
Merged at revision: | 47 | ||||||||
Proposed branch: | lp:~f-riccardo87/ubuntu-calculator-app/new-formula-structure | ||||||||
Merge into: | lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk | ||||||||
Diff against target: |
589 lines (+284/-172) 8 files modified
Simple/CalcKeyboard.qml (+4/-4) Simple/CalcLabel.qml (+7/-0) Simple/Screen.qml (+1/-0) Simple/SimplePage.qml (+34/-143) formula.js (+133/-0) tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py (+12/-0) tests/autopilot/ubuntu_calculator_app/tests/__init__.py (+12/-12) tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py (+81/-13) |
||||||||
To merge this branch: | bzr merge lp:~f-riccardo87/ubuntu-calculator-app/new-formula-structure | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gustavo Pichorim Boiko (community) | Approve | ||
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Riccardo Ferrazzo (community) | Abstain | ||
Review via email: mp+158100@code.launchpad.net |
Commit message
New formula implementation
Description of the change
Operations on the formula moved to a specific javascript class within another file.
Implementation of every preexisting function to use the new formula implementation.
C button now works as expected.
Some bugs corrected
- 47. By Riccardo Ferrazzo
-
comments added
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:47
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Riccardo Ferrazzo (f-riccardo87) wrote : | # |
> 108 + if(last.type === CALC.T_NUMBER || last.type ===
> CALC.T_
> 109 + screenFormula[
> last.value.
> 110 + } else {
> 111 + screenFormula.
> last.value.
>
> Would you mind adding a comment in the code explaining what is the use case
> being handle here? It will make it easier to understand and avoid wrong
> changes in the future.
Fixed!
Riccardo Ferrazzo (f-riccardo87) : | # |
Riccardo Ferrazzo (f-riccardo87) : | # |
Riccardo Ferrazzo (f-riccardo87) wrote : | # |
Excuse me, i maded some mistakes with my smartphone browser
- 48. By Riccardo Ferrazzo
-
merged autopilot tests
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:48
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Gustavo Pichorim Boiko (boiko) wrote : | # |
Looks good now!
Preview Diff
1 | === modified file 'Simple/CalcKeyboard.qml' |
2 | --- Simple/CalcKeyboard.qml 2013-04-07 11:18:00 +0000 |
3 | +++ Simple/CalcKeyboard.qml 2013-04-12 09:09:27 +0000 |
4 | @@ -33,7 +33,7 @@ |
5 | y: 0 |
6 | text: "C" |
7 | onClicked: { |
8 | - pop(); |
9 | + formulaPop(); |
10 | } |
11 | } |
12 | |
13 | @@ -50,14 +50,14 @@ |
14 | x: (calcGridUnit*11)*2 |
15 | y: 0 |
16 | text: "÷" |
17 | - onClicked: formulaPush(text) |
18 | + onClicked: formulaPush("/") |
19 | } |
20 | |
21 | KeyboardButton { |
22 | x: (calcGridUnit*11)*3 |
23 | y: 0 |
24 | text: "×" |
25 | - onClicked: formulaPush(text) |
26 | + onClicked: formulaPush("*") |
27 | } |
28 | |
29 | KeyboardButton { |
30 | @@ -85,7 +85,7 @@ |
31 | x: (calcGridUnit*11)*3 |
32 | y: (calcGridUnit*8) |
33 | text: "−" |
34 | - onClicked: formulaPush(text) |
35 | + onClicked: formulaPush('-') |
36 | } |
37 | |
38 | KeyboardButton { |
39 | |
40 | === modified file 'Simple/CalcLabel.qml' |
41 | --- Simple/CalcLabel.qml 2013-03-19 17:52:36 +0000 |
42 | +++ Simple/CalcLabel.qml 2013-04-12 09:09:27 +0000 |
43 | @@ -14,6 +14,7 @@ |
44 | property string labelText: "" |
45 | property int numbersHeight: units.gu(4) |
46 | property string numbersColor: '#757373' |
47 | + property bool isLast: false |
48 | |
49 | Row{ |
50 | id: row |
51 | @@ -39,6 +40,12 @@ |
52 | } |
53 | Label { |
54 | id: formulaLabel |
55 | + |
56 | + // this property is used by autopilot tests to find the correct item |
57 | + // FIXME: implement it in a better way |
58 | + property bool isLast: root.isLast |
59 | + |
60 | + objectName: "formulaLabel" |
61 | width: units.gu(25) |
62 | color: numbersColor |
63 | anchors.bottom: parent.bottom |
64 | |
65 | === modified file 'Simple/Screen.qml' |
66 | --- Simple/Screen.qml 2013-03-20 16:28:57 +0000 |
67 | +++ Simple/Screen.qml 2013-04-12 09:09:27 +0000 |
68 | @@ -77,6 +77,7 @@ |
69 | operation: _operation |
70 | numbersColor: (isLastItem && index === repeater.model.count-1) ? "#dd4814" : "#757373" |
71 | numbersHeight: (isLastItem && index === repeater.model.count-1) ? units.gu(7) : units.gu(4) |
72 | + isLast: (isLastItem && index === repeater.model.count-1) |
73 | |
74 | onLabelTextChanged: { |
75 | root.labelTextUpdated(index, labelText) |
76 | |
77 | === modified file 'Simple/SimplePage.qml' |
78 | --- Simple/SimplePage.qml 2013-04-06 08:47:15 +0000 |
79 | +++ Simple/SimplePage.qml 2013-04-12 09:09:27 +0000 |
80 | @@ -1,168 +1,59 @@ |
81 | import QtQuick 2.0 |
82 | import Ubuntu.Components 0.1 |
83 | import "../engine.js" as CALC |
84 | -//TODO: check for unneeded scanner initializations |
85 | +import "../formula.js" as F |
86 | |
87 | Page { |
88 | |
89 | - property var context: new CALC.Context; |
90 | - property var scanner: new CALC.Scanner(engineFormula.join(''), context); |
91 | + property var formula: new F.Formula() |
92 | property var screenFormula: [{_text:'', _operation: '', _number:''}] |
93 | - property var engineFormula: [''] |
94 | |
95 | function formulaPush(visual) { |
96 | - var engine; |
97 | - switch(visual){ |
98 | - case '÷': |
99 | - engine = '/'; |
100 | - break; |
101 | - case '×': |
102 | - engine = '*'; |
103 | - break; |
104 | - case '−': |
105 | - engine = '-'; |
106 | - break; |
107 | - default: |
108 | - engine = visual; |
109 | - } |
110 | - if(screenFormula.length === 0){ |
111 | - screenFormula.push({_text:'', _operation: '', _number:''}); |
112 | - } |
113 | - if(engineFormula.length === 0){ |
114 | - engineFormula.push(''); |
115 | - } |
116 | - if(screenFormula[screenFormula.length-1]._operation === "=") return; |
117 | try{ |
118 | - var n_scanner = new CALC.Scanner(engineFormula.join('') + engine, context); |
119 | - } catch(exception) { |
120 | - console.log("errore",exception) |
121 | + var last = formula.push(visual); |
122 | + } catch(exception){ |
123 | return; |
124 | } |
125 | - if(n_scanner.tokens.length > 1){ |
126 | - switch(n_scanner.tokens.last().type){ |
127 | - case CALC.T_PLUS: |
128 | - case CALC.T_MINUS: |
129 | - case CALC.T_DIV: |
130 | - case CALC.T_TIMES: |
131 | - if(n_scanner.tokens[n_scanner.tokens.length-2].type & CALC.T_OPERATOR) return; |
132 | - scanner = n_scanner; |
133 | - screenFormula.push({_text:'', _operation: '', _number:''}); |
134 | - screenFormula[screenFormula.length-1]._operation = visual; |
135 | - engineFormula.push(''); |
136 | - engineFormula[engineFormula.length-1] += engine; |
137 | - formulaView.currentOperatorsChanged(); |
138 | - return; |
139 | - case CALC.T_UNARY_PLUS: |
140 | - case CALC.T_UNARY_MINUS: |
141 | - if(n_scanner.tokens[n_scanner.tokens.length-2].type === CALC.T_UNARY_MINUS || |
142 | - n_scanner.tokens[n_scanner.tokens.length-2].type === CALC.T_UNARY_PLUS ) return; |
143 | - break; |
144 | - } |
145 | + |
146 | + //if the element to add is a number or an unary operator it is added to the current line |
147 | + //otherwise the element is a binary operator and it needs to be added to a new line |
148 | + if(last.type === CALC.T_NUMBER || last.type === CALC.T_UNARY_MINUS){ |
149 | + screenFormula[screenFormula.length - 1]._number += last.value.toString(); |
150 | + } else { |
151 | + screenFormula.push({_text:'', _operation: last.value.toString(), _number: ''}) |
152 | } |
153 | - scanner = n_scanner; |
154 | - screenFormula[screenFormula.length-1]._number += visual; |
155 | - engineFormula[engineFormula.length-1] += engine; |
156 | formulaView.currentOperatorsChanged(); |
157 | } |
158 | |
159 | function changeSign(){ |
160 | - if(screenFormula[screenFormula.length-1]._operation === "=") return; |
161 | - var prev_tokens = []; |
162 | - var add_minus = true; |
163 | + formula.changeSign(); |
164 | + formulaView.currentOperatorsChanged(); |
165 | + } |
166 | + |
167 | + function calculate() { |
168 | + try{ |
169 | + var result = formula.calculate(); |
170 | + } catch(exception) { |
171 | + formulaPop(); |
172 | + calculate(); |
173 | + } |
174 | + screenFormula.push({_text:'', _operation: '=', _number: result.toString()}); |
175 | + formulaView.currentOperatorsChanged(); |
176 | + } |
177 | + |
178 | + function formulaPop(){ |
179 | + if(screenFormula.length <= 1){ |
180 | + clear(); |
181 | + return; |
182 | + } |
183 | + formula.pop(); |
184 | screenFormula.pop(); |
185 | - engineFormula.pop(); |
186 | - if(scanner.tokens.length === 0){ |
187 | - prev_tokens.push(new CALC.Token('-', CALC.T_UNARY_MINUS)); |
188 | - } |
189 | - while(scanner.tokens.length > 0 ){ |
190 | - var last = scanner.tokens.pop(); |
191 | - if(last.type & CALC.T_OPERATOR && |
192 | - last.type !== CALC.T_UNARY_MINUS && |
193 | - last.type !== CALC.T_UNARY_PLUS ){ |
194 | - if(add_minus){ |
195 | - prev_tokens.push(new CALC.Token('-', CALC.T_UNARY_MINUS)); |
196 | - } |
197 | - prev_tokens.push(last); |
198 | - break; |
199 | - } |
200 | - if(last.type === CALC.T_UNARY_MINUS){ |
201 | - add_minus = false; |
202 | - continue; |
203 | - } |
204 | - prev_tokens.push(last); |
205 | - if(scanner.tokens.length === 0 && add_minus){ |
206 | - prev_tokens.push(new CALC.Token('-', CALC.T_UNARY_MINUS)); |
207 | - } |
208 | - } |
209 | - while(prev_tokens.length > 0){ |
210 | - var last = prev_tokens.pop(); |
211 | - var visual; |
212 | - switch(last.type){ |
213 | - case CALC.T_TIMES: |
214 | - visual = '×'; |
215 | - break; |
216 | - case CALC.T_DIV: |
217 | - visual = '÷'; |
218 | - break; |
219 | - case CALC.T_MINUS: |
220 | - visual = "−"; |
221 | - break; |
222 | - default: |
223 | - visual = last.value.toString(); |
224 | - } |
225 | - formulaPush(visual); |
226 | - } |
227 | - formulaView.currentOperatorsChanged(); |
228 | - } |
229 | - |
230 | - function calculate() { |
231 | - if(screenFormula[screenFormula.length-1]._operation === "="){ |
232 | - var lastOperation = engineFormula.pop(); |
233 | - var previousResult = screenFormula[screenFormula.length-1]._number |
234 | - engineFormula = [previousResult, lastOperation]; |
235 | - } |
236 | - try{ |
237 | - scanner = new CALC.Scanner(engineFormula.join(""), context); |
238 | - var result = new CALC.Parser(scanner).reduce(context); |
239 | - if (result === Number.POSITIVE_INFINITY) |
240 | - result = '∞'; |
241 | - else if (result === Number.NEGATIVE_INFINITY) |
242 | - result = '-∞'; |
243 | - } catch(exception) { |
244 | - if(exception instanceof CALC.DivisionByZeroError){ |
245 | - result = "division by zero error"; |
246 | - } else{ |
247 | - screenFormula.pop(); |
248 | - engineFormula.pop(); |
249 | - scanner = new CALC.Scanner(engineFormula.join(''), context); |
250 | - calculate(); |
251 | - return; |
252 | - } |
253 | - } |
254 | - screenFormula.push({_text:'', _operation: '=', _number:result.toString()}); |
255 | - formulaView.currentOperatorsChanged(); |
256 | - } |
257 | - |
258 | - function pop(){ |
259 | - if(screenFormula.length === 0) return; |
260 | - var lastRow = screenFormula.pop(); |
261 | - formulaView.currentOperatorsChanged(); |
262 | - if(screenFormula[screenFormula.length-1]._operation === "=") return; |
263 | - var oldFormula = screenFormula; |
264 | - clear(); |
265 | - for(var i = 0; i<oldFormula.length; i++){ |
266 | - if(oldFormula[i]._operation !== '') |
267 | - formulaPush(oldFormula[i]._operation); |
268 | - formulaPush(oldFormula[i]._number); |
269 | - screenFormula[screenFormula.length-1]._text = oldFormula[i]._text; |
270 | - } |
271 | formulaView.currentOperatorsChanged(); |
272 | } |
273 | |
274 | function clear(){ |
275 | screenFormula = [{_text:'', _operation: '', _number:''}]; |
276 | - engineFormula = ['']; |
277 | - scanner = new CALC.Scanner(engineFormula.join(''), context); |
278 | + formula = new F.Formula(); |
279 | formulaView.currentOperatorsChanged(); |
280 | } |
281 | |
282 | @@ -173,7 +64,7 @@ |
283 | return; |
284 | } |
285 | if(temp.tokens.length === 1 && temp.tokens.last().type === CALC.T_NUMBER){ |
286 | - formulaPush(numberToAdd, numberToAdd); |
287 | + formulaPush(numberToAdd); |
288 | } |
289 | } |
290 | |
291 | |
292 | === added file 'formula.js' |
293 | --- formula.js 1970-01-01 00:00:00 +0000 |
294 | +++ formula.js 2013-04-12 09:09:27 +0000 |
295 | @@ -0,0 +1,133 @@ |
296 | +Qt.include("engine.js"); |
297 | + |
298 | +var context = new Context; |
299 | + |
300 | +function Formula() { |
301 | + var previous = new Token(0, T_NUMBER); |
302 | + var formula = ''; |
303 | + var results = []; |
304 | + var lookupTbl = { |
305 | + '-': '−', |
306 | + '/': '÷', |
307 | + '*': '×' |
308 | + }; |
309 | + |
310 | + var _calculate = function(func){ |
311 | + try{ |
312 | + var result = parse(func, context); |
313 | + if (result === Number.POSITIVE_INFINITY) |
314 | + result = '∞'; |
315 | + else if (result === Number.NEGATIVE_INFINITY) |
316 | + result = '-∞'; |
317 | + }catch(exception){ |
318 | + if(exception instanceof DivisionByZeroError){ |
319 | + result = "division by zero error"; |
320 | + } else{ |
321 | + throw new SyntaxError("malformed calculation"); |
322 | + } |
323 | + } |
324 | + return result; |
325 | + } |
326 | + |
327 | + this.push = function(digit){ |
328 | + if(results.length > 0) throw new SyntaxError("cannot push"); |
329 | + var last = (new Scanner(previous.value.toString()+digit, context)).tokens.pop(); |
330 | + switch(last.type){ |
331 | + case T_PLUS: |
332 | + case T_MINUS: |
333 | + case T_DIV: |
334 | + case T_TIMES: |
335 | + if(previous.type & T_OPERATOR) return; |
336 | + break; |
337 | + case T_UNARY_PLUS: |
338 | + case T_UNARY_MINUS: |
339 | + if(previous.type === T_UNARY_MINUS || previous.type === T_UNARY_PLUS ) return; |
340 | + break; |
341 | + } |
342 | + formula += digit; |
343 | + previous = last; |
344 | + var ret = {value: '', type: last.type}; |
345 | + if(lookupTbl[digit] !== undefined){ |
346 | + ret.value = lookupTbl[digit]; |
347 | + } else { |
348 | + ret.value = digit; |
349 | + } |
350 | + return ret; |
351 | + }; |
352 | + |
353 | + this.pop = function(){ |
354 | + if(results.length > 0){ |
355 | + results.pop(); |
356 | + return; |
357 | + } |
358 | + var scannedFormula = new Scanner(formula, context); |
359 | + var last = {type:T_NUMBER}; |
360 | + var removeSize = 0; |
361 | + while(scannedFormula.tokens.length > 0 && (last.type === T_NUMBER || last.type === T_UNARY_PLUS || last.type === T_UNARY_MINUS)){ |
362 | + last = scannedFormula.tokens.pop(); |
363 | + removeSize += last.value.toString().length |
364 | + } |
365 | + formula = formula.substring(0, formula.length - removeSize); |
366 | + previous = scannedFormula.tokens.pop(); |
367 | + }; |
368 | + |
369 | + this.calculate = function(){ |
370 | + var result; |
371 | + var previousSize = previous.value.toString().length; |
372 | + if(formula.length <= previousSize) return; |
373 | + if(results.length > 0){ |
374 | + var scannedFormula = new Scanner(formula, context); |
375 | + var last = scannedFormula.tokens.pop(); |
376 | + var newFormula = last.value.toString(); |
377 | + while(last.type !== T_PLUS && |
378 | + last.type !== T_MINUS && |
379 | + last.type !== T_DIV && |
380 | + last.type !== T_TIMES ){ |
381 | + last = scannedFormula.tokens.pop(); |
382 | + newFormula = last.value.toString() + newFormula; |
383 | + } |
384 | + result = _calculate(results[results.length-1]+newFormula); |
385 | + } else { |
386 | + result = _calculate(formula); |
387 | + } |
388 | + results.push(result.toString()); |
389 | + return result; |
390 | + } |
391 | + |
392 | + this.changeSign = function(){ |
393 | + if(results.length > 0) throw new SyntaxError("cannot edit formula"); |
394 | + switch(previous.type){ |
395 | + case T_PLUS: |
396 | + case T_MINUS: |
397 | + case T_DIV: |
398 | + case T_TIMES: |
399 | + formulaPush("-"); |
400 | + break; |
401 | + default: |
402 | + var scannedFormula = new Scanner(formula, context); |
403 | + var last = {type: undefined}; |
404 | + var toAdd = []; |
405 | + var addMinus = true; |
406 | + while(scannedFormula.tokens.length > 0 && last.type !== T_PLUS && |
407 | + last.type !== T_MINUS && |
408 | + last.type !== T_DIV && |
409 | + last.type !== T_TIMES ){ |
410 | + last = scannedFormula.tokens.pop(); |
411 | + if(last.type !== T_UNARY_MINUS && last.type !== T_UNARY_PLUS){ |
412 | + toAdd.push(last); |
413 | + } else { |
414 | + if(last.type === T_UNARY_MINUS) |
415 | + addMinus = false; |
416 | + } |
417 | + } |
418 | + formulaPop(); |
419 | + while(toAdd.length > 0){ |
420 | + var el = toAdd.pop() |
421 | + formulaPush(el.value.toString()); |
422 | + if((el.type & T_OPERATOR) && addMinus){ |
423 | + formulaPush('-'); |
424 | + } |
425 | + } |
426 | + } |
427 | + } |
428 | +} |
429 | |
430 | === renamed file 'tests/autopilot/ubuntu_calculator_app/emulators/main_buttons.py' => 'tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py' |
431 | --- tests/autopilot/ubuntu_calculator_app/emulators/main_buttons.py 2013-03-22 12:15:46 +0000 |
432 | +++ tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py 2013-04-12 09:09:27 +0000 |
433 | @@ -4,3 +4,15 @@ |
434 | # This program is free software: you can redistribute it and/or modify it |
435 | # under the terms of the GNU General Public License version 3, as published |
436 | # by the Free Software Foundation. |
437 | + |
438 | +class SimplePage(object): |
439 | + """An emulator class that makes it easy to interact with the call panel.""" |
440 | + def __init__(self, app): |
441 | + self.app = app |
442 | + |
443 | + def get_button(self, text): |
444 | + return self.app.select_single('KeyboardButton', text=text) |
445 | + |
446 | + def get_formula_label(self): |
447 | + # FIXME: find a better way to find the latest formula label |
448 | + return self.app.select_single('Label', objectName='formulaLabel', isLast=True) |
449 | |
450 | === modified file 'tests/autopilot/ubuntu_calculator_app/tests/__init__.py' |
451 | --- tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-03-22 12:15:46 +0000 |
452 | +++ tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-04-12 09:09:27 +0000 |
453 | @@ -17,22 +17,22 @@ |
454 | |
455 | class CalculatorTestCase(AutopilotTestCase, QtIntrospectionTestMixin): |
456 | |
457 | - """A common testcase class that provides useful methods for calculator app.""" |
458 | - |
459 | - def setUp(self): |
460 | - super(CalculatorTestCase, self).setUp() |
461 | - |
462 | - if os.path.realpath(__file__).startswith("/usr/"): |
463 | + """A common testcase class that provides useful methods for calculator app.""" |
464 | + |
465 | + def setUp(self): |
466 | + super(CalculatorTestCase, self).setUp() |
467 | + |
468 | + if os.path.realpath(__file__).startswith("/usr/"): |
469 | self.launch_test_installed() |
470 | else: |
471 | self.launch_test_local() |
472 | |
473 | def launch_test_local(self): |
474 | - self.app = self.launch_test_application( |
475 | - "qmlscene", "../../ubuntu-calculator-app.qml" |
476 | - ) |
477 | + self.app = self.launch_test_application( |
478 | + "qmlscene", "../../ubuntu-calculator-app.qml" |
479 | + ) |
480 | |
481 | def launch_test_installed(self): |
482 | - self.app = self.launch_test_application( |
483 | - "ubuntu-calculator-app" |
484 | - ) |
485 | + self.app = self.launch_test_application( |
486 | + "ubuntu-calculator-app" |
487 | + ) |
488 | |
489 | === renamed file 'tests/autopilot/ubuntu_calculator_app/tests/test_main_buttons.py' => 'tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py' |
490 | --- tests/autopilot/ubuntu_calculator_app/tests/test_main_buttons.py 2013-03-22 14:17:43 +0000 |
491 | +++ tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py 2013-04-12 09:09:27 +0000 |
492 | @@ -14,16 +14,84 @@ |
493 | from autopilot.matchers import Eventually |
494 | |
495 | from ubuntu_calculator_app.tests import CalculatorTestCase |
496 | - |
497 | - |
498 | -class TestMainButtons(CalculatorTestCase): |
499 | - |
500 | - def setUp(self): |
501 | - super(TestMainButtons, self).setUp() |
502 | - |
503 | - def test_this(self): |
504 | - buttons = self.app.select_many("KeyboardButton") |
505 | - |
506 | - for keys in buttons: |
507 | - self.pointing_device.move_to_object(keys) |
508 | - self.pointing_device.click() |
509 | +from ubuntu_calculator_app.emulators.simple_page import SimplePage |
510 | + |
511 | +class TestSimplePage(CalculatorTestCase): |
512 | + |
513 | + def setUp(self): |
514 | + super(TestSimplePage, self).setUp() |
515 | + |
516 | + def test_this(self): |
517 | + buttons = self.app.select_many("KeyboardButton") |
518 | + |
519 | + for keys in buttons: |
520 | + self.pointing_device.move_to_object(keys) |
521 | + self.pointing_device.click() |
522 | + |
523 | + def test_operation_after_clear(self): |
524 | + """ Test that after clearing one calculation, the next is still correct (bug #1164973) """ |
525 | + oneButton = self.simple_page.get_button("1") |
526 | + plusButton = self.simple_page.get_button("+") |
527 | + equalsButton = self.simple_page.get_button("=") |
528 | + clearButton = self.simple_page.get_button("C") |
529 | + |
530 | + # type 1+1= |
531 | + self.pointing_device.move_to_object(oneButton) |
532 | + self.pointing_device.click() |
533 | + self.pointing_device.move_to_object(plusButton) |
534 | + self.pointing_device.click() |
535 | + self.pointing_device.move_to_object(oneButton) |
536 | + self.pointing_device.click() |
537 | + self.pointing_device.move_to_object(equalsButton) |
538 | + self.pointing_device.click() |
539 | + |
540 | + # make sure the result is already there |
541 | + self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("2"))) |
542 | + |
543 | + # now clear the input by pressing "C" three times |
544 | + self.pointing_device.move_to_object(clearButton) |
545 | + self.pointing_device.click() |
546 | + self.pointing_device.click() |
547 | + self.pointing_device.click() |
548 | + |
549 | + # and do the operation again to make sure the result is correct |
550 | + self.pointing_device.move_to_object(oneButton) |
551 | + self.pointing_device.click() |
552 | + self.pointing_device.move_to_object(plusButton) |
553 | + self.pointing_device.click() |
554 | + self.pointing_device.move_to_object(oneButton) |
555 | + self.pointing_device.click() |
556 | + self.pointing_device.move_to_object(equalsButton) |
557 | + self.pointing_device.click() |
558 | + |
559 | + # make sure the result is correct |
560 | + self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("2"))) |
561 | + |
562 | + def test_equals_dont_change_numbers(self): |
563 | + """ Test that typing a number and pressing "=" won't change the number (bug #1165894) """ |
564 | + oneButton = self.simple_page.get_button("1") |
565 | + twoButton = self.simple_page.get_button("2") |
566 | + threeButton = self.simple_page.get_button("3") |
567 | + equalsButton = self.simple_page.get_button("=") |
568 | + |
569 | + # type the initial number |
570 | + self.pointing_device.move_to_object(oneButton) |
571 | + self.pointing_device.click() |
572 | + self.pointing_device.move_to_object(twoButton) |
573 | + self.pointing_device.click() |
574 | + self.pointing_device.move_to_object(threeButton) |
575 | + self.pointing_device.click() |
576 | + |
577 | + # check that the label is displaying correctly |
578 | + self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("123"))) |
579 | + |
580 | + # click the "=" button |
581 | + self.pointing_device.move_to_object(equalsButton) |
582 | + self.pointing_device.click() |
583 | + |
584 | + # check that the label is still displaying correctly |
585 | + self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("123"))) |
586 | + |
587 | + @property |
588 | + def simple_page(self): |
589 | + return SimplePage(self.app) |
108 + if(last.type === CALC.T_NUMBER || last.type === CALC.T_ UNARY_MINUS) { screenFormula. length - 1]._number += last.value. toString( ); push({_ text:'' , _operation: last.value. toString( ), _number: ''})
109 + screenFormula[
110 + } else {
111 + screenFormula.
Would you mind adding a comment in the code explaining what is the use case being handle here? It will make it easier to understand and avoid wrong changes in the future.