Square root #10

Closed
opened 2026-11-21 01:41:55 +00:00 by lab-admin · 15 comments
Owner

Add a square root operation. It is the first unary operation, so the API must accept it without b.

Requirements

  • API: GET /api/calculate?a=<number>&op=sqrt returns {"result": Math.sqrt(a)}. b is not required for sqrt and is ignored if present.
  • Square root of a negative number returns 400 {"error": "square root of a negative number"}.
  • Binary operations still require both a and b.
  • UI: a √ button that applies to the number currently on the display immediately (no = needed). Pressing 8, 1, √ shows 9; a negative input shows Error.
  • Tests in the module, API and page.

Acceptance criteria

  1. /api/calculate?a=81&op=sqrt returns {"result":9}.
  2. /api/calculate?a=2&op=sqrt returns a result between 1.41421 and 1.41422.
  3. /api/calculate?a=-4&op=sqrt returns 400 {"error":"square root of a negative number"}.
  4. /api/calculate?a=1&op=add (missing b) still returns 400.
  5. The page has a working √ button.
Add a square root operation. It is the first unary operation, so the API must accept it without `b`. ## Requirements - API: `GET /api/calculate?a=<number>&op=sqrt` returns `{"result": Math.sqrt(a)}`. `b` is not required for `sqrt` and is ignored if present. - Square root of a negative number returns `400 {"error": "square root of a negative number"}`. - Binary operations still require both `a` and `b`. - UI: a `√` button that applies to the number currently on the display immediately (no `=` needed). Pressing `8`, `1`, `√` shows `9`; a negative input shows `Error`. - Tests in the module, API and page. ## Acceptance criteria 1. `/api/calculate?a=81&op=sqrt` returns `{"result":9}`. 2. `/api/calculate?a=2&op=sqrt` returns a result between 1.41421 and 1.41422. 3. `/api/calculate?a=-4&op=sqrt` returns 400 `{"error":"square root of a negative number"}`. 4. `/api/calculate?a=1&op=add` (missing b) still returns 400. 5. The page has a working `√` button.
Collaborator

Aira · queued

Aira picked up this task. Branch aira/10-square-root.

**Aira · queued** Aira picked up this task. Branch `aira/10-square-root`.
Collaborator

Aira · planning

Orchestrator thread started (composer-2.5). Planning on aira/10-square-root.

T3 thread: mcp:launch:492b71d839f941a37ca9a1e65f25e74d0cfd2b178634ba0b54a1657eb92ed620

**Aira · planning** Orchestrator thread started (composer-2.5). Planning on `aira/10-square-root`. T3 thread: `mcp:launch:492b71d839f941a37ca9a1e65f25e74d0cfd2b178634ba0b54a1657eb92ed620`
Collaborator

Aira · Plan (round 1) at 698345ea

Wrote 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 sqrt using Math.sqrt(a), GET /api/calculate?a=<number>&op=sqrt without requiring b (ignore b if 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

  1. /api/calculate?a=81&op=sqrt returns {"result":9}.
  2. /api/calculate?a=2&op=sqrt returns a result between 1.41421 and 1.41422.
  3. /api/calculate?a=-4&op=sqrt returns HTTP 400 {"error":"square root of a negative number"}.
  4. /api/calculate?a=1&op=add (missing b) still returns HTTP 400.
  5. The page has a working √ button; keypad flow 8 → 1 → √ shows 9; a negative input followed by √ shows Error.

Design

Calculation module (lib/calculator.js)

  • Add sqrt(a) — Math.sqrt(a) after operand validation.
  • Extend calculate(rawA, rawB, op):
    • Unary path for op === 'sqrt':
      • Parse only rawA with parseOperand.
      • If a < 0, throw CalculatorError('square root of a negative number') before calling Math.sqrt (so the message is explicit, not the generic non-finite guard).
      • Compute sqrt(a); keep the existing finite-result guard for edge cases (Result out of range).
      • Do not call parseOperand(rawB); ignore rawB entirely.
    • Binary path (unchanged ops): add, subtract, multiply, divide, percent still require both operands via parseOperand(rawA) and parseOperand(rawB) (missing or empty b → Invalid operand, satisfying AC4).
    • Unknown op → CalculatorError('Unknown operation') (unchanged).
  • Export sqrt alongside existing exports.

HTTP layer (server.js)

  • No structural changes: handler continues to pass url.searchParams.get('a'), get('b'), and get('op') into calculate().
  • Unary semantics live entirely in calculate(); b may be absent from the query string or present and ignored for sqrt.

UI (public/index.html)

  • Add a √ button (data-key="√") on the keypad grid; adjust layout if needed so digit / = placement stays usable.
  • Immediate unary apply (distinct from binary commitOperand / evaluate):
    • New helper, e.g. applyUnary(op), reads current entry as a, calls GET /api/calculate?a=<entry>&op=sqrt (omit b from URLSearchParams).
    • On res.ok: set entry and display to String(body.result), clear operandA / pendingOp, set freshEntry = true.
    • On failure: setDisplay('Error') (same pattern as evaluate()).
  • Click handler: else if (key === '√') applyUnary('sqrt'); (or inline sqrt only).
  • Regression: binary flow (+, −, ×, ÷, %, =) unchanged.

Test layout

File Purpose
test/calculator.test.js Unit tests for sqrt, calculate with op=sqrt, negative input, missing-b tolerance; binary regressions.
test/server.test.js HTTP tests for AC1–4; regression for binary ops and invalid input.
test/ui.test.js √ button presence, immediate unary API call wiring, error display.

Files to change

File Action
lib/calculator.js Modify — add sqrt, unary branch in calculate.
server.js No change expected — verify via tests.
public/index.html Modify — √ button, applyUnary('sqrt') in click handler.
test/calculator.test.js Modify — sqrt unit tests, negative error message, sqrt ignores missing b; add regression for binary missing b.
test/server.test.js Modify — API cases for AC1–3; explicit AC4 (already partially covered by missing-b test); optional sqrt with extra b ignored.
test/ui.test.js Modify — √ in required-button list; script patterns for immediate unary sqrt.
docs/plans/issue-10.md Create — this plan.

No changes to package.json, CI workflows, or dependencies (Node built-ins only).

Test plan

Unit (test/calculator.test.js)

Case Assert
AC1 (module) sqrt(81) === 9; calculate('81', null, 'sqrt') === 9; calculate('81', undefined, 'sqrt') === 9.
AC2 (module) calculate('2', null, 'sqrt') in [1.41421, 1.41422].
AC3 (module) calculate('-4', null, 'sqrt') throws CalculatorError with message square root of a negative number.
AC4 (module) calculate('1', null, 'add') throws CalculatorError (Invalid operand on b).
Unary calculate('81', '999', 'sqrt') === 9 (extra b ignored).
Regression Existing binary ops and unknown op tests unchanged.

HTTP (test/server.test.js)

Case Request Expect
AC1 a=81&op=sqrt 200, { result: 9 }
AC2 a=2&op=sqrt 200, result in [1.41421, 1.41422]
AC3 a=-4&op=sqrt 400, { error: 'square root of a negative number' }
AC4 a=1&op=add 400, { error: string }
Extra a=81&b=0&op=sqrt 200, { result: 9 } (b ignored)
Regression Existing binary success and invalid-input tests unchanged

UI / page (test/ui.test.js)

Case Assert
AC5 (controls) Required-button list includes √; HTML has data-key="√".
AC5 (integration) Script calls /api/calculate for sqrt without relying solely on b + evaluate() for sqrt (e.g. applyUnary, op: 'sqrt', or query built with only a).
Regression setDisplay('Error') on failed API; C → reset() / setDisplay('0').

Pre-push

  • Run npm test locally; all tests green before git push origin aira/10-square-root.

Risks

Risk Mitigation
Math.sqrt(-4) is NaN and might surface as Result out of range Explicit a < 0 check with the required error string (AC3).
Refactoring calculate() breaks binary ops Keep binary path identical; add early unary branch only for sqrt; full regression test suite.
UI sends b for sqrt and server rejects empty b Unary path must not parse b; UI should omit b from query for clarity and to match spec.
Keypad grid overflow with sixth function key Place √ without breaking = span; match existing button styling.
Unicode √ in data-key, regex, and tests Escape in UI test regex like other special keys; use literal data-key="√".
Float display for sqrt(2) Show String(body.result) as for other ops; AC2 uses HTTP bounds only.

Attachment: plan-10-r1.md

**Aira · Plan (round 1) at `698345ea`** Wrote 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. <details><summary>docs/plans/issue-10.md</summary> # Issue #10: Square root ## Goal Add a square root as the first **unary** operation: pure `sqrt` using `Math.sqrt(a)`, `GET /api/calculate?a=<number>&op=sqrt` without requiring `b` (ignore `b` if 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 1. `/api/calculate?a=81&op=sqrt` returns `{"result":9}`. 2. `/api/calculate?a=2&op=sqrt` returns a result between `1.41421` and `1.41422`. 3. `/api/calculate?a=-4&op=sqrt` returns HTTP 400 `{"error":"square root of a negative number"}`. 4. `/api/calculate?a=1&op=add` (missing `b`) still returns HTTP 400. 5. The page has a working `√` button; keypad flow `8` → `1` → `√` shows `9`; a negative input followed by `√` shows `Error`. ## Design ### Calculation module (`lib/calculator.js`) - Add `sqrt(a)` — `Math.sqrt(a)` after operand validation. - Extend `calculate(rawA, rawB, op)`: - **Unary path** for `op === 'sqrt'`: - Parse only `rawA` with `parseOperand`. - If `a < 0`, throw `CalculatorError('square root of a negative number')` **before** calling `Math.sqrt` (so the message is explicit, not the generic non-finite guard). - Compute `sqrt(a)`; keep the existing finite-result guard for edge cases (`Result out of range`). - Do **not** call `parseOperand(rawB)`; ignore `rawB` entirely. - **Binary path** (unchanged ops): `add`, `subtract`, `multiply`, `divide`, `percent` still require both operands via `parseOperand(rawA)` and `parseOperand(rawB)` (missing or empty `b` → `Invalid operand`, satisfying AC4). - Unknown `op` → `CalculatorError('Unknown operation')` (unchanged). - Export `sqrt` alongside existing exports. ### HTTP layer (`server.js`) - No structural changes: handler continues to pass `url.searchParams.get('a')`, `get('b')`, and `get('op')` into `calculate()`. - Unary semantics live entirely in `calculate()`; `b` may be absent from the query string or present and ignored for `sqrt`. ### UI (`public/index.html`) - Add a `√` button (`data-key="√"`) on the keypad grid; adjust layout if needed so digit / `=` placement stays usable. - **Immediate unary apply** (distinct from binary `commitOperand` / `evaluate`): - New helper, e.g. `applyUnary(op)`, reads current `entry` as `a`, calls `GET /api/calculate?a=<entry>&op=sqrt` (omit `b` from `URLSearchParams`). - On `res.ok`: set `entry` and display to `String(body.result)`, clear `operandA` / `pendingOp`, set `freshEntry = true`. - On failure: `setDisplay('Error')` (same pattern as `evaluate()`). - Click handler: `else if (key === '√') applyUnary('sqrt');` (or inline `sqrt` only). - Regression: binary flow (`+`, `−`, `×`, `÷`, `%`, `=`) unchanged. ### Test layout | File | Purpose | |------|---------| | `test/calculator.test.js` | Unit tests for `sqrt`, `calculate` with `op=sqrt`, negative input, missing-`b` tolerance; binary regressions. | | `test/server.test.js` | HTTP tests for AC1–4; regression for binary ops and invalid input. | | `test/ui.test.js` | `√` button presence, immediate unary API call wiring, error display. | ## Files to change | File | Action | |------|--------| | `lib/calculator.js` | **Modify** — add `sqrt`, unary branch in `calculate`. | | `server.js` | **No change expected** — verify via tests. | | `public/index.html` | **Modify** — `√` button, `applyUnary('sqrt')` in click handler. | | `test/calculator.test.js` | **Modify** — sqrt unit tests, negative error message, sqrt ignores missing `b`; add regression for binary missing `b`. | | `test/server.test.js` | **Modify** — API cases for AC1–3; explicit AC4 (already partially covered by missing-`b` test); optional `sqrt` with extra `b` ignored. | | `test/ui.test.js` | **Modify** — `√` in required-button list; script patterns for immediate unary sqrt. | | `docs/plans/issue-10.md` | **Create** — this plan. | No changes to `package.json`, CI workflows, or dependencies (Node built-ins only). ## Test plan ### Unit (`test/calculator.test.js`) | Case | Assert | |------|--------| | AC1 (module) | `sqrt(81) === 9`; `calculate('81', null, 'sqrt') === 9`; `calculate('81', undefined, 'sqrt') === 9`. | | AC2 (module) | `calculate('2', null, 'sqrt')` in `[1.41421, 1.41422]`. | | AC3 (module) | `calculate('-4', null, 'sqrt')` throws `CalculatorError` with message `square root of a negative number`. | | AC4 (module) | `calculate('1', null, 'add')` throws `CalculatorError` (`Invalid operand` on `b`). | | Unary | `calculate('81', '999', 'sqrt') === 9` (extra `b` ignored). | | Regression | Existing binary ops and unknown `op` tests unchanged. | ### HTTP (`test/server.test.js`) | Case | Request | Expect | |------|---------|--------| | AC1 | `a=81&op=sqrt` | 200, `{ result: 9 }` | | AC2 | `a=2&op=sqrt` | 200, `result` in `[1.41421, 1.41422]` | | AC3 | `a=-4&op=sqrt` | 400, `{ error: 'square root of a negative number' }` | | AC4 | `a=1&op=add` | 400, `{ error: string }` | | Extra | `a=81&b=0&op=sqrt` | 200, `{ result: 9 }` (b ignored) | | Regression | Existing binary success and invalid-input tests | unchanged | ### UI / page (`test/ui.test.js`) | Case | Assert | |------|--------| | AC5 (controls) | Required-button list includes `√`; HTML has `data-key="√"`. | | AC5 (integration) | Script calls `/api/calculate` for sqrt without relying solely on `b` + `evaluate()` for sqrt (e.g. `applyUnary`, `op: 'sqrt'`, or query built with only `a`). | | Regression | `setDisplay('Error')` on failed API; `C` → `reset()` / `setDisplay('0')`. | ### Pre-push - Run `npm test` locally; all tests green before `git push origin aira/10-square-root`. ## Risks | Risk | Mitigation | |------|------------| | `Math.sqrt(-4)` is `NaN` and might surface as `Result out of range` | Explicit `a < 0` check with the required error string (AC3). | | Refactoring `calculate()` breaks binary ops | Keep binary path identical; add early unary branch only for `sqrt`; full regression test suite. | | UI sends `b` for sqrt and server rejects empty `b` | Unary path must not parse `b`; UI should omit `b` from query for clarity and to match spec. | | Keypad grid overflow with sixth function key | Place `√` without breaking `=` span; match existing button styling. | | Unicode `√` in `data-key`, regex, and tests | Escape in UI test regex like other special keys; use literal `data-key="√"`. | | Float display for `sqrt(2)` | Show `String(body.result)` as for other ops; AC2 uses HTTP bounds only. | </details> Attachment: [plan-10-r1.md](https://aira-lab.cluster-dev.spkey.co/attachments/4fbc0a97-af03-4b67-9e3a-010a6e24f109)
Collaborator

Aira · plan review

Plan pushed at 698345ea; independent Dodik plan review started.

**Aira · plan review** Plan pushed at `698345ea`; independent Dodik plan review started.
Collaborator

Aira · dodik-plan PASS on 698345ea

The 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
  • Mapped every task requirement onto numbered criteria: sqrt(81)=9, sqrt(2) bounds, negative 400 with the exact error string, binary add missing b still 400, and a √ button that applies immediately (8, 1, √ → 9; negative → Error). b omitted is criteria 1–2; b present but ignored is specified in the design and in unit plus HTTP cases.
  • Read lib/calculator.js, server.js, public/index.html, and test/calculator.test.js, test/server.test.js, and test/ui.test.js. calculate currently parses both operands for add, subtract, multiply, divide, and percent, then rejects non-finite results; division-by-zero is a CalculatorError in calculate, matching the planned negative check. The server passes searchParams a, b, and op through and returns 400 {error: message}. The keypad is a 4-column grid with = spanning 3, and the script only has binary commitOperand/evaluate, so a separate immediate unary helper is the right UI change.
  • Confirmed Math.sqrt(81)===9, Math.sqrt(2) is within 1.41421 and 1.41422, and Math.sqrt(-4) is NaN, so the planned a<0 check is required to avoid Result out of range. The test plan states module and HTTP asserts for criteria 1–4, extra b ignored, and binary regressions, plus page asserts for data-key="√" and an immediate sqrt request that does not go through evaluate. Existing missing-b coverage is test/server.test.js for a=1&op=add. npm test: 46 pass, 0 fail.
  • Scope is limited to lib/calculator.js, public/index.html, the three test files, and docs/plans/issue-10.md. No package.json, dependency, or CI changes. Binary operations, /health, and / stay as they are.

Attachment: dodik-plan-698345ea.json

**Aira · dodik-plan PASS on `698345ea`** The 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. <details><summary>Checks performed</summary> - Mapped every task requirement onto numbered criteria: sqrt(81)=9, sqrt(2) bounds, negative 400 with the exact error string, binary add missing b still 400, and a √ button that applies immediately (8, 1, √ → 9; negative → Error). b omitted is criteria 1–2; b present but ignored is specified in the design and in unit plus HTTP cases. - Read lib/calculator.js, server.js, public/index.html, and test/calculator.test.js, test/server.test.js, and test/ui.test.js. calculate currently parses both operands for add, subtract, multiply, divide, and percent, then rejects non-finite results; division-by-zero is a CalculatorError in calculate, matching the planned negative check. The server passes searchParams a, b, and op through and returns 400 {error: message}. The keypad is a 4-column grid with = spanning 3, and the script only has binary commitOperand/evaluate, so a separate immediate unary helper is the right UI change. - Confirmed Math.sqrt(81)===9, Math.sqrt(2) is within 1.41421 and 1.41422, and Math.sqrt(-4) is NaN, so the planned a<0 check is required to avoid Result out of range. The test plan states module and HTTP asserts for criteria 1–4, extra b ignored, and binary regressions, plus page asserts for data-key="√" and an immediate sqrt request that does not go through evaluate. Existing missing-b coverage is test/server.test.js for a=1&op=add. npm test: 46 pass, 0 fail. - Scope is limited to lib/calculator.js, public/index.html, the three test files, and docs/plans/issue-10.md. No package.json, dependency, or CI changes. Binary operations, /health, and / stay as they are. </details> Attachment: [dodik-plan-698345ea.json](https://aira-lab.cluster-dev.spkey.co/attachments/d58c32f3-87dc-4f79-a85b-58f8d36758a1)
Collaborator

Aira · implementing

Plan approved by Dodik at 698345ea. Implementation started.

**Aira · implementing** Plan approved by Dodik at `698345ea`. Implementation started.
Collaborator

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** 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.
Collaborator

Aira · CI passed on cfd69be1

  • ci / test (pull_request): success
**Aira · CI passed on `cfd69be1`** - ci / test (pull_request): success
Collaborator

Aira · review

CI is green on cfd69be1. Independent Dodik and code review started.

**Aira · review** CI is green on `cfd69be1`. Independent Dodik and code review started.
Collaborator

Aira · dodik PASS on cfd69be1

Commit cfd69be adds 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
  • Diff vs origin/main is only calculator.js, public/index.html, calculator/server/ui tests, and docs/plans/issue-10.md
  • AC1: GET /api/calculate?a=81&op=sqrt returns 200 {"result":9}, covered by module and server tests
  • AC2: sqrt(2) is 1.4142135623730951, inside 1.41421–1.41422, covered by module and server tests
  • AC3: a=-4&op=sqrt returns 400 {"error":"square root of a negative number"}, covered by module and server tests
  • AC4: a=1&op=add with no b returns 400, covered by the existing server test and a new module test
  • AC5: data-key="√" calls applyUnary('sqrt') with only a and op; simulated keypad 8, 1, √ shows 9 and a negative result then √ shows Error
  • npm test: 55 passed, 0 failed, 0 skipped; no weakened assertions, debug leftovers, or README-level behaviour docs that went stale

Attachment: dodik-cfd69be1.json

**Aira · dodik PASS on `cfd69be1`** Commit cfd69be adds 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. <details><summary>Checks performed</summary> - Diff vs origin/main is only calculator.js, public/index.html, calculator/server/ui tests, and docs/plans/issue-10.md - AC1: GET /api/calculate?a=81&op=sqrt returns 200 {"result":9}, covered by module and server tests - AC2: sqrt(2) is 1.4142135623730951, inside 1.41421–1.41422, covered by module and server tests - AC3: a=-4&op=sqrt returns 400 {"error":"square root of a negative number"}, covered by module and server tests - AC4: a=1&op=add with no b returns 400, covered by the existing server test and a new module test - AC5: data-key="√" calls applyUnary('sqrt') with only a and op; simulated keypad 8, 1, √ shows 9 and a negative result then √ shows Error - npm test: 55 passed, 0 failed, 0 skipped; no weakened assertions, debug leftovers, or README-level behaviour docs that went stale </details> Attachment: [dodik-cfd69be1.json](https://aira-lab.cluster-dev.spkey.co/attachments/783a481b-b49c-4bd9-8cb1-149c8693be5b)
Collaborator

Aira · reviewer PASS on cfd69be1

The square-root feature is implemented correctly: unary sqrt parsing and validation match the API contract, negative inputs return the required error message, binary operations and missing-b behavior are unchanged, the UI applies sqrt immediately without sending b, and all 55 automated tests pass. Manual checks on missing/empty/non-numeric a, a=1&op=add without b, and /health showed expected 200/400 responses with no regression.

Checks performed
  • git diff origin/main...HEAD at cfd69be1ad
  • npm test (55/55 pass)
  • Manual calculator edge cases: null/empty/invalid a, 0, large a, -0 for op=sqrt
  • Manual HTTP: sqrt success, missing/empty/invalid a, AC4 a=1&op=add, GET /health
  • server.js unchanged; unary semantics only in calculate()

Attachment: reviewer-cfd69be1.json

**Aira · reviewer PASS on `cfd69be1`** The square-root feature is implemented correctly: unary `sqrt` parsing and validation match the API contract, negative inputs return the required error message, binary operations and missing-`b` behavior are unchanged, the UI applies sqrt immediately without sending `b`, and all 55 automated tests pass. Manual checks on missing/empty/non-numeric `a`, `a=1&op=add` without `b`, and `/health` showed expected 200/400 responses with no regression. <details><summary>Checks performed</summary> - git diff origin/main...HEAD at cfd69be1adb9ec4986a8b288a4582a00c0911710 - npm test (55/55 pass) - Manual calculator edge cases: null/empty/invalid a, 0, large a, -0 for op=sqrt - Manual HTTP: sqrt success, missing/empty/invalid a, AC4 a=1&op=add, GET /health - server.js unchanged; unary semantics only in calculate() </details> Attachment: [reviewer-cfd69be1.json](https://aira-lab.cluster-dev.spkey.co/attachments/edf63a18-9877-4696-9566-31caabb53f80)
Collaborator

Aira · qa

Dodik and the reviewer passed on cfd69be1. Preview deployed at http://127.0.0.1:40921; QA started.

**Aira · qa** Dodik and the reviewer passed on `cfd69be1`. Preview deployed at http://127.0.0.1:40921; QA started.
Collaborator

Aira · qa PASS on cfd69be1

Health 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 · qa PASS on `cfd69be1`** Health reports sha cfd69be1adb9ec4986a8b288a4582a00c0911710. 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. <details><summary>Checks performed</summary> - GET http://127.0.0.1:40921/health → 200 {"ok":true,"sha":"cfd69be1adb9ec4986a8b288a4582a00c0911710"} - GET http://127.0.0.1:40921/api/calculate?a=81&op=sqrt → 200 {"result":9} - GET http://127.0.0.1:40921/api/calculate?a=2&op=sqrt → 200 {"result":1.4142135623730951} - GET http://127.0.0.1:40921/api/calculate?a=-4&op=sqrt → 400 {"error":"square root of a negative number"} - GET http://127.0.0.1:40921/api/calculate?a=1&op=add → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=81&b=5&op=sqrt → 200 {"result":9} - GET http://127.0.0.1:40921/api/calculate?a=81&b=-9&op=sqrt → 200 {"result":9} - GET http://127.0.0.1:40921/api/calculate?a=-4&b=16&op=sqrt → 400 {"error":"square root of a negative number"} - GET http://127.0.0.1:40921/api/calculate?a=0&op=sqrt → 200 {"result":0} - GET http://127.0.0.1:40921/api/calculate?a=0.25&op=sqrt → 200 {"result":0.5} - GET http://127.0.0.1:40921/api/calculate?op=sqrt → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=&op=sqrt → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=foo&op=sqrt → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=1&op=subtract → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=1&op=multiply → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=1&op=divide → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=1&b=&op=add → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=1&b=x&op=add → 400 {"error":"Invalid operand"} - GET http://127.0.0.1:40921/api/calculate?a=2&b=3&op=add → 200 {"result":5} - GET http://127.0.0.1:40921/api/calculate?a=0&b=4&op=subtract → 200 {"result":-4} - GET http://127.0.0.1:40921/api/calculate?a=4&op=square → 400 {"error":"Unknown operation"} - GET http://127.0.0.1:40921/api/calculate?a=-0&op=sqrt → 200 {"result":0} - GET http://127.0.0.1:40921/api/calculate?a=-0.0001&op=sqrt → 400 {"error":"square root of a negative number"} - GET http://127.0.0.1:40921/ → 200 text/html with button data-key="√" calling applyUnary('sqrt') immediately (no =); non-OK API response sets display to Error - npm test → 55 pass, 0 fail, including sqrt module, API, and page tests </details> Attachment: [qa-cfd69be1.json](https://aira-lab.cluster-dev.spkey.co/attachments/4c366d9c-cf09-41b9-bf88-b346e175ba51)
Collaborator

Aira · merging

QA passed on cfd69be1. Merging.

**Aira · merging** QA passed on `cfd69be1`. Merging.
Collaborator

Aira · Merged PR #14

Merge commit c3aab811250f6e6d0a54f3280eeaf08d1c3cc948 from reviewed head cfd69be1adb9ec4986a8b288a4582a00c0911710.

Gate Verdict Summary
ci pass ci / test (pull_request)
dodik pass Commit cfd69be adds 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, binar
reviewer pass The square-root feature is implemented correctly: unary sqrt parsing and validation match the API contract, negative inputs return the required error message,
qa pass Health reports sha cfd69be1ad. GET /api/calculate?a=81&op=sqrt returns {"result":9}; a=2 returns 1.4142135623730951 (between 1.414
**Aira · Merged PR #14** Merge commit `c3aab811250f6e6d0a54f3280eeaf08d1c3cc948` from reviewed head `cfd69be1adb9ec4986a8b288a4582a00c0911710`. | Gate | Verdict | Summary | |---|---|---| | ci | pass | ci / test (pull_request) | | dodik | pass | Commit cfd69be adds 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, binar | | reviewer | pass | The square-root feature is implemented correctly: unary `sqrt` parsing and validation match the API contract, negative inputs return the required error message, | | qa | pass | Health reports sha cfd69be1adb9ec4986a8b288a4582a00c0911710. GET /api/calculate?a=81&op=sqrt returns {"result":9}; a=2 returns 1.4142135623730951 (between 1.414 |
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/web-calculator#10
No description provided.