Divide numbers #4
Labels
No labels
aira:blocked
aira:cancelled
aira:ci
aira:done
aira:implementing
aira:merging
aira:plan-review
aira:planning
aira:qa
aira:queued
aira:ready
aira:review
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/web-calculator-2#4
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add division with safe handling of division by zero.
Requirements
op=dividereturnsa / b.400 {"error": "division by zero"}; neverInfinityorNaN.÷button. Pressing9,÷,3,=shows3; dividing by zero showsErroron the display, andCclears it.Acceptance criteria
/api/calculate?a=9&b=3&op=dividereturns{"result":3}./api/calculate?a=1&b=4&op=dividereturns{"result":0.25}./api/calculate?a=1&b=0&op=dividereturns 400{"error":"division by zero"}.ErrorandCresets the display.Aira · queued
Aira picked up this task. Branch
aira/4-divide-numbers.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/4-divide-numbers.T3 thread:
mcp:launch:aa337a064bf6fc4e6a6b6d68b05ac0f882da824ed3170f180f1f2963f0de64f5Aira · Plan (round 1) at
5fb7cd91Wrote docs/plans/issue-4.md (goal, acceptance criteria, design, files, test plan, risks), committed, and pushed branch aira/4-divide-numbers.
docs/plans/issue-4.md
Issue #4: Divide numbers
Goal
Add division end to end: a pure
dividefunction inlib/calculator.js,GET /api/calculatesupport forop=dividewith explicit handling whenb === 0, and a÷button in the UI. The flow9,÷,3,=must show3. Dividing by zero must return HTTP 400 with{"error":"division by zero"}(neverInfinityorNaNin the API). On the page, division by zero showsErroron the display;Cresets the display. Addition, subtraction, multiplication, and existing error handling remain unchanged.Acceptance criteria
GET /api/calculate?a=9&b=3&op=dividereturns HTTP 200 with body{"result":3}.GET /api/calculate?a=1&b=4&op=dividereturns HTTP 200 with body{"result":0.25}.GET /api/calculate?a=1&b=0&op=dividereturns HTTP 400 with body{"error":"division by zero"}./has a divide button; division by zero showsErroron the display;Cclears the display (back to0).Design
Calculator module (
lib/calculator.js)divide(a, b)— returnsa / bfor finite numbers whenb !== 0(caller supplies parsed numbers).calculate(op, a, b):op === 'divide'in the allowed-operation check (alongsideadd,subtract, andmultiply).naandnb, ifop === 'divide'andnb === 0, return{ error: 'division by zero' }before callingdivide(do not rely onInfinityand the generic non-finite guard alone).dividewhenop === 'divide'; keep existing branches for other operations.opstill returns{ error: 'unknown operation' }.dividefrommodule.exportsalongside existing exports.parseNumberand, for successful divides, the existing non-finite result check (e.g.0 / 0should not surface asNaNin a 200 response).HTTP layer (
server.js)/api/calculatealready mapsout.errorto HTTP 400 with{ error: out.error }.UI (
public/index.html)÷key (Unicode division sign U+00F7) to the button grid inlabels, consistent with−and×.onKeyso÷callspressOperator('divide')(samewaitingForSecondflow as other operators).pressEquals, when the API returns a non-OK response withbody.error === 'division by zero', set the display to exactlyError(acceptance criterion 4). Other error responses may continue to show the API error string or existing behaviour so prior operations’ error handling stays intact.clearAllonCalready resetscurrentto'0'; after a divide-by-zeroErrorstate,Cmust still clear via existingclearAll.labelsso the 4-column grid still includes all digits, operators (+,−,×,÷),C,=, and.without removing existing keys.Files to change
lib/calculator.jsdivide; extendcalculateforop=divideandb === 0; exportdivide.server.jspublic/index.html÷) button; wirepressOperator('divide'); showErroron divide-by-zero API response.test/calculator.test.jsdivide,calculate('divide', ...), and divide-by-zero at module level.test/server.test.jstest/ui.test.jsdivide; HTML/script reflectsErrorfor divide-by-zero.Test plan
Unit tests (
test/calculator.test.js)divide(9, 3) === 3divide(1, 4) === 0.25calculate('divide', '9', '3')→{ result: 3 }calculate('divide', '1', '4')→{ result: 0.25 }calculate('divide', '1', '0')→{ error: 'division by zero' }calculate('divide', '1', '0')does not return{ result: Infinity }or NaNcalculate('pow', ...)still unknown errorHTTP tests (
test/server.test.js)Use existing
withServer+fetchpattern:?a=9&b=3&op=divide{ result: 3 }?a=1&b=4&op=divide{ result: 0.25 }?a=1&b=0&op=divide{ error: 'division by zero' }?a=1&b=0&op=dividebody must not containInfinityorNaN?a=2&b=3&op=add?a=2&b=5&op=subtract?a=6&b=7&op=multiply?a=1&b=2&op=powerrorstring?a=x&b=2&op=divideerrorstring (bad input)UI / page tests (
test/ui.test.js)labelsincludes÷(or equivalent documented label)pressOperator('divide')or equivalent+,−,×,=,C, andfetchto/api/calculateErrorwhen handling divide-by-zero (e.g. match on'Error'and'division by zero'in error path)clearAll/Cstill resets display after error stateCclears).Run
npm testlocally before every push; all tests must pass.Risks
Infinityvia raw/nb === 0check with fixed message before division.1/4 === 0.25)0/0or other NaN cases÷vs APIop=divide)op=divide; UI label is display-only; tests assert HTML contains÷.labelsto keep 4-column grid; UI test checks all prior buttons remain.Erroron divide-by-zeropressEquals; UI test assertsErrorstring in source.calculateonly; run full existing test suite.Implementation order (for later steps)
lib/calculator.js+test/calculator.test.jstest/server.test.js(server unchanged)public/index.htmlUI +test/ui.test.jsnpm test, then push branchaira/4-divide-numbersAttachment: plan-4-r1.md
Aira · plan review
Plan pushed at
5fb7cd91; independent Dodik plan review started.Aira · dodik-plan PASS on
5fb7cd91The plan at
5fb7cd9covers division end to end and matches the current code. Criteria 1–2 lock op=divide (9/3 → 3 and 1/4 → 0.25). Criterion 3 requires HTTP 400 with {"error":"division by zero"}, which is necessary because calculate’s existing non-finite guard would otherwise return "non-finite result" for 1/0. Criterion 4 covers the ÷ button, the display text Error, and C resetting the display to 0; the 9 ÷ 3 = flow is required in the goal and uses the existing operator path, with the value locked by criterion 1. server.js already maps module errors to HTTP 400. Unit and HTTP tests prove criteria 1–3, including Infinity/NaN, invalid input, and add/subtract/multiply regressions; UI source tests prove criterion 4. Scope stays in lib/calculator.js, public/index.html, and the three test files. The current suite is 40 passing tests.Checks performed
5fb7cd9and confirmed the allow-list, non-finite guard, HTTP 400 mapping, labels/onKey/pressEquals, and clearAll match the design.Attachment: dodik-plan-5fb7cd91.json
Aira · implementing
Plan approved by Dodik at
5fb7cd91. Implementation started.Aira · ci
Ready for review at
dcbfa202(PR #12). Waiting for CI.Implemented divide in calculator.js, ÷ button and Error UI in index.html, and tests covering all four acceptance criteria; npm test 48/48 pass; pushed feat commit on aira/4-divide-numbers.
Aira · CI passed on
dcbfa202Aira · review
CI is green on
dcbfa202. Independent Dodik and code review started.Aira · dodik PASS on
dcbfa202Division is implemented end to end at
dcbfa202acand matches the approved plan. The API returns 3 and 0.25 for the acceptance quotients and HTTP 400 {"error":"division by zero"} for division by zero, including 0/0 and -0, with no Infinity or NaN. The page has a ÷ button that calls op=divide; divide-by-zero sets the display to Error and C resets it to 0. npm test passed 48/48 with no skips, and the diff stays within the plan, calculator, UI, and tests.Checks performed
dcbfa20) with docs/plans/issue-4.mdAttachment: dodik-dcbfa202.json
Aira · reviewer PASS on
dcbfa202Issue #4 adds division consistently across lib/calculator.js, the existing /api/calculate handler, and the UI: explicit divide-by-zero returns {"error":"division by zero"} before division, successful quotients match acceptance examples, and the ÷ key is wired with Error display on divide-by-zero while other operations and validation behave as before. All automated tests pass and spot checks on 0/0, negatives, and multiply regression match the plan.
Checks performed
dcbfa202acAttachment: reviewer-dcbfa202.json
Aira · qa
Dodik and the reviewer passed on
dcbfa202. Preview deployed at http://127.0.0.1:45473; QA started.Aira · qa PASS on
dcbfa202Preview commit
dcbfa202acserves division correctly. GET /api/calculate?a=9&b=3&op=divide returns 200 {"result":3}, a=1&b=4 returns 200 {"result":0.25}, and a=1&b=0 returns 400 {"error":"division by zero"}. Zero in other forms (0/0, -0, 0.0, 00, 0e0) also returns that 400 error and never Infinity or NaN. The served page defines a ÷ control; pressing 9, ÷, 3, = shows 3, dividing by zero shows Error, and C resets the display to 0. Existing add, subtract, and multiply results and invalid-input 400s still hold. npm test passed 48 tests, including module and API division, division by zero, and page text.Checks performed
Attachment: qa-dcbfa202.json
Aira · merging
QA passed on
dcbfa202. Merging.Aira · Merged PR #12
Merge commit
6da87f598ceb41065e6ebedb622ef284edfe6b73from reviewed headdcbfa202acfbb767a2bec610b31501545cf09d47.dcbfa202acand matches the approved plan. The API returns 3 and 0.25 for the acceptance quotdcbfa202acserves division correctly. GET /api/calculate?a=9&b=3&op=divide returns 200 {"result":3}, a=1&b=4 return