Test cases for a calculator
Updated 2026-11-13 · 6 min read
A calculator looks simple until you ask how it handles precedence, decimals, overflow and percent. These 34 cases cover arithmetic, precision, boundaries, errors, functions, UI and speed.
Assumes a standard (not scientific) calculator app for web and mobile with digits, the four operators, decimal point, equals, percent, sign change, square root, C, CE, backspace and memory keys (M+, M−, MR, MC), with a 12-digit display. Where calculators genuinely differ, the expected result says "as specified": find out the rule before you run the case.
How to answer in an interview
Ask first: basic or scientific, physical or app, how many digits, does it follow operator precedence or calculate as you go, how does it round, what does percent do, and which locales does it support? Then group: basic arithmetic, decimals and precision, boundaries, errors, functions, and UI and performance. Mention precedence and floating point early; they show you know where calculators actually break.
Why 0.1 + 0.2 is a real test
Any app that does arithmetic with binary floating point numbers can show tiny errors. This is what JavaScript does without rounding (run with Node v24.22.2):
console.log(0.1 + 0.2);
console.log(Number((0.1 + 0.2).toFixed(10)));
console.log(5 / 0, 0 / 0);
console.log((1234567.5).toLocaleString("en-IN"));
console.log((1234567.5).toLocaleString("en-US"));
0.30000000000000004
0.3
Infinity NaN
12,34,567.5
1,234,567.5
So C09 catches a display that is not rounded, C19 and C20 catch an app that prints Infinity or NaN instead of an error message, and C32 checks Indian digit grouping.
Basic arithmetic
| ID | Category | Test case | Expected result |
|---|---|---|---|
| C01 | Functional | 2 + 3 = | 5 |
| C02 | Functional | 9 − 12 = | −3 |
| C03 | Functional | 6 × 7 = | 42 |
| C04 | Functional | 8 ÷ 2 = | 4 |
| C05 | Functional | 7 ÷ 2 = | 3.5 |
| C06 | Functional | 2 + 3 × 4 = | 14 with precedence or 20 with immediate execution, as specified |
| C07 | Functional | 5 + 2 = = | 9 if repeating the last operation is specified; otherwise stays 7 |
| C08 | Functional | 10 − 4 + 2 = | 8 |
Decimals and precision
| ID | Category | Test case | Expected result |
|---|---|---|---|
| C09 | Functional | 0.1 + 0.2 = | 0.3, not 0.30000000000000004 |
| C10 | Functional | 1 ÷ 3 = | 0.33333333333 filling the display, rounded as specified |
| C11 | Functional | 2 ÷ 3 = | Last digit rounded (…667) or cut off (…666), as specified |
| C12 | Negative | Type 1 . . 2 | Second decimal point ignored; shows 1.2 |
| C13 | Functional | Type 0 0 7 | Shows 7, not 007 |
Boundaries
| ID | Category | Test case | Expected result |
|---|---|---|---|
| C14 | Boundary | Type 13 digits on a 12-digit display | 13th digit ignored |
| C15 | Boundary | 999999999999 + 1 = | Overflow handled as specified (error or scientific notation); never a wrong number |
| C16 | Boundary | 0.0000001 ÷ 1000000 = | Scientific notation or 0, as specified; no garbage digits |
| C17 | Functional | −5 × −5 = (using the sign key) | 25 |
| C18 | Boundary | 99999999 × 99999999 = | Exact result if it fits, otherwise the specified overflow behaviour |
Errors
| ID | Category | Test case | Expected result |
|---|---|---|---|
| C19 | Negative | 5 ÷ 0 = | Clear message such as "Cannot divide by zero"; app does not crash; C clears it |
| C20 | Negative | 0 ÷ 0 = | Same error handling; never shows NaN |
| C21 | Negative | Square root of −9 | Error message on a standard calculator |
| C22 | Negative | 5 + × 3 = | Last operator pressed wins: 15 |
| C23 | Negative | 5 + = | Behaviour as specified (5 or 10); no crash |
Functions
| ID | Category | Test case | Expected result |
|---|---|---|---|
| C24 | Functional | 200 + 10 % = | Result as the spec defines percent (often 220); document the rule |
| C25 | Functional | 12 + 34, press CE, type 5, = | CE clears only 34; result 17. C clears everything |
| C26 | Functional | Type 123 and press backspace | Shows 12 |
| C27 | Functional | 10 M+, 3 M−, MR, then MC and MR | MR shows 7; after MC, MR shows 0 and the memory indicator goes off |
| C28 | Functional | Type 8 and press the sign key twice | −8, then 8 |
UI, compatibility and performance
| ID | Category | Test case | Expected result |
|---|---|---|---|
| C29 | Compatibility | Use a physical keyboard: digits, + − * /, Enter, Esc, Backspace | Each key does the same as its on-screen button |
| C30 | Functional | Copy a result; paste a number; paste text | Result copies; the number pastes; text is rejected |
| C31 | UI | Produce a 12-digit result on a narrow phone screen | Fully visible or shrunk to fit; never cut off silently |
| C32 | Functional | Show 1234567.5 with the locale set to India and to the US | 12,34,567.5 and 1,234,567.5, if locale grouping is supported |
| C33 | Compatibility | Rotate the phone mid-calculation | Current number and pending operation are kept |
| C34 | Performance | Press keys as fast as possible | Every press registered once, in order, without lag |
What to prioritise
Correctness first (C01 to C11), then errors (C19 to C23), because a calculator that shows a wrong number is worse than one that shows an error. In interviews, the common mistake is to state C06 or C24 as if there were only one right answer. Say that you would ask, then give both possibilities.
Downloads
Quick answers
Is 2 + 3 × 4 equal to 14 or 20 on a calculator?
It depends on the calculator. One that evaluates the whole expression with precedence gives 14; a simple immediate-execution calculator applies each operator as you press it and gives 20. Ask which behaviour is specified; both can be correct.
Why test 0.1 + 0.2?
Many apps store numbers as binary floating point, where 0.1 + 0.2 is not exactly 0.3. If the app shows 0.30000000000000004, it is not rounding its display, and money calculations built the same way may be wrong too.
What does the percent key do?
It varies between calculators. On many basic calculators 200 + 10 % gives 220 (10 percent of 200 added), while others treat 10 % as 0.1. Write the expected result from the spec, not from your own phone.
Want a project you can show in interviews?
The portfolio project kit walks you through testing a deliberately buggy app with Selenium or Playwright and API tests, then explaining it. The app itself is free.
