Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/calculator - add calculator functionallity #118

Merged
merged 46 commits into from
Jun 29, 2021

Conversation

nirtamir2
Copy link
Contributor

@nirtamir2 nirtamir2 commented Jun 26, 2021

This PR adds functionality to the calculator as in PuruVJ/macos-web#83.
It also adds tests with jest to the project.

Notice

It is currently implemented more like a windows calculator (which has subtle differences from the macOS calculator).
These functionalities can be implemented in the future (we have tests for the current implementation) but I think it's good enough for now.

Click here to see the differences
  • No (math order of operations)[https://en.wikipedia.org/wiki/Order_of_operations]. 1 + 2 * 3 = 7 in macOS but in windows 1 + 2 * 3 is more like 1 + 2 ( = 3 ) , 3 * 3 = 9
it("* before + - math order", () => {
  performPresses([1, "+", 2, "*", 3, "="]);
  expectResultToBe("7"); // this test will return 9 in this PR
});
  • Minus for building the numbers can be achieved via the +/- operator instead of -.
it("should allow writing minus as part of the number", () => {
  performPresses(["-", 6]);
  expectResultToBe("-6"); //  actual: 6
});

it("should show minus sign if it's the first key", () => {
  performPresses(["-"]);
  expectResultToBe("-"); // actual: 0
});

it("minus after operator show minus in result", () => {
  performPresses(["*", "-"]);
  expectResultToBe("-"); //  actual: 0
});
  • Other edge cases from macOS calculator implementation are not implemented (see this question for example)

Unimplemented small features that can be done separately (UI)

  • Add keyboard shortcuts
  • Add "blinking" effect to the result after the operator pressed
  • Decreasing font size if the result contains "overflow" (I fixed the precision to max 12 digits after dot).
    image

@vercel
Copy link

vercel bot commented Jun 26, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/puruvj/macos-web/2RZv46FsPXZtQNPRLRD4VDDJdWKw
✅ Preview: https://macos-web-git-fork-nirtamir2-feat-calculator-tdd-puruvj.vercel.app

@nirtamir2 nirtamir2 changed the title feat/calculator add calculator functionallity feat/calculator - add calculator functionallity Jun 26, 2021
@nirtamir2 nirtamir2 marked this pull request as ready for review June 26, 2021 18:45
@PuruVJ
Copy link
Owner

PuruVJ commented Jun 26, 2021

Looks great to me!! Will review tomorrow!

@PuruVJ PuruVJ merged commit b62a687 into PuruVJ:main Jun 29, 2021
@PuruVJ
Copy link
Owner

PuruVJ commented Jun 29, 2021

Sorry for the delay. Merged it. Your officially a contributor on macOS web now. Thank you for all your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants