Merge lp:~f-riccardo87/ubuntu-calculator-app/new-formula-structure into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Riccardo Ferrazzo
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
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

To post a comment you must log in.
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

108 + if(last.type === CALC.T_NUMBER || last.type === CALC.T_UNARY_MINUS){
109 + screenFormula[screenFormula.length - 1]._number += last.value.toString();
110 + } else {
111 + screenFormula.push({_text:'', _operation: last.value.toString(), _number: ''})

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.

review: Needs Fixing
47. By Riccardo Ferrazzo

comments added

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
Riccardo Ferrazzo (f-riccardo87) wrote :

> 108 + if(last.type === CALC.T_NUMBER || last.type ===
> CALC.T_UNARY_MINUS){
> 109 + screenFormula[screenFormula.length - 1]._number +=
> last.value.toString();
> 110 + } else {
> 111 + screenFormula.push({_text:'', _operation:
> last.value.toString(), _number: ''})
>
> 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!

review: Needs Resubmitting
Revision history for this message
Riccardo Ferrazzo (f-riccardo87) :
review: Approve
Revision history for this message
Riccardo Ferrazzo (f-riccardo87) :
review: Abstain
Revision history for this message
Riccardo Ferrazzo (f-riccardo87) wrote :

Excuse me, i maded some mistakes with my smartphone browser

48. By Riccardo Ferrazzo

merged autopilot tests

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
Gustavo Pichorim Boiko (boiko) wrote :

Looks good now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Simple/CalcKeyboard.qml'
--- Simple/CalcKeyboard.qml 2013-04-07 11:18:00 +0000
+++ Simple/CalcKeyboard.qml 2013-04-12 09:09:27 +0000
@@ -33,7 +33,7 @@
33 y: 033 y: 0
34 text: "C"34 text: "C"
35 onClicked: {35 onClicked: {
36 pop();36 formulaPop();
37 }37 }
38 }38 }
3939
@@ -50,14 +50,14 @@
50 x: (calcGridUnit*11)*250 x: (calcGridUnit*11)*2
51 y: 051 y: 0
52 text: "÷"52 text: "÷"
53 onClicked: formulaPush(text)53 onClicked: formulaPush("/")
54 }54 }
5555
56 KeyboardButton {56 KeyboardButton {
57 x: (calcGridUnit*11)*357 x: (calcGridUnit*11)*3
58 y: 058 y: 0
59 text: "×"59 text: "×"
60 onClicked: formulaPush(text)60 onClicked: formulaPush("*")
61 }61 }
6262
63 KeyboardButton {63 KeyboardButton {
@@ -85,7 +85,7 @@
85 x: (calcGridUnit*11)*385 x: (calcGridUnit*11)*3
86 y: (calcGridUnit*8)86 y: (calcGridUnit*8)
87 text: "−"87 text: "−"
88 onClicked: formulaPush(text)88 onClicked: formulaPush('-')
89 }89 }
9090
91 KeyboardButton {91 KeyboardButton {
9292
=== modified file 'Simple/CalcLabel.qml'
--- Simple/CalcLabel.qml 2013-03-19 17:52:36 +0000
+++ Simple/CalcLabel.qml 2013-04-12 09:09:27 +0000
@@ -14,6 +14,7 @@
14 property string labelText: ""14 property string labelText: ""
15 property int numbersHeight: units.gu(4)15 property int numbersHeight: units.gu(4)
16 property string numbersColor: '#757373'16 property string numbersColor: '#757373'
17 property bool isLast: false
1718
18 Row{19 Row{
19 id: row20 id: row
@@ -39,6 +40,12 @@
39 }40 }
40 Label {41 Label {
41 id: formulaLabel42 id: formulaLabel
43
44 // this property is used by autopilot tests to find the correct item
45 // FIXME: implement it in a better way
46 property bool isLast: root.isLast
47
48 objectName: "formulaLabel"
42 width: units.gu(25)49 width: units.gu(25)
43 color: numbersColor50 color: numbersColor
44 anchors.bottom: parent.bottom51 anchors.bottom: parent.bottom
4552
=== modified file 'Simple/Screen.qml'
--- Simple/Screen.qml 2013-03-20 16:28:57 +0000
+++ Simple/Screen.qml 2013-04-12 09:09:27 +0000
@@ -77,6 +77,7 @@
77 operation: _operation77 operation: _operation
78 numbersColor: (isLastItem && index === repeater.model.count-1) ? "#dd4814" : "#757373"78 numbersColor: (isLastItem && index === repeater.model.count-1) ? "#dd4814" : "#757373"
79 numbersHeight: (isLastItem && index === repeater.model.count-1) ? units.gu(7) : units.gu(4)79 numbersHeight: (isLastItem && index === repeater.model.count-1) ? units.gu(7) : units.gu(4)
80 isLast: (isLastItem && index === repeater.model.count-1)
8081
81 onLabelTextChanged: {82 onLabelTextChanged: {
82 root.labelTextUpdated(index, labelText)83 root.labelTextUpdated(index, labelText)
8384
=== modified file 'Simple/SimplePage.qml'
--- Simple/SimplePage.qml 2013-04-06 08:47:15 +0000
+++ Simple/SimplePage.qml 2013-04-12 09:09:27 +0000
@@ -1,168 +1,59 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import "../engine.js" as CALC3import "../engine.js" as CALC
4//TODO: check for unneeded scanner initializations4import "../formula.js" as F
55
6Page {6Page {
77
8 property var context: new CALC.Context;8 property var formula: new F.Formula()
9 property var scanner: new CALC.Scanner(engineFormula.join(''), context);
10 property var screenFormula: [{_text:'', _operation: '', _number:''}]9 property var screenFormula: [{_text:'', _operation: '', _number:''}]
11 property var engineFormula: ['']
1210
13 function formulaPush(visual) {11 function formulaPush(visual) {
14 var engine;
15 switch(visual){
16 case '÷':
17 engine = '/';
18 break;
19 case '×':
20 engine = '*';
21 break;
22 case '−':
23 engine = '-';
24 break;
25 default:
26 engine = visual;
27 }
28 if(screenFormula.length === 0){
29 screenFormula.push({_text:'', _operation: '', _number:''});
30 }
31 if(engineFormula.length === 0){
32 engineFormula.push('');
33 }
34 if(screenFormula[screenFormula.length-1]._operation === "=") return;
35 try{12 try{
36 var n_scanner = new CALC.Scanner(engineFormula.join('') + engine, context);13 var last = formula.push(visual);
37 } catch(exception) {14 } catch(exception){
38 console.log("errore",exception)
39 return;15 return;
40 }16 }
41 if(n_scanner.tokens.length > 1){17
42 switch(n_scanner.tokens.last().type){18 //if the element to add is a number or an unary operator it is added to the current line
43 case CALC.T_PLUS:19 //otherwise the element is a binary operator and it needs to be added to a new line
44 case CALC.T_MINUS:20 if(last.type === CALC.T_NUMBER || last.type === CALC.T_UNARY_MINUS){
45 case CALC.T_DIV:21 screenFormula[screenFormula.length - 1]._number += last.value.toString();
46 case CALC.T_TIMES:22 } else {
47 if(n_scanner.tokens[n_scanner.tokens.length-2].type & CALC.T_OPERATOR) return;23 screenFormula.push({_text:'', _operation: last.value.toString(), _number: ''})
48 scanner = n_scanner;
49 screenFormula.push({_text:'', _operation: '', _number:''});
50 screenFormula[screenFormula.length-1]._operation = visual;
51 engineFormula.push('');
52 engineFormula[engineFormula.length-1] += engine;
53 formulaView.currentOperatorsChanged();
54 return;
55 case CALC.T_UNARY_PLUS:
56 case CALC.T_UNARY_MINUS:
57 if(n_scanner.tokens[n_scanner.tokens.length-2].type === CALC.T_UNARY_MINUS ||
58 n_scanner.tokens[n_scanner.tokens.length-2].type === CALC.T_UNARY_PLUS ) return;
59 break;
60 }
61 }24 }
62 scanner = n_scanner;
63 screenFormula[screenFormula.length-1]._number += visual;
64 engineFormula[engineFormula.length-1] += engine;
65 formulaView.currentOperatorsChanged();25 formulaView.currentOperatorsChanged();
66 }26 }
6727
68 function changeSign(){28 function changeSign(){
69 if(screenFormula[screenFormula.length-1]._operation === "=") return;29 formula.changeSign();
70 var prev_tokens = [];30 formulaView.currentOperatorsChanged();
71 var add_minus = true;31 }
32
33 function calculate() {
34 try{
35 var result = formula.calculate();
36 } catch(exception) {
37 formulaPop();
38 calculate();
39 }
40 screenFormula.push({_text:'', _operation: '=', _number: result.toString()});
41 formulaView.currentOperatorsChanged();
42 }
43
44 function formulaPop(){
45 if(screenFormula.length <= 1){
46 clear();
47 return;
48 }
49 formula.pop();
72 screenFormula.pop();50 screenFormula.pop();
73 engineFormula.pop();
74 if(scanner.tokens.length === 0){
75 prev_tokens.push(new CALC.Token('-', CALC.T_UNARY_MINUS));
76 }
77 while(scanner.tokens.length > 0 ){
78 var last = scanner.tokens.pop();
79 if(last.type & CALC.T_OPERATOR &&
80 last.type !== CALC.T_UNARY_MINUS &&
81 last.type !== CALC.T_UNARY_PLUS ){
82 if(add_minus){
83 prev_tokens.push(new CALC.Token('-', CALC.T_UNARY_MINUS));
84 }
85 prev_tokens.push(last);
86 break;
87 }
88 if(last.type === CALC.T_UNARY_MINUS){
89 add_minus = false;
90 continue;
91 }
92 prev_tokens.push(last);
93 if(scanner.tokens.length === 0 && add_minus){
94 prev_tokens.push(new CALC.Token('-', CALC.T_UNARY_MINUS));
95 }
96 }
97 while(prev_tokens.length > 0){
98 var last = prev_tokens.pop();
99 var visual;
100 switch(last.type){
101 case CALC.T_TIMES:
102 visual = '×';
103 break;
104 case CALC.T_DIV:
105 visual = '÷';
106 break;
107 case CALC.T_MINUS:
108 visual = "−";
109 break;
110 default:
111 visual = last.value.toString();
112 }
113 formulaPush(visual);
114 }
115 formulaView.currentOperatorsChanged();
116 }
117
118 function calculate() {
119 if(screenFormula[screenFormula.length-1]._operation === "="){
120 var lastOperation = engineFormula.pop();
121 var previousResult = screenFormula[screenFormula.length-1]._number
122 engineFormula = [previousResult, lastOperation];
123 }
124 try{
125 scanner = new CALC.Scanner(engineFormula.join(""), context);
126 var result = new CALC.Parser(scanner).reduce(context);
127 if (result === Number.POSITIVE_INFINITY)
128 result = '∞';
129 else if (result === Number.NEGATIVE_INFINITY)
130 result = '-∞';
131 } catch(exception) {
132 if(exception instanceof CALC.DivisionByZeroError){
133 result = "division by zero error";
134 } else{
135 screenFormula.pop();
136 engineFormula.pop();
137 scanner = new CALC.Scanner(engineFormula.join(''), context);
138 calculate();
139 return;
140 }
141 }
142 screenFormula.push({_text:'', _operation: '=', _number:result.toString()});
143 formulaView.currentOperatorsChanged();
144 }
145
146 function pop(){
147 if(screenFormula.length === 0) return;
148 var lastRow = screenFormula.pop();
149 formulaView.currentOperatorsChanged();
150 if(screenFormula[screenFormula.length-1]._operation === "=") return;
151 var oldFormula = screenFormula;
152 clear();
153 for(var i = 0; i<oldFormula.length; i++){
154 if(oldFormula[i]._operation !== '')
155 formulaPush(oldFormula[i]._operation);
156 formulaPush(oldFormula[i]._number);
157 screenFormula[screenFormula.length-1]._text = oldFormula[i]._text;
158 }
159 formulaView.currentOperatorsChanged();51 formulaView.currentOperatorsChanged();
160 }52 }
16153
162 function clear(){54 function clear(){
163 screenFormula = [{_text:'', _operation: '', _number:''}];55 screenFormula = [{_text:'', _operation: '', _number:''}];
164 engineFormula = [''];56 formula = new F.Formula();
165 scanner = new CALC.Scanner(engineFormula.join(''), context);
166 formulaView.currentOperatorsChanged();57 formulaView.currentOperatorsChanged();
167 }58 }
16859
@@ -173,7 +64,7 @@
173 return;64 return;
174 }65 }
175 if(temp.tokens.length === 1 && temp.tokens.last().type === CALC.T_NUMBER){66 if(temp.tokens.length === 1 && temp.tokens.last().type === CALC.T_NUMBER){
176 formulaPush(numberToAdd, numberToAdd);67 formulaPush(numberToAdd);
177 }68 }
178 }69 }
17970
18071
=== added file 'formula.js'
--- formula.js 1970-01-01 00:00:00 +0000
+++ formula.js 2013-04-12 09:09:27 +0000
@@ -0,0 +1,133 @@
1Qt.include("engine.js");
2
3var context = new Context;
4
5function Formula() {
6 var previous = new Token(0, T_NUMBER);
7 var formula = '';
8 var results = [];
9 var lookupTbl = {
10 '-': '−',
11 '/': '÷',
12 '*': '×'
13 };
14
15 var _calculate = function(func){
16 try{
17 var result = parse(func, context);
18 if (result === Number.POSITIVE_INFINITY)
19 result = '∞';
20 else if (result === Number.NEGATIVE_INFINITY)
21 result = '-∞';
22 }catch(exception){
23 if(exception instanceof DivisionByZeroError){
24 result = "division by zero error";
25 } else{
26 throw new SyntaxError("malformed calculation");
27 }
28 }
29 return result;
30 }
31
32 this.push = function(digit){
33 if(results.length > 0) throw new SyntaxError("cannot push");
34 var last = (new Scanner(previous.value.toString()+digit, context)).tokens.pop();
35 switch(last.type){
36 case T_PLUS:
37 case T_MINUS:
38 case T_DIV:
39 case T_TIMES:
40 if(previous.type & T_OPERATOR) return;
41 break;
42 case T_UNARY_PLUS:
43 case T_UNARY_MINUS:
44 if(previous.type === T_UNARY_MINUS || previous.type === T_UNARY_PLUS ) return;
45 break;
46 }
47 formula += digit;
48 previous = last;
49 var ret = {value: '', type: last.type};
50 if(lookupTbl[digit] !== undefined){
51 ret.value = lookupTbl[digit];
52 } else {
53 ret.value = digit;
54 }
55 return ret;
56 };
57
58 this.pop = function(){
59 if(results.length > 0){
60 results.pop();
61 return;
62 }
63 var scannedFormula = new Scanner(formula, context);
64 var last = {type:T_NUMBER};
65 var removeSize = 0;
66 while(scannedFormula.tokens.length > 0 && (last.type === T_NUMBER || last.type === T_UNARY_PLUS || last.type === T_UNARY_MINUS)){
67 last = scannedFormula.tokens.pop();
68 removeSize += last.value.toString().length
69 }
70 formula = formula.substring(0, formula.length - removeSize);
71 previous = scannedFormula.tokens.pop();
72 };
73
74 this.calculate = function(){
75 var result;
76 var previousSize = previous.value.toString().length;
77 if(formula.length <= previousSize) return;
78 if(results.length > 0){
79 var scannedFormula = new Scanner(formula, context);
80 var last = scannedFormula.tokens.pop();
81 var newFormula = last.value.toString();
82 while(last.type !== T_PLUS &&
83 last.type !== T_MINUS &&
84 last.type !== T_DIV &&
85 last.type !== T_TIMES ){
86 last = scannedFormula.tokens.pop();
87 newFormula = last.value.toString() + newFormula;
88 }
89 result = _calculate(results[results.length-1]+newFormula);
90 } else {
91 result = _calculate(formula);
92 }
93 results.push(result.toString());
94 return result;
95 }
96
97 this.changeSign = function(){
98 if(results.length > 0) throw new SyntaxError("cannot edit formula");
99 switch(previous.type){
100 case T_PLUS:
101 case T_MINUS:
102 case T_DIV:
103 case T_TIMES:
104 formulaPush("-");
105 break;
106 default:
107 var scannedFormula = new Scanner(formula, context);
108 var last = {type: undefined};
109 var toAdd = [];
110 var addMinus = true;
111 while(scannedFormula.tokens.length > 0 && last.type !== T_PLUS &&
112 last.type !== T_MINUS &&
113 last.type !== T_DIV &&
114 last.type !== T_TIMES ){
115 last = scannedFormula.tokens.pop();
116 if(last.type !== T_UNARY_MINUS && last.type !== T_UNARY_PLUS){
117 toAdd.push(last);
118 } else {
119 if(last.type === T_UNARY_MINUS)
120 addMinus = false;
121 }
122 }
123 formulaPop();
124 while(toAdd.length > 0){
125 var el = toAdd.pop()
126 formulaPush(el.value.toString());
127 if((el.type & T_OPERATOR) && addMinus){
128 formulaPush('-');
129 }
130 }
131 }
132 }
133}
0134
=== renamed file 'tests/autopilot/ubuntu_calculator_app/emulators/main_buttons.py' => 'tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py'
--- tests/autopilot/ubuntu_calculator_app/emulators/main_buttons.py 2013-03-22 12:15:46 +0000
+++ tests/autopilot/ubuntu_calculator_app/emulators/simple_page.py 2013-04-12 09:09:27 +0000
@@ -4,3 +4,15 @@
4# This program is free software: you can redistribute it and/or modify it4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.6# by the Free Software Foundation.
7
8class SimplePage(object):
9 """An emulator class that makes it easy to interact with the call panel."""
10 def __init__(self, app):
11 self.app = app
12
13 def get_button(self, text):
14 return self.app.select_single('KeyboardButton', text=text)
15
16 def get_formula_label(self):
17 # FIXME: find a better way to find the latest formula label
18 return self.app.select_single('Label', objectName='formulaLabel', isLast=True)
719
=== modified file 'tests/autopilot/ubuntu_calculator_app/tests/__init__.py'
--- tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-03-22 12:15:46 +0000
+++ tests/autopilot/ubuntu_calculator_app/tests/__init__.py 2013-04-12 09:09:27 +0000
@@ -17,22 +17,22 @@
1717
18class CalculatorTestCase(AutopilotTestCase, QtIntrospectionTestMixin):18class CalculatorTestCase(AutopilotTestCase, QtIntrospectionTestMixin):
1919
20 """A common testcase class that provides useful methods for calculator app."""20 """A common testcase class that provides useful methods for calculator app."""
2121
22 def setUp(self):22 def setUp(self):
23 super(CalculatorTestCase, self).setUp()23 super(CalculatorTestCase, self).setUp()
2424
25 if os.path.realpath(__file__).startswith("/usr/"):25 if os.path.realpath(__file__).startswith("/usr/"):
26 self.launch_test_installed()26 self.launch_test_installed()
27 else:27 else:
28 self.launch_test_local()28 self.launch_test_local()
2929
30 def launch_test_local(self):30 def launch_test_local(self):
31 self.app = self.launch_test_application(31 self.app = self.launch_test_application(
32 "qmlscene", "../../ubuntu-calculator-app.qml"32 "qmlscene", "../../ubuntu-calculator-app.qml"
33 )33 )
3434
35 def launch_test_installed(self):35 def launch_test_installed(self):
36 self.app = self.launch_test_application(36 self.app = self.launch_test_application(
37 "ubuntu-calculator-app"37 "ubuntu-calculator-app"
38 )38 )
3939
=== renamed file 'tests/autopilot/ubuntu_calculator_app/tests/test_main_buttons.py' => 'tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py'
--- tests/autopilot/ubuntu_calculator_app/tests/test_main_buttons.py 2013-03-22 14:17:43 +0000
+++ tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py 2013-04-12 09:09:27 +0000
@@ -14,16 +14,84 @@
14from autopilot.matchers import Eventually14from autopilot.matchers import Eventually
1515
16from ubuntu_calculator_app.tests import CalculatorTestCase16from ubuntu_calculator_app.tests import CalculatorTestCase
1717from ubuntu_calculator_app.emulators.simple_page import SimplePage
1818
19class TestMainButtons(CalculatorTestCase):19class TestSimplePage(CalculatorTestCase):
2020
21 def setUp(self):21 def setUp(self):
22 super(TestMainButtons, self).setUp()22 super(TestSimplePage, self).setUp()
2323
24 def test_this(self):24 def test_this(self):
25 buttons = self.app.select_many("KeyboardButton")25 buttons = self.app.select_many("KeyboardButton")
2626
27 for keys in buttons:27 for keys in buttons:
28 self.pointing_device.move_to_object(keys)28 self.pointing_device.move_to_object(keys)
29 self.pointing_device.click()29 self.pointing_device.click()
30
31 def test_operation_after_clear(self):
32 """ Test that after clearing one calculation, the next is still correct (bug #1164973) """
33 oneButton = self.simple_page.get_button("1")
34 plusButton = self.simple_page.get_button("+")
35 equalsButton = self.simple_page.get_button("=")
36 clearButton = self.simple_page.get_button("C")
37
38 # type 1+1=
39 self.pointing_device.move_to_object(oneButton)
40 self.pointing_device.click()
41 self.pointing_device.move_to_object(plusButton)
42 self.pointing_device.click()
43 self.pointing_device.move_to_object(oneButton)
44 self.pointing_device.click()
45 self.pointing_device.move_to_object(equalsButton)
46 self.pointing_device.click()
47
48 # make sure the result is already there
49 self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("2")))
50
51 # now clear the input by pressing "C" three times
52 self.pointing_device.move_to_object(clearButton)
53 self.pointing_device.click()
54 self.pointing_device.click()
55 self.pointing_device.click()
56
57 # and do the operation again to make sure the result is correct
58 self.pointing_device.move_to_object(oneButton)
59 self.pointing_device.click()
60 self.pointing_device.move_to_object(plusButton)
61 self.pointing_device.click()
62 self.pointing_device.move_to_object(oneButton)
63 self.pointing_device.click()
64 self.pointing_device.move_to_object(equalsButton)
65 self.pointing_device.click()
66
67 # make sure the result is correct
68 self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("2")))
69
70 def test_equals_dont_change_numbers(self):
71 """ Test that typing a number and pressing "=" won't change the number (bug #1165894) """
72 oneButton = self.simple_page.get_button("1")
73 twoButton = self.simple_page.get_button("2")
74 threeButton = self.simple_page.get_button("3")
75 equalsButton = self.simple_page.get_button("=")
76
77 # type the initial number
78 self.pointing_device.move_to_object(oneButton)
79 self.pointing_device.click()
80 self.pointing_device.move_to_object(twoButton)
81 self.pointing_device.click()
82 self.pointing_device.move_to_object(threeButton)
83 self.pointing_device.click()
84
85 # check that the label is displaying correctly
86 self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("123")))
87
88 # click the "=" button
89 self.pointing_device.move_to_object(equalsButton)
90 self.pointing_device.click()
91
92 # check that the label is still displaying correctly
93 self.assertThat(self.simple_page.get_formula_label().text, Eventually(Equals("123")))
94
95 @property
96 def simple_page(self):
97 return SimplePage(self.app)

Subscribers

People subscribed via source and target branches