Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Bug Fix for #17 Multiple Presses of Multiplication or Division Error #29

Merged
merged 2 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/logic/calculate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,20 @@ describe("calculate", function() {
test(["2", "x", "2", "%"], {
total: "0.04",
});

//Test that pressing the multiplication or division sign multiple times should not affect the current computation
test(["2", "x", "x"], {
total: "2",
operation: "x"
});

test(["2", "÷", "÷"], {
total: "2",
operation: "÷"
});

test(["2", "÷", "x", "+", "-", "x"], {
total: "2",
operation: 'x'
});
});
2 changes: 1 addition & 1 deletion src/logic/operate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Big from "big.js";

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