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

Commit

Permalink
Bug Fix for #17 Multiple Presses of Multiplication or Division Error (#…
Browse files Browse the repository at this point in the history
…29)

* bug #17 fix

* tests for fix for #17
  • Loading branch information
alexanderjordanbaker authored and andrewagain committed Jun 2, 2019
1 parent 0b9711e commit 37b5607
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 37b5607

Please sign in to comment.