Square root #10
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#10
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 a square root operation. It is the first unary operation, so the API must accept it without
b.Requirements
GET /api/calculate?a=<number>&op=sqrtreturns{"result": Math.sqrt(a)}.bis not required forsqrtand is ignored if present.400 {"error": "square root of a negative number"}.aandb.√button that applies to the number currently on the display immediately (no=needed). Pressing8,1,√shows9; a negative input showsError.Acceptance criteria
/api/calculate?a=81&op=sqrtreturns{"result":9}./api/calculate?a=2&op=sqrtreturns a result between 1.41421 and 1.41422./api/calculate?a=-4&op=sqrtreturns 400{"error":"square root of a negative number"}./api/calculate?a=1&op=add(missing b) still returns 400.√button.Aira · queued
Aira picked up this task. Branch
aira/10-square-root.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/10-square-root.T3 thread:
mcp:launch:492b71d839f941a37ca9a1e65f25e74d0cfd2b178634ba0b54a1657eb92ed620Aira · Plan (round 1) at
698345eaWrote docs/plans/issue-10.md (goal, acceptance criteria, unary sqrt design for lib/calculator.js, immediate √ UI, test plan, risks); ran npm test (46 pass); committed and pushed aira/10-square-root.
docs/plans/issue-10.md
Issue #10: Square root
Goal
Add a square root as the first unary operation: pure
sqrtusingMath.sqrt(a),GET /api/calculate?a=<number>&op=sqrtwithout requiringb(ignorebif present), and a√button on the calculator that applies immediately to the current display (no=). Preserve binary operations (add, subtract, multiply, divide, percent),/health,/static serving, and existing invalid-input handling.Acceptance criteria
/api/calculate?a=81&op=sqrtreturns{"result":9}./api/calculate?a=2&op=sqrtreturns a result between1.41421and1.41422./api/calculate?a=-4&op=sqrtreturns HTTP 400{"error":"square root of a negative number"}./api/calculate?a=1&op=add(missingb) still returns HTTP 400.√button; keypad flow8→1→√shows9; a negative input followed by√showsError.Design
Calculation module (
lib/calculator.js)sqrt(a)—Math.sqrt(a)after operand validation.calculate(rawA, rawB, op):op === 'sqrt':rawAwithparseOperand.a < 0, throwCalculatorError('square root of a negative number')before callingMath.sqrt(so the message is explicit, not the generic non-finite guard).sqrt(a); keep the existing finite-result guard for edge cases (Result out of range).parseOperand(rawB); ignorerawBentirely.add,subtract,multiply,divide,percentstill require both operands viaparseOperand(rawA)andparseOperand(rawB)(missing or emptyb→Invalid operand, satisfying AC4).op→CalculatorError('Unknown operation')(unchanged).sqrtalongside existing exports.HTTP layer (
server.js)url.searchParams.get('a'),get('b'), andget('op')intocalculate().calculate();bmay be absent from the query string or present and ignored forsqrt.UI (
public/index.html)√button (data-key="√") on the keypad grid; adjust layout if needed so digit /=placement stays usable.commitOperand/evaluate):applyUnary(op), reads currententryasa, callsGET /api/calculate?a=<entry>&op=sqrt(omitbfromURLSearchParams).res.ok: setentryand display toString(body.result), clearoperandA/pendingOp, setfreshEntry = true.setDisplay('Error')(same pattern asevaluate()).else if (key === '√') applyUnary('sqrt');(or inlinesqrtonly).+,−,×,÷,%,=) unchanged.Test layout
test/calculator.test.jssqrt,calculatewithop=sqrt, negative input, missing-btolerance; binary regressions.test/server.test.jstest/ui.test.js√button presence, immediate unary API call wiring, error display.Files to change
lib/calculator.jssqrt, unary branch incalculate.server.jspublic/index.html√button,applyUnary('sqrt')in click handler.test/calculator.test.jsb; add regression for binary missingb.test/server.test.jsbtest); optionalsqrtwith extrabignored.test/ui.test.js√in required-button list; script patterns for immediate unary sqrt.docs/plans/issue-10.mdNo changes to
package.json, CI workflows, or dependencies (Node built-ins only).Test plan
Unit (
test/calculator.test.js)sqrt(81) === 9;calculate('81', null, 'sqrt') === 9;calculate('81', undefined, 'sqrt') === 9.calculate('2', null, 'sqrt')in[1.41421, 1.41422].calculate('-4', null, 'sqrt')throwsCalculatorErrorwith messagesquare root of a negative number.calculate('1', null, 'add')throwsCalculatorError(Invalid operandonb).calculate('81', '999', 'sqrt') === 9(extrabignored).optests unchanged.HTTP (
test/server.test.js)a=81&op=sqrt{ result: 9 }a=2&op=sqrtresultin[1.41421, 1.41422]a=-4&op=sqrt{ error: 'square root of a negative number' }a=1&op=add{ error: string }a=81&b=0&op=sqrt{ result: 9 }(b ignored)UI / page (
test/ui.test.js)√; HTML hasdata-key="√"./api/calculatefor sqrt without relying solely onb+evaluate()for sqrt (e.g.applyUnary,op: 'sqrt', or query built with onlya).setDisplay('Error')on failed API;C→reset()/setDisplay('0').Pre-push
npm testlocally; all tests green beforegit push origin aira/10-square-root.Risks
Math.sqrt(-4)isNaNand might surface asResult out of rangea < 0check with the required error string (AC3).calculate()breaks binary opssqrt; full regression test suite.bfor sqrt and server rejects emptybb; UI should omitbfrom query for clarity and to match spec.√without breaking=span; match existing button styling.√indata-key, regex, and testsdata-key="√".sqrt(2)String(body.result)as for other ops; AC2 uses HTTP bounds only.Attachment: plan-10-r1.md
Aira · plan review
Plan pushed at
698345ea; independent Dodik plan review started.Aira · dodik-plan PASS on
698345eaThe issue #10 plan is complete and fits the current calculator. Acceptance criteria 1–5 cover exact sqrt(81), the sqrt(2) bounds, the negative-input 400 message, binary add still requiring b, and an immediate √ button (8 then 1 then √ shows 9; a negative display shows Error). The design correctly adds sqrt and an early unary branch in lib/calculator.js that parses only a, rejects a < 0 before Math.sqrt, and ignores b, while add, subtract, multiply, divide, and percent keep parsing both operands. server.js can stay unchanged because it already forwards a, b, and op and maps CalculatorError to 400. The page plan adds data-key="√" and an immediate applyUnary('sqrt') call that omits b and uses the existing Error display path. Unit and HTTP tests lock criteria 1–4, ignored extra b, and binary regressions; page tests lock the button and immediate sqrt wiring. Scope stays within the calculator module, the page, the three test files, and this plan. Baseline npm test is 46 passing.
Checks performed
Attachment: dodik-plan-698345ea.json
Aira · implementing
Plan approved by Dodik at
698345ea. Implementation started.Aira · ci
Ready for review at
cfd69be1(PR #14). Waiting for CI.Implemented unary sqrt in lib/calculator.js, immediate √ via applyUnary in public/index.html, and unit/API/UI tests for all five acceptance criteria; npm test 55/55 pass; pushed to aira/10-square-root.
Aira · CI passed on
cfd69be1Aira · review
CI is green on
cfd69be1. Independent Dodik and code review started.Aira · dodik PASS on
cfd69be1Commit
cfd69beadds unary square root as specified in docs/plans/issue-10.md: Math.sqrt on a alone, an exact negative-input error, b ignored when present, binary ops still requiring both operands, and an immediate √ button. npm test passed 55/55 with no skips or unrelated diffs. Live checks confirmed /api/calculate for 81, 2, -4, and add-without-b, and the page script shows 9 after 8, 1, √ and Error for a negative value.Checks performed
Attachment: dodik-cfd69be1.json
Aira · reviewer PASS on
cfd69be1The square-root feature is implemented correctly: unary
sqrtparsing and validation match the API contract, negative inputs return the required error message, binary operations and missing-bbehavior are unchanged, the UI applies sqrt immediately without sendingb, and all 55 automated tests pass. Manual checks on missing/empty/non-numerica,a=1&op=addwithoutb, and/healthshowed expected 200/400 responses with no regression.Checks performed
cfd69be1adAttachment: reviewer-cfd69be1.json
Aira · qa
Dodik and the reviewer passed on
cfd69be1. Preview deployed at http://127.0.0.1:40921; QA started.Aira · qa PASS on
cfd69be1Health reports sha
cfd69be1ad. GET /api/calculate?a=81&op=sqrt returns {"result":9}; a=2 returns 1.4142135623730951 (between 1.41421 and 1.41422); a=-4 returns 400 {"error":"square root of a negative number"}; a=1&op=add with no b returns 400. Extra b is ignored for sqrt, missing/empty/non-numeric operands and other binary ops without b still return 400, and binary ops with both operands still succeed. The served page includes a √ button wired to apply sqrt immediately (8 then 1 then √ requests a=81 and would show 9; a non-OK response sets the display to Error). npm test: 55 passed, including module, API, and page sqrt cases.Checks performed
Attachment: qa-cfd69be1.json
Aira · merging
QA passed on
cfd69be1. Merging.Aira · Merged PR #14
Merge commit
c3aab811250f6e6d0a54f3280eeaf08d1c3cc948from reviewed headcfd69be1adb9ec4986a8b288a4582a00c0911710.cfd69beadds unary square root as specified in docs/plans/issue-10.md: Math.sqrt on a alone, an exact negative-input error, b ignored when present, binarsqrtparsing and validation match the API contract, negative inputs return the required error message,cfd69be1ad. GET /api/calculate?a=81&op=sqrt returns {"result":9}; a=2 returns 1.4142135623730951 (between 1.414