-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcalculator_mobile.rb
169 lines (163 loc) · 9.74 KB
/
calculator_mobile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
require 'kata'
kata 'Calculator' do
context 'Display Button' do
requirement 'Create a calculator app that is works with a string expression' do
detail 'The expression is of the form digits separated by commas: 1,2'
detail 'The expression is accessed by button named Display'
detail 'Clicking on the Display button will show the expression on the screen'
detail 'Changing the expression and pressing the [Return] key will update the display on the screen'
example '
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ 1,2┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┏━━━━━━━┓ ┃
┃ ┃Display┃ ┃
┃ ┗━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ 1,2 ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
'
end
requirement 'Validate the expression is of the proper form' do
detail 'Invalid expressions will be shown in the app'
example '
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ a,b┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┏━━━━━━━┓ ┃
┃ ┃Display┃ ┃
┃ ┗━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ Invalid Expression ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
'
end
end
context 'Add Button' do
requirement 'Create an Add button that sums the string expression' do
detail 'The event will return the sum of the digits'
detail 'The expression can contain 0, 1 or 2 numbers'
detail 'Then empty string will return 0'
example '
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ 1,2┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┏━━━━━━━┓ ┃
┃ ┃ Add ┃ ┃
┃ ┗━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ 3 ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
'
example '"" computes to 0'
example '"1" computes to 1'
example '"1,2" computes to 3'
end
requirement 'Allow the expression to contain an unknown amount of numbers' do
example '"1,2,3" computes to 6'
example '"1,2,5,8" computes to 16'
example '
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ 1,2,3┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┏━━━━━━━┓ ┃
┃ ┃ Add ┃ ┃
┃ ┗━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ 6 ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
'
end
end
context 'Diff Method' do
requirement 'Create an event that computes the consecutive differences' do
detail 'The expression must contain at least 2 digits'
detail 'Pressing the Sub button computes the differences while the Add button remains unchanged'
example '
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ 2,1┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┏━━━━━━━┓ ┏━━━━━━━┓ ┃
┃ ┃ Add ┃ ┃ Sub ┃ ┃
┃ ┗━━━━━━━┛ ┗━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ 1 ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
'
example '"1,0" compues to 1'
example '"3,2,1" computes to 0'
example '"5,4,3,2,1 computes to -5'
detail 'Expressions with less than 2 digits raise an exception'
example '"" or "5"'
end
end
context 'Prod Method' do
requirement 'Create a event that computes the product multiples in the expression' do
detail 'Pressing the Mul button will return the product of the numbers'
example '
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ 3,2┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┏━━━━━━━┓ ┏━━━━━━━┓ ┏━━━━━━━┓ ┃
┃ ┃ Add ┃ ┃ Sub ┃ ┃ Mul ┃ ┃
┃ ┗━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ 6 ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
'
example '"0" computes to 0'
example '"2,1" computes to 2'
example '"3,2,1" computes to 6'
end
end
context 'Div Method' do
requirement 'Create an event that computes the consecutive divisions in the expression' do
detail 'The Div will return the final quotient of the numbers'
detail 'Display an invalid expression message if it contains a zero'
example '
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃
┃ ┃ 3,2┃ ┃
┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┃
┃ ┏━━━━━━━┓ ┏━━━━━━━┓ ┏━━━━━━━┓ ┏━━━━━━━┓ ┃
┃ ┃ Add ┃ ┃ Sub ┃ ┃ Mul ┃ ┃ Div ┃ ┃
┃ ┗━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━┛ ┗━━━━━━━┛ ┃
┃ ┃
┃ ┃
┃ ┃
┃ 6 ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
'
example '"2,1" computes to 2'
example '"3,2,1" computes to 1'
example '"1,2,3" computes to 0'
example '"0,1,2" computes to 0'
example '"4,0,2" is an invalid expression'
end
end
end