Skip to content

Commit 37b5607

Browse files
alexanderjordanbakerandrewagain
authored andcommitted
Bug Fix for andrewagain#17 Multiple Presses of Multiplication or Division Error (andrewagain#29)
* bug andrewagain#17 fix * tests for fix for andrewagain#17
1 parent 0b9711e commit 37b5607

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/logic/calculate.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,20 @@ describe("calculate", function() {
154154
test(["2", "x", "2", "%"], {
155155
total: "0.04",
156156
});
157+
158+
//Test that pressing the multiplication or division sign multiple times should not affect the current computation
159+
test(["2", "x", "x"], {
160+
total: "2",
161+
operation: "x"
162+
});
163+
164+
test(["2", "÷", "÷"], {
165+
total: "2",
166+
operation: "÷"
167+
});
168+
169+
test(["2", "÷", "x", "+", "-", "x"], {
170+
total: "2",
171+
operation: 'x'
172+
});
157173
});

src/logic/operate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Big from "big.js";
22

33
export default function operate(numberOne, numberTwo, operation) {
44
const one = Big(numberOne || "0");
5-
const two = Big(numberTwo || "0");
5+
const two = Big(numberTwo || (operation === "÷" || operation === 'x' ? "1": "0")); //If dividing or multiplying, then 1 maintains current value in cases of null
66
if (operation === "+") {
77
return one.plus(two).toString();
88
}

0 commit comments

Comments
 (0)