Brackets Function #25

Open
opened 2025-09-20 13:11:48 +01:00 by Vylpes · 5 comments
Owner

Epic: #21
Story Points: 5


AS a user, I want expressions with brackets to be evaluated correctly
SO THAT I can control the order of operations in multi-operation expressions

Acceptance Criteria

GIVEN #22 (multiple operations in one expression) is complete
WHEN I evaluate an expression containing brackets in CLI interactive mode
THEN bracketed sub-expressions are solved before the surrounding operations

GIVEN #22 is complete
WHEN I evaluate (2 + 3) * 4
THEN the result is 20

GIVEN #22 is complete
WHEN I evaluate 2 + (3 * 4)
THEN the result is 14

GIVEN #22 is complete
WHEN I evaluate a nested bracketed expression such as ((2 + 3) * 2) - 1
THEN each inner bracketed group is solved before outer operations and the result is 9

GIVEN #22 is complete
WHEN I evaluate an expression with optional spaces such as ( 2 + 3 ) * 4
THEN spaces are ignored and the result matches (2 + 3) * 4

GIVEN #22 is complete
WHEN I evaluate an expression with unclosed or unmatched brackets such as (2 + 3 or 2 + 3) or ((2 + 3)
THEN a clear error message is shown and no result is produced

GIVEN #22 is complete
WHEN I run calculator cli "(2 + 3) * 4" (single-expression mode)
THEN 20 is printed to stdout

GIVEN I am in GUI mode
WHEN I evaluate an expression containing brackets
THEN bracketed sub-expressions are solved before the surrounding operations, consistent with CLI behaviour

Subtasks

  • Extend expression parser to support round brackets ( )
  • Evaluate nested bracketed sub-expressions before outer operations
  • Return a clear error for unclosed or unmatched brackets
  • Add unit tests for bracket evaluation and error cases
  • Enable bracketed expression evaluation in GUI (may require expression-entry support)

Notes

  • Depends on #22 (multiple operations in one expression)
  • Round brackets only; square brackets are out of scope
  • Operator precedence outside brackets follows #22 (left-to-right unless overridden by a future BIDMAS story)
Epic: #21 Story Points: 5 --- AS a user, I want expressions with brackets to be evaluated correctly SO THAT I can control the order of operations in multi-operation expressions ## Acceptance Criteria GIVEN #22 (multiple operations in one expression) is complete WHEN I evaluate an expression containing brackets in CLI interactive mode THEN bracketed sub-expressions are solved before the surrounding operations GIVEN #22 is complete WHEN I evaluate `(2 + 3) * 4` THEN the result is `20` GIVEN #22 is complete WHEN I evaluate `2 + (3 * 4)` THEN the result is `14` GIVEN #22 is complete WHEN I evaluate a nested bracketed expression such as `((2 + 3) * 2) - 1` THEN each inner bracketed group is solved before outer operations and the result is `9` GIVEN #22 is complete WHEN I evaluate an expression with optional spaces such as `( 2 + 3 ) * 4` THEN spaces are ignored and the result matches `(2 + 3) * 4` GIVEN #22 is complete WHEN I evaluate an expression with unclosed or unmatched brackets such as `(2 + 3` or `2 + 3)` or `((2 + 3)` THEN a clear error message is shown and no result is produced GIVEN #22 is complete WHEN I run `calculator cli "(2 + 3) * 4"` (single-expression mode) THEN `20` is printed to stdout GIVEN I am in GUI mode WHEN I evaluate an expression containing brackets THEN bracketed sub-expressions are solved before the surrounding operations, consistent with CLI behaviour ## Subtasks - [ ] Extend expression parser to support round brackets `(` `)` - [ ] Evaluate nested bracketed sub-expressions before outer operations - [ ] Return a clear error for unclosed or unmatched brackets - [ ] Add unit tests for bracket evaluation and error cases - [ ] Enable bracketed expression evaluation in GUI (may require expression-entry support) ## Notes - Depends on #22 (multiple operations in one expression) - Round brackets only; square brackets are out of scope - Operator precedence outside brackets follows #22 (left-to-right unless overridden by a future BIDMAS story)
Vylpes added this to the 0.2.0 milestone 2025-09-20 13:11:48 +01:00
Author
Owner

Blocked by #22

Blocked by #22
Author
Owner

@Smithy-bot This should have GUI controls also

@Smithy-bot This should have GUI controls also
Member

Planning: criteria → estimate

Acceptance criteria on the issue body look complete (including GUI parity from your comment). needs/criteria is done; moving to needs/estimate for story points.

Note: Still blocked on #22 for implementation — that does not block sizing once #22 is assumed complete.

### Planning: criteria → estimate Acceptance criteria on the issue body look complete (including GUI parity from your comment). **needs/criteria** is done; moving to **needs/estimate** for story points. **Note:** Still **blocked** on #22 for implementation — that does not block sizing once #22 is assumed complete.
Member

Story point estimate (needs/estimate)

Estimate: 5

Acceptance criteria are clear (CLI + single-expression + GUI parity, nesting, spacing, bracket errors). Implementation assumes #22 is done; the existing blocked label reflects delivery order, not sizing uncertainty.

Slice Points Notes
Parser / evaluator: ( ) groups, nested evaluation before outer ops 2 Builds on #22 multi-op engine
Bracket validation + clear errors (unclosed / unmatched) 1 Covered explicitly in AC
Unit tests (happy path, nesting, spaces, error cases) 1 Listed subtask
GUI parity with CLI bracket behaviour 1 May reuse existing expression entry; no new UX design in AC

Comparable to #22 (5 points) and other calculator 5-point engine stories (#30, #31). Square brackets remain out of scope per notes.


Advancing needs/estimate → needs/tests. Story Points set to 5 on the issue body.

## Story point estimate (needs/estimate) **Estimate: 5** Acceptance criteria are clear (CLI + single-expression + GUI parity, nesting, spacing, bracket errors). Implementation assumes #22 is done; the existing **blocked** label reflects delivery order, not sizing uncertainty. | Slice | Points | Notes | |-------|--------|-------| | Parser / evaluator: `(` `)` groups, nested evaluation before outer ops | 2 | Builds on #22 multi-op engine | | Bracket validation + clear errors (unclosed / unmatched) | 1 | Covered explicitly in AC | | Unit tests (happy path, nesting, spaces, error cases) | 1 | Listed subtask | | GUI parity with CLI bracket behaviour | 1 | May reuse existing expression entry; no new UX design in AC | Comparable to #22 (**5** points) and other calculator **5**-point engine stories (#30, #31). Square brackets remain out of scope per notes. --- Advancing **needs/estimate → needs/tests**. Story Points set to **5** on the issue body.
Member

QA test scripts (needs/tests)

Precondition: #22 (multiple operations in one expression) is merged and available in the build under test. This story remains blocked for implementation until then; run these scripts after the brackets feature ships.

Scope: Round brackets ( ) only. Operator precedence outside brackets follows #22 (left-to-right). Square brackets are out of scope.


CLI — interactive mode

ID Steps Expected result
QA-25-01 Start interactive CLI. Enter (2 + 3) * 4 and submit. Result 20; inner (2 + 3) evaluated before * 4.
QA-25-02 Enter 2 + (3 * 4) and submit. Result 14; inner (3 * 4) evaluated before + 2.
QA-25-03 Enter ((2 + 3) * 2) - 1 and submit. Result 9; nested groups evaluated inside-out.
QA-25-04 Enter ( 2 + 3 ) * 4 (extra spaces) and submit. Result 20; same as (2 + 3) * 4.
QA-25-05 Enter (2 + 3 (unclosed) and submit. Clear error message; no numeric result.
QA-25-06 Enter 2 + 3) (unmatched close) and submit. Clear error message; no numeric result.
QA-25-07 Enter ((2 + 3) (extra open) and submit. Clear error message; no numeric result.

CLI — single-expression mode

ID Steps Expected result
QA-25-08 Run calculator cli "(2 + 3) * 4". 20 printed to stdout (exit success).
QA-25-09 Run calculator cli "((2 + 3) * 2) - 1". 9 on stdout.
QA-25-10 Run calculator cli "(2 + 3". Non-zero exit or stderr error; no result line.

GUI mode

ID Steps Expected result
QA-25-11 Open GUI. Evaluate (2 + 3) * 4 using the same expression entry as other multi-op expressions. Display 20; bracket grouping matches CLI.
QA-25-12 Evaluate 2 + (3 * 4) in GUI. Display 14.
QA-25-13 Evaluate ((2 + 3) * 2) - 1 in GUI. Display 9.
QA-25-14 Enter (2 + 3 in GUI and attempt evaluate. User-visible error; no misleading result.

Regression / parity

ID Steps Expected result
QA-25-15 CLI vs GUI: same inputs (2 + 3) * 4, 2 + (3 * 4), ( 2 + 3 ) * 4. Identical numeric results in both modes.
QA-25-16 Expression without brackets (e.g. 2 + 3 * 4) still behaves per #22. No regression in non-bracket evaluation.

Sign-off checklist

  • All QA-25-01 … QA-25-16 pass on target build
  • Automated unit tests cover bracket happy path, nesting, spaces, and error cases (per subtasks)
  • Error copy is understandable without reading source

Advancing needs/tests → needs/approval for human sign-off before implementation work begins (delivery still ordered behind #22).

## QA test scripts (needs/tests) **Precondition:** #22 (multiple operations in one expression) is merged and available in the build under test. This story remains **blocked** for implementation until then; run these scripts after the brackets feature ships. **Scope:** Round brackets `(` `)` only. Operator precedence outside brackets follows #22 (left-to-right). Square brackets are out of scope. --- ### CLI — interactive mode | ID | Steps | Expected result | |----|--------|-----------------| | QA-25-01 | Start interactive CLI. Enter `(2 + 3) * 4` and submit. | Result **20**; inner `(2 + 3)` evaluated before `* 4`. | | QA-25-02 | Enter `2 + (3 * 4)` and submit. | Result **14**; inner `(3 * 4)` evaluated before `+ 2`. | | QA-25-03 | Enter `((2 + 3) * 2) - 1` and submit. | Result **9**; nested groups evaluated inside-out. | | QA-25-04 | Enter `( 2 + 3 ) * 4` (extra spaces) and submit. | Result **20**; same as `(2 + 3) * 4`. | | QA-25-05 | Enter `(2 + 3` (unclosed) and submit. | Clear error message; **no** numeric result. | | QA-25-06 | Enter `2 + 3)` (unmatched close) and submit. | Clear error message; **no** numeric result. | | QA-25-07 | Enter `((2 + 3)` (extra open) and submit. | Clear error message; **no** numeric result. | ### CLI — single-expression mode | ID | Steps | Expected result | |----|--------|-----------------| | QA-25-08 | Run `calculator cli "(2 + 3) * 4"`. | **20** printed to stdout (exit success). | | QA-25-09 | Run `calculator cli "((2 + 3) * 2) - 1"`. | **9** on stdout. | | QA-25-10 | Run `calculator cli "(2 + 3"`. | Non-zero exit or stderr error; **no** result line. | ### GUI mode | ID | Steps | Expected result | |----|--------|-----------------| | QA-25-11 | Open GUI. Evaluate `(2 + 3) * 4` using the same expression entry as other multi-op expressions. | Display **20**; bracket grouping matches CLI. | | QA-25-12 | Evaluate `2 + (3 * 4)` in GUI. | Display **14**. | | QA-25-13 | Evaluate `((2 + 3) * 2) - 1` in GUI. | Display **9**. | | QA-25-14 | Enter `(2 + 3` in GUI and attempt evaluate. | User-visible error; no misleading result. | ### Regression / parity | ID | Steps | Expected result | |----|--------|-----------------| | QA-25-15 | CLI vs GUI: same inputs `(2 + 3) * 4`, `2 + (3 * 4)`, `( 2 + 3 ) * 4`. | Identical numeric results in both modes. | | QA-25-16 | Expression without brackets (e.g. `2 + 3 * 4`) still behaves per #22. | No regression in non-bracket evaluation. | --- ### Sign-off checklist - [ ] All QA-25-01 … QA-25-16 pass on target build - [ ] Automated unit tests cover bracket happy path, nesting, spaces, and error cases (per subtasks) - [ ] Error copy is understandable without reading source --- Advancing **needs/tests → needs/approval** for human sign-off before implementation work begins (delivery still ordered behind #22).
Smithy-bot removed their assignment 2026-10-02 12:05:47 +01:00
Vylpes removed their assignment 2026-10-02 17:28:05 +01:00
Sign in to join this conversation.
No description provided.