File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -273,11 +273,14 @@ public class Calculator
273
273
274
274
// numKey except `.Point` (NOTE: `case .Point` declared above)
275
275
case let numKey where contains ( Key . numKeys ( ) , numKey) :
276
- if acc == Key . Num0. rawValue {
277
- return newKey. rawValue // e.g. "0" -> "1" will be "1"
276
+ if acc == Key . Minus. rawValue + Key. Num0. rawValue {
277
+ return Key . Minus. rawValue + newKey. rawValue // e.g. "-0" then "1" will be "-1"
278
+ }
279
+ else if acc == Key . Num0. rawValue {
280
+ return newKey. rawValue // e.g. "0" then "1" will be "1"
278
281
}
279
282
else {
280
- return ( accumulatedString ?? " " ) + newKey. rawValue // e.g. "12" -> "3" will be "123"
283
+ return ( accumulatedString ?? " " ) + newKey. rawValue // e.g. "12" then "3" will be "123"
281
284
}
282
285
283
286
case . PlusMinus:
Original file line number Diff line number Diff line change @@ -139,6 +139,29 @@ class OutputSpec: QuickSpec
139
139
140
140
}
141
141
142
+ it ( " `± 0` should print `-0` " ) {
143
+
144
+ p. input = " ± "
145
+ expect ( p. output!) . to ( equal ( " -0 " ) )
146
+
147
+ p. input = " 0 "
148
+ expect ( p. output!) . to ( equal ( " -0 " ) )
149
+
150
+ }
151
+
152
+ it ( " `± 0 1` should print `-1` " ) {
153
+
154
+ p. input = " ± "
155
+ expect ( p. output!) . to ( equal ( " -0 " ) )
156
+
157
+ p. input = " 0 "
158
+ expect ( p. output!) . to ( equal ( " -0 " ) )
159
+
160
+ p. input = " 1 "
161
+ expect ( p. output!) . to ( equal ( " -1 " ) )
162
+
163
+ }
164
+
142
165
it ( " `1 ±` should print `-1` " ) {
143
166
144
167
p. input = " 1 "
You can’t perform that action at this time.
0 commit comments