Square root #6

Closed
opened 2026-11-21 03:35:34 +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/6-square-root.

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

Aira · planning

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

T3 thread: mcp:launch:a0898b02d8caeabf9df288722b8964b0f6e9c6696f98901144e4a59c3e30b45b

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

Aira · Plan (round 1) at 04cf219f

Wrote docs/plans/issue-6.md (goal, AC1–5, unary sqrt design, files, test plan, risks), committed, and pushed aira/6-square-root.

docs/plans/issue-6.md

Issue #6: Square root

Goal

Add square root as the first unary operation end-to-end: op=sqrt uses only operand a (Math.sqrt(a)), b is neither required nor validated when present, binary operations still require both operands, and the UI exposes a √ button that applies to the current display immediately (no =). Example: 8, 1, √ shows 9. Negative input under sqrt shows Error on the display.

Acceptance criteria

  1. GET /api/calculate?a=81&op=sqrt returns HTTP 200 with body {"result":9}.
  2. GET /api/calculate?a=2&op=sqrt returns HTTP 200 with a result between 1.41421 and 1.41422.
  3. GET /api/calculate?a=-4&op=sqrt returns HTTP 400 with body {"error":"square root of a negative number"}.
  4. GET /api/calculate?a=1&op=add (missing b) still returns HTTP 400 with an error string in the JSON body.
  5. The page at / has a working √ button: entering 8, 1, then √ shows 9; a negative displayed value followed by √ shows Error.

Design

Calculator module (lib/calculator.js)

  • Introduce a clear split between unary and binary operations inside calculate(a, b, op):
    • Unary (op === 'sqrt'): parse only a with parseNumber(a); do not read or validate b (extra query param is ignored).
    • Binary (add, subtract, multiply, divide, percent): parse both a and b as today so missing b still throws operand is required / related messages.
  • sqrt branch:
    • If x < 0, throw new Error('square root of a negative number') (exact message for AC3).
    • Otherwise result = Math.sqrt(x); if not finite, throw result out of range (parity with other ops).
  • sqrt(0) and positive non-integers use normal Math.sqrt (AC2).
  • Unknown op unchanged.

HTTP layer (server.js)

  • handleCalculate can remain structurally the same (pass a, b, op into calculate); unary-vs-binary operand rules live in lib/calculator.js.
  • Optional clarity: document in comments that b may be absent for sqrt only; no new routes or status-code mapping.
  • Existing catch (err) → sendJson(400, { error: err.message }) covers negative sqrt and missing b on binary ops.

UI (public/index.html)

  • Add a keypad button labeled √ with data-key="√" (Unicode root symbol).
  • Unary behavior (distinct from binary operators):
    • On √ click, take currentOperand() as a, fetch('/api/calculate?a=' + encodeURIComponent(a) + '&op=sqrt') (no b, no =).
    • On success: set display and operand to String(body.result); clear left / pendingOp / afterOp so the user can continue from the result.
    • On 400: if body.error === 'square root of a negative number', show Error (match division-by-zero UX); other errors may show the message or Error per existing patterns.
  • Binary operators (+, −, ×, ÷, %) and = behavior unchanged.
  • Keypad layout: place √ without removing existing keys (e.g. operator column or row near % / ÷), same button styling as other operators.

API contract note

  • Task extends the contract: for op=sqrt, b is optional and ignored; for all other supported ops, both a and b remain required. AGENTS.md can be updated in implementation if Aira wants docs in sync (not required for AC).

Test layout

File Scope
test/calculator.test.js Unit tests for sqrt, negative reject, binary still needs b, regressions
test/server.test.js HTTP tests AC1–4, sqrt with ignored b, regressions
test/ui.test.js √ button in HTML; script wires immediate sqrt API call and negative → Error

Files to change

File Action
lib/calculator.js Modify — unary sqrt; binary ops unchanged regarding b
public/index.html Modify — √ button; immediate unary handler
test/calculator.test.js Modify — sqrt unit cases + AC4 at module level + regressions
test/server.test.js Modify — sqrt API AC1–3; missing b on add (AC4); optional b ignored on sqrt
test/ui.test.js Modify — add √ to required keys; assert sqrt op and error mapping

Test plan

Unit (test/calculator.test.js)

Case Maps to
calculate('81', undefined, 'sqrt') → 9 AC1 (module)
calculate('2', null, 'sqrt') → ~√2 within bounds AC2 (module)
calculate('-4', undefined, 'sqrt') throws square root of a negative number AC3 (module)
calculate('1', undefined, 'add') throws (operand / required) AC4 (module)
calculate('9', '999', 'sqrt') → 3 (ignore b) Design
calculate('0', undefined, 'sqrt') → 0 Edge
calculate('2', '3', 'add') → 5 Regression
calculate('50', '8', 'percent') → 4 Regression

HTTP (test/server.test.js)

Request Expected Maps to
?a=81&op=sqrt → 200, result: 9 AC1
?a=2&op=sqrt → 200, result in (1.41421, 1.41422) AC2
?a=-4&op=sqrt → 400, { error: 'square root of a negative number' } AC3
?a=1&op=add → 400, error string AC4
?a=81&b=0&op=sqrt → 200, result: 9 b ignored
?a=2&b=3&op=add → 200, result: 5 Regression
?a=1&b=0&op=divide → 400 division by zero Regression

All existing server tests (health, index, 404, prior op errors) must still pass.

UI (test/ui.test.js)

Case Maps to
Served HTML includes data-key="√" AC5 (button)
Inline script references op=sqrt and unary fetch (no b in sqrt path) AC5 (wiring)
HTML maps negative sqrt error to Error display (same pattern as division by zero) AC5 (negative)
Existing REQUIRED_KEYS and binary percent mapping remain Regression

Full suite: npm test must pass before push.

Risks

Risk Mitigation
calculate still parses b for sqrt via shared path Branch on op before parseNumber(b) for unary ops only
Missing b accidentally allowed for add/subtract/etc. AC4 HTTP test; unit test add without b; keep binary list explicit
UI treats √ like binary op (needs =) Dedicated click branch; AC5 flow 81 → √ → 9 covered in manual QA; UI tests assert immediate sqrt
Wrong error message string Use exact phrase square root of a negative number; assert in unit + HTTP tests
Float bounds for AC2 Use strict inequalities on result in HTTP test, not exact decimal equality
Keypad layout overflow Add one button; follow issue #5 layout pattern without removing keys
Unicode √ in regex tests Escape in REQUIRED_KEYS loop like other special characters

Implementation order

  1. lib/calculator.js sqrt + unary/binary split + unit tests in test/calculator.test.js
  2. test/server.test.js for AC1–4 and ignored b on sqrt
  3. public/index.html √ button and immediate unary handler + test/ui.test.js
  4. Full npm test, then push aira/6-square-root

Attachment: plan-6-r1.md

**Aira · Plan (round 1) at `04cf219f`** Wrote docs/plans/issue-6.md (goal, AC1–5, unary sqrt design, files, test plan, risks), committed, and pushed aira/6-square-root. <details><summary>docs/plans/issue-6.md</summary> # Issue #6: Square root ## Goal Add square root as the first **unary** operation end-to-end: `op=sqrt` uses only operand `a` (`Math.sqrt(a)`), `b` is neither required nor validated when present, binary operations still require both operands, and the UI exposes a `√` button that applies to the current display immediately (no `=`). Example: `8`, `1`, `√` shows `9`. Negative input under sqrt shows `Error` on the display. ## Acceptance criteria 1. `GET /api/calculate?a=81&op=sqrt` returns HTTP 200 with body `{"result":9}`. 2. `GET /api/calculate?a=2&op=sqrt` returns HTTP 200 with a `result` between `1.41421` and `1.41422`. 3. `GET /api/calculate?a=-4&op=sqrt` returns HTTP 400 with body `{"error":"square root of a negative number"}`. 4. `GET /api/calculate?a=1&op=add` (missing `b`) still returns HTTP 400 with an `error` string in the JSON body. 5. The page at `/` has a working `√` button: entering `8`, `1`, then `√` shows `9`; a negative displayed value followed by `√` shows `Error`. ## Design ### Calculator module (`lib/calculator.js`) - Introduce a clear split between unary and binary operations inside `calculate(a, b, op)`: - **Unary** (`op === 'sqrt'`): parse only `a` with `parseNumber(a)`; do not read or validate `b` (extra query param is ignored). - **Binary** (add, subtract, multiply, divide, percent): parse both `a` and `b` as today so missing `b` still throws `operand is required` / related messages. - `sqrt` branch: - If `x < 0`, throw `new Error('square root of a negative number')` (exact message for AC3). - Otherwise `result = Math.sqrt(x)`; if not finite, throw `result out of range` (parity with other ops). - `sqrt(0)` and positive non-integers use normal `Math.sqrt` (AC2). - Unknown `op` unchanged. ### HTTP layer (`server.js`) - `handleCalculate` can remain structurally the same (pass `a`, `b`, `op` into `calculate`); unary-vs-binary operand rules live in `lib/calculator.js`. - Optional clarity: document in comments that `b` may be absent for `sqrt` only; no new routes or status-code mapping. - Existing `catch (err) → sendJson(400, { error: err.message })` covers negative sqrt and missing `b` on binary ops. ### UI (`public/index.html`) - Add a keypad button labeled `√` with `data-key="√"` (Unicode root symbol). - **Unary behavior** (distinct from binary operators): - On `√` click, take `currentOperand()` as `a`, `fetch('/api/calculate?a=' + encodeURIComponent(a) + '&op=sqrt')` (no `b`, no `=`). - On success: set display and `operand` to `String(body.result)`; clear `left` / `pendingOp` / `afterOp` so the user can continue from the result. - On 400: if `body.error === 'square root of a negative number'`, show `Error` (match division-by-zero UX); other errors may show the message or `Error` per existing patterns. - Binary operators (`+`, `−`, `×`, `÷`, `%`) and `=` behavior unchanged. - Keypad layout: place `√` without removing existing keys (e.g. operator column or row near `%` / `÷`), same button styling as other operators. ### API contract note - Task extends the contract: for `op=sqrt`, `b` is optional and ignored; for all other supported ops, both `a` and `b` remain required. AGENTS.md can be updated in implementation if Aira wants docs in sync (not required for AC). ### Test layout | File | Scope | |------|--------| | `test/calculator.test.js` | Unit tests for `sqrt`, negative reject, binary still needs `b`, regressions | | `test/server.test.js` | HTTP tests AC1–4, sqrt with ignored `b`, regressions | | `test/ui.test.js` | `√` button in HTML; script wires immediate `sqrt` API call and negative → `Error` | ## Files to change | File | Action | |------|--------| | `lib/calculator.js` | **Modify** — unary `sqrt`; binary ops unchanged regarding `b` | | `public/index.html` | **Modify** — `√` button; immediate unary handler | | `test/calculator.test.js` | **Modify** — sqrt unit cases + AC4 at module level + regressions | | `test/server.test.js` | **Modify** — sqrt API AC1–3; missing `b` on add (AC4); optional `b` ignored on sqrt | | `test/ui.test.js` | **Modify** — add `√` to required keys; assert `sqrt` op and error mapping | ## Test plan ### Unit (`test/calculator.test.js`) | Case | Maps to | |------|---------| | `calculate('81', undefined, 'sqrt')` → `9` | AC1 (module) | | `calculate('2', null, 'sqrt')` → ~√2 within bounds | AC2 (module) | | `calculate('-4', undefined, 'sqrt')` throws `square root of a negative number` | AC3 (module) | | `calculate('1', undefined, 'add')` throws (operand / required) | AC4 (module) | | `calculate('9', '999', 'sqrt')` → `3` (ignore `b`) | Design | | `calculate('0', undefined, 'sqrt')` → `0` | Edge | | `calculate('2', '3', 'add')` → `5` | Regression | | `calculate('50', '8', 'percent')` → `4` | Regression | ### HTTP (`test/server.test.js`) | Request | Expected | Maps to | |---------|----------|---------| | `?a=81&op=sqrt` → 200, `result: 9` | AC1 | | `?a=2&op=sqrt` → 200, `result` in (1.41421, 1.41422) | AC2 | | `?a=-4&op=sqrt` → 400, `{ error: 'square root of a negative number' }` | AC3 | | `?a=1&op=add` → 400, `error` string | AC4 | | `?a=81&b=0&op=sqrt` → 200, `result: 9` | `b` ignored | | `?a=2&b=3&op=add` → 200, `result: 5` | Regression | | `?a=1&b=0&op=divide` → 400 division by zero | Regression | All existing server tests (health, index, 404, prior op errors) must still pass. ### UI (`test/ui.test.js`) | Case | Maps to | |------|---------| | Served HTML includes `data-key="√"` | AC5 (button) | | Inline script references `op=sqrt` and unary fetch (no `b` in sqrt path) | AC5 (wiring) | | HTML maps negative sqrt error to `Error` display (same pattern as `division by zero`) | AC5 (negative) | | Existing `REQUIRED_KEYS` and binary `percent` mapping remain | Regression | Full suite: `npm test` must pass before push. ## Risks | Risk | Mitigation | |------|------------| | `calculate` still parses `b` for `sqrt` via shared path | Branch on `op` before `parseNumber(b)` for unary ops only | | Missing `b` accidentally allowed for add/subtract/etc. | AC4 HTTP test; unit test `add` without `b`; keep binary list explicit | | UI treats `√` like binary op (needs `=`) | Dedicated click branch; AC5 flow `81` → `√` → `9` covered in manual QA; UI tests assert immediate `sqrt` | | Wrong error message string | Use exact phrase `square root of a negative number`; assert in unit + HTTP tests | | Float bounds for AC2 | Use strict inequalities on `result` in HTTP test, not exact decimal equality | | Keypad layout overflow | Add one button; follow issue #5 layout pattern without removing keys | | Unicode `√` in regex tests | Escape in `REQUIRED_KEYS` loop like other special characters | ## Implementation order 1. `lib/calculator.js` sqrt + unary/binary split + unit tests in `test/calculator.test.js` 2. `test/server.test.js` for AC1–4 and ignored `b` on sqrt 3. `public/index.html` `√` button and immediate unary handler + `test/ui.test.js` 4. Full `npm test`, then push `aira/6-square-root` </details> Attachment: [plan-6-r1.md](https://aira-lab.cluster-dev.spkey.co/attachments/3ff8cfe4-fab0-4a52-ab71-26f3a50037eb)
Collaborator

Aira · plan review

Plan pushed at 04cf219f; independent Dodik plan review started.

**Aira · plan review** Plan pushed at `04cf219f`; independent Dodik plan review started.
Collaborator

Aira · dodik-plan PASS on 04cf219f

The issue #6 plan at 04cf219 maps every requirement to a numbered, testable acceptance criterion and matches the current calculator, server, and page. Unary sqrt is specified before parseNumber(b), binary ops still require both operands, negative sqrt uses the exact 400 error string, and the √ button applies to the current display without equals. Unit, HTTP, and page tests cover AC1–AC5, ignored b, sqrt(0), and binary regressions, with nothing material missing or out of scope.

Checks performed
  • Compared plan AC1–AC5 to the task requirements and the task's own acceptance criteria
  • Read lib/calculator.js, server.js, public/index.html, and test/calculator.test.js, test/server.test.js, and test/ui.test.js at 04cf219
  • Confirmed Math.sqrt(81) === 9 and Math.sqrt(2) is strictly inside 1.41421 and 1.41422
  • Confirmed calculate currently parses b first and missing b on add throws 'operand is required', which the unary branch and AC4 tests address
  • Confirmed the √ handler, error-to-Error mapping, and keypad placement fit the existing equals path, division-by-zero display, and 4-column grid
  • Confirmed the test plan covers module, HTTP, and page levels including negative sqrt, ignored b, and binary regressions without extra features

Attachment: dodik-plan-04cf219f.json

**Aira · dodik-plan PASS on `04cf219f`** The issue #6 plan at 04cf219 maps every requirement to a numbered, testable acceptance criterion and matches the current calculator, server, and page. Unary sqrt is specified before parseNumber(b), binary ops still require both operands, negative sqrt uses the exact 400 error string, and the √ button applies to the current display without equals. Unit, HTTP, and page tests cover AC1–AC5, ignored b, sqrt(0), and binary regressions, with nothing material missing or out of scope. <details><summary>Checks performed</summary> - Compared plan AC1–AC5 to the task requirements and the task's own acceptance criteria - Read lib/calculator.js, server.js, public/index.html, and test/calculator.test.js, test/server.test.js, and test/ui.test.js at 04cf219 - Confirmed Math.sqrt(81) === 9 and Math.sqrt(2) is strictly inside 1.41421 and 1.41422 - Confirmed calculate currently parses b first and missing b on add throws 'operand is required', which the unary branch and AC4 tests address - Confirmed the √ handler, error-to-Error mapping, and keypad placement fit the existing equals path, division-by-zero display, and 4-column grid - Confirmed the test plan covers module, HTTP, and page levels including negative sqrt, ignored b, and binary regressions without extra features </details> Attachment: [dodik-plan-04cf219f.json](https://aira-lab.cluster-dev.spkey.co/attachments/cd73433d-1cb7-4140-a059-7b9869df2c9d)
Collaborator

Aira · implementing

Plan approved by Dodik at 04cf219f. Implementation started.

**Aira · implementing** Plan approved by Dodik at `04cf219f`. Implementation started.
Collaborator

Aira · ci

Ready for review at f97ec43a (PR #14). Waiting for CI.

Implemented sqrt (calculator, UI √ button with immediate apply, tests); npm test 50/50 pass; pushed aira/6-square-root.

**Aira · ci** Ready for review at `f97ec43a` (PR #14). Waiting for CI. Implemented sqrt (calculator, UI √ button with immediate apply, tests); npm test 50/50 pass; pushed aira/6-square-root.
Collaborator

Aira · CI passed on f97ec43a

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

Aira · review

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

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

Aira · dodik PASS on f97ec43a

Square root is implemented as a unary operation end to end. The API returns 9 for a=81, a value strictly between 1.41421 and 1.41422 for a=2, and 400 with the exact negative-root error for a=-4. Missing b on add still returns 400, and an extra b on sqrt is ignored. The page has a √ button that calls op=sqrt immediately and shows Error for a negative value. npm test passed 50/50 with no skips, and the diff stays within the planned files.

Checks performed
  • Compared f97ec43 against origin/main and docs/plans/issue-6.md
  • AC1: GET /api/calculate?a=81&op=sqrt returns 200 {"result":9}, covered by test/server.test.js and test/calculator.test.js
  • AC2: a=2&op=sqrt returns 1.4142135623730951, asserted inside (1.41421, 1.41422)
  • AC3: a=-4&op=sqrt returns 400 {"error":"square root of a negative number"} in module and HTTP tests
  • AC4: a=1&op=add with no b still returns 400 with an error string; unit test asserts operand is required
  • AC5: public/index.html has data-key="√" and an immediate sqrt fetch with no b; negative-root error maps to Error; test/ui.test.js asserts the button, op, and error text
  • npm test: 50 passed, 0 failed, 0 skipped, 0 todo
  • No unrelated code changes, no weakened or skipped tests, no debug leftovers
  • Browser click-through was unavailable (missing preview libraries); the √ click path was verified from the page script plus the passing UI and API tests

Attachment: dodik-f97ec43a.json

**Aira · dodik PASS on `f97ec43a`** Square root is implemented as a unary operation end to end. The API returns 9 for a=81, a value strictly between 1.41421 and 1.41422 for a=2, and 400 with the exact negative-root error for a=-4. Missing b on add still returns 400, and an extra b on sqrt is ignored. The page has a √ button that calls op=sqrt immediately and shows Error for a negative value. npm test passed 50/50 with no skips, and the diff stays within the planned files. <details><summary>Checks performed</summary> - Compared f97ec43 against origin/main and docs/plans/issue-6.md - AC1: GET /api/calculate?a=81&op=sqrt returns 200 {"result":9}, covered by test/server.test.js and test/calculator.test.js - AC2: a=2&op=sqrt returns 1.4142135623730951, asserted inside (1.41421, 1.41422) - AC3: a=-4&op=sqrt returns 400 {"error":"square root of a negative number"} in module and HTTP tests - AC4: a=1&op=add with no b still returns 400 with an error string; unit test asserts operand is required - AC5: public/index.html has data-key="√" and an immediate sqrt fetch with no b; negative-root error maps to Error; test/ui.test.js asserts the button, op, and error text - npm test: 50 passed, 0 failed, 0 skipped, 0 todo - No unrelated code changes, no weakened or skipped tests, no debug leftovers - Browser click-through was unavailable (missing preview libraries); the √ click path was verified from the page script plus the passing UI and API tests </details> Attachment: [dodik-f97ec43a.json](https://aira-lab.cluster-dev.spkey.co/attachments/16275539-0fbf-4413-b569-0315f49624d6)
Collaborator

Aira · reviewer PASS on f97ec43a

The square-root feature correctly implements unary op=sqrt in lib/calculator.js (negative inputs rejected with the specified message, b skipped), exposes immediate √ handling in the UI consistent with existing fetch/error patterns, and adds HTTP/unit/UI tests that cover AC1–AC5 and binary regressions including missing b on add. Full npm test (50/50) passed at f97ec43; manual probes confirmed 400 responses for missing/empty a, ignored invalid b, and intact /health. No blocker or major correctness, security, or contract violations were found.

Checks performed
  • git diff origin/main...HEAD at f97ec43
  • npm test (50 passing)
  • Manual API probes for /health, sqrt missing/empty a, sqrt with invalid b
  • Review of lib/calculator.js, server.js, public/index.html against issue-6 plan

Attachment: reviewer-f97ec43a.json

**Aira · reviewer PASS on `f97ec43a`** The square-root feature correctly implements unary `op=sqrt` in `lib/calculator.js` (negative inputs rejected with the specified message, `b` skipped), exposes immediate √ handling in the UI consistent with existing fetch/error patterns, and adds HTTP/unit/UI tests that cover AC1–AC5 and binary regressions including missing `b` on add. Full `npm test` (50/50) passed at f97ec43; manual probes confirmed 400 responses for missing/empty `a`, ignored invalid `b`, and intact `/health`. No blocker or major correctness, security, or contract violations were found. <details><summary>Checks performed</summary> - git diff origin/main...HEAD at f97ec43 - npm test (50 passing) - Manual API probes for /health, sqrt missing/empty a, sqrt with invalid b - Review of lib/calculator.js, server.js, public/index.html against issue-6 plan </details> Attachment: [reviewer-f97ec43a.json](https://aira-lab.cluster-dev.spkey.co/attachments/cdcb86f2-f61b-4748-af06-051563fd9f85)
Collaborator

Aira · qa

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

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

Aira · qa PASS on f97ec43a

Commit f97ec43a55 serves a working square-root API and a √ button. GET /api/calculate?a=81&op=sqrt returns {"result":9}, sqrt(2) is 1.4142135623730951, a negative input returns 400 {"error":"square root of a negative number"}, and add without b still returns 400. The page button applies sqrt to the display immediately and shows Error for that negative case. Health reports the same sha, binary operations still require both operands, and npm test passed 50/50.

Checks performed
  • GET /health returned 200 {"ok":true,"sha":"f97ec43a55538ccb1e10cb43b5589211f3228650"}
  • GET / returned 200 text/html with a √ button (data-key="√") whose click handler fetches /api/calculate?a=&op=sqrt immediately and sets the display to Error when the error is "square root of a negative number"
  • GET /api/calculate?a=81&op=sqrt returned 200 {"result":9}
  • GET /api/calculate?a=2&op=sqrt returned 200 {"result":1.4142135623730951}
  • GET /api/calculate?a=-4&op=sqrt returned 400 {"error":"square root of a negative number"}
  • GET /api/calculate?a=-0.0001&op=sqrt returned 400 {"error":"square root of a negative number"}
  • GET /api/calculate?a=0&op=sqrt returned 200 {"result":0}
  • GET /api/calculate?a=-0&op=sqrt returned 200 {"result":0}
  • GET /api/calculate?a=1&op=sqrt returned 200 {"result":1}
  • GET /api/calculate?a=0.25&op=sqrt returned 200 {"result":0.5}
  • GET /api/calculate?a=81&b=99&op=sqrt returned 200 {"result":9}
  • GET /api/calculate?a=9&op=sqrt&b= returned 200 {"result":3}
  • GET /api/calculate?op=sqrt returned 400 {"error":"operand is required"}
  • GET /api/calculate?b=9&op=sqrt returned 400 {"error":"operand is required"}
  • GET /api/calculate?a=&op=sqrt returned 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=foo&op=sqrt returned 400 {"error":"operand must be a number"}
  • GET /api/calculate?a=1&op=add returned 400 {"error":"operand is required"}
  • GET /api/calculate?b=2&op=add returned 400 {"error":"operand is required"}
  • GET /api/calculate?a=1&b=2&op=add returned 200 {"result":3}
  • GET /api/calculate?a=5&b=3&op=subtract returned 200 {"result":2}
  • GET /api/calculate?a=5&op=subtract returned 400 {"error":"operand is required"}
  • GET /api/calculate?a=4&b=3&op=multiply returned 200 {"result":12}
  • GET /api/calculate?a=4&op=multiply returned 400 {"error":"operand is required"}
  • GET /api/calculate?a=8&b=2&op=divide returned 200 {"result":4}
  • GET /api/calculate?a=8&op=divide returned 400 {"error":"operand is required"}
  • GET /api/calculate?a=1&b=0&op=divide returned 400 {"error":"division by zero"}
  • GET /api/calculate?a=50&b=200&op=percent returned 200 {"result":100}
  • GET /api/calculate?a=1&b=2&op=pow returned 400 {"error":"unknown operation"}
  • npm test (node --test) on HEAD f97ec43a55: 50 passed, 0 failed, including calculate sqrt module tests, API sqrt tests, and the index page sqrt wiring test

Attachment: qa-f97ec43a.json

**Aira · qa PASS on `f97ec43a`** Commit f97ec43a55538ccb1e10cb43b5589211f3228650 serves a working square-root API and a √ button. GET /api/calculate?a=81&op=sqrt returns {"result":9}, sqrt(2) is 1.4142135623730951, a negative input returns 400 {"error":"square root of a negative number"}, and add without b still returns 400. The page button applies sqrt to the display immediately and shows Error for that negative case. Health reports the same sha, binary operations still require both operands, and npm test passed 50/50. <details><summary>Checks performed</summary> - GET /health returned 200 {"ok":true,"sha":"f97ec43a55538ccb1e10cb43b5589211f3228650"} - GET / returned 200 text/html with a √ button (data-key="√") whose click handler fetches /api/calculate?a=<display>&op=sqrt immediately and sets the display to Error when the error is "square root of a negative number" - GET /api/calculate?a=81&op=sqrt returned 200 {"result":9} - GET /api/calculate?a=2&op=sqrt returned 200 {"result":1.4142135623730951} - GET /api/calculate?a=-4&op=sqrt returned 400 {"error":"square root of a negative number"} - GET /api/calculate?a=-0.0001&op=sqrt returned 400 {"error":"square root of a negative number"} - GET /api/calculate?a=0&op=sqrt returned 200 {"result":0} - GET /api/calculate?a=-0&op=sqrt returned 200 {"result":0} - GET /api/calculate?a=1&op=sqrt returned 200 {"result":1} - GET /api/calculate?a=0.25&op=sqrt returned 200 {"result":0.5} - GET /api/calculate?a=81&b=99&op=sqrt returned 200 {"result":9} - GET /api/calculate?a=9&op=sqrt&b= returned 200 {"result":3} - GET /api/calculate?op=sqrt returned 400 {"error":"operand is required"} - GET /api/calculate?b=9&op=sqrt returned 400 {"error":"operand is required"} - GET /api/calculate?a=&op=sqrt returned 400 {"error":"operand must be a number"} - GET /api/calculate?a=foo&op=sqrt returned 400 {"error":"operand must be a number"} - GET /api/calculate?a=1&op=add returned 400 {"error":"operand is required"} - GET /api/calculate?b=2&op=add returned 400 {"error":"operand is required"} - GET /api/calculate?a=1&b=2&op=add returned 200 {"result":3} - GET /api/calculate?a=5&b=3&op=subtract returned 200 {"result":2} - GET /api/calculate?a=5&op=subtract returned 400 {"error":"operand is required"} - GET /api/calculate?a=4&b=3&op=multiply returned 200 {"result":12} - GET /api/calculate?a=4&op=multiply returned 400 {"error":"operand is required"} - GET /api/calculate?a=8&b=2&op=divide returned 200 {"result":4} - GET /api/calculate?a=8&op=divide returned 400 {"error":"operand is required"} - GET /api/calculate?a=1&b=0&op=divide returned 400 {"error":"division by zero"} - GET /api/calculate?a=50&b=200&op=percent returned 200 {"result":100} - GET /api/calculate?a=1&b=2&op=pow returned 400 {"error":"unknown operation"} - npm test (node --test) on HEAD f97ec43a55538ccb1e10cb43b5589211f3228650: 50 passed, 0 failed, including calculate sqrt module tests, API sqrt tests, and the index page sqrt wiring test </details> Attachment: [qa-f97ec43a.json](https://aira-lab.cluster-dev.spkey.co/attachments/a4feff68-a339-44b0-9505-b17bb58c7f40)
Collaborator

Aira · merging

QA passed on f97ec43a. Merging.

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

Aira · Merged PR #14

Merge commit 0b92e5df1ea7331816904ccaf6585a291aadf37e from reviewed head f97ec43a55538ccb1e10cb43b5589211f3228650.

Gate Verdict Summary
ci pass ci / test (pull_request)
dodik pass Square root is implemented as a unary operation end to end. The API returns 9 for a=81, a value strictly between 1.41421 and 1.41422 for a=2, and 400 with the e
reviewer pass The square-root feature correctly implements unary op=sqrt in lib/calculator.js (negative inputs rejected with the specified message, b skipped), exposes
qa pass Commit f97ec43a55 serves a working square-root API and a √ button. GET /api/calculate?a=81&op=sqrt returns {"result":9}, sqrt(2) i
**Aira · Merged PR #14** Merge commit `0b92e5df1ea7331816904ccaf6585a291aadf37e` from reviewed head `f97ec43a55538ccb1e10cb43b5589211f3228650`. | Gate | Verdict | Summary | |---|---|---| | ci | pass | ci / test (pull_request) | | dodik | pass | Square root is implemented as a unary operation end to end. The API returns 9 for a=81, a value strictly between 1.41421 and 1.41422 for a=2, and 400 with the e | | reviewer | pass | The square-root feature correctly implements unary `op=sqrt` in `lib/calculator.js` (negative inputs rejected with the specified message, `b` skipped), exposes | | qa | pass | Commit f97ec43a55538ccb1e10cb43b5589211f3228650 serves a working square-root API and a √ button. GET /api/calculate?a=81&op=sqrt returns {"result":9}, sqrt(2) i |
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-3#6
No description provided.