Support multiple operations in one expression #22

Open
opened 2025-09-20 13:09:52 +01:00 by Vylpes · 3 comments
Owner

Epic: #21
Estimate: 5


I want there the ability to support multiple operations in one expression, such as 5 + 2 * 6

Acceptance Criteria

GIVEN I am a user
WHEN I type in an expression with more than one operation
THEN the program will calculate this together

Subtasks

  • Add support for multiple operations
  • Hook into error handler for invalid expressions (5 + 2 *, 5 + * 6, 5 / 0 * 6, etc.)
  • Update tests

Notes

  • Left to right for now to keep the logic simpler
Epic: #21 Estimate: 5 --- I want there the ability to support multiple operations in one expression, such as `5 + 2 * 6` ## Acceptance Criteria GIVEN I am a user WHEN I type in an expression with more than one operation THEN the program will calculate this together ## Subtasks - [ ] Add support for multiple operations - [ ] Hook into error handler for invalid expressions (`5 + 2 *`, `5 + * 6`, `5 / 0 * 6`, etc.) - [ ] Update tests ## Notes - Left to right for now to keep the logic simpler
Vylpes added this to the 0.1.0 milestone 2025-09-20 13:09:52 +01:00
Author
Owner

Do we follow BIDMAS?

Do we follow BIDMAS?
Author
Owner

@Vylpes wrote in #22 (comment):

Do we follow BIDMAS?

Not for this, as it'll be easier not to, but perhaps at some point

@Vylpes wrote in https://git.vylpes.xyz/RabbitLabs/calculator/issues/22#issuecomment-18424: > Do we follow BIDMAS? Not for this, as it'll be easier not to, but perhaps at some point
Member

QA Testing Scripts

Story: Support multiple operations in one expression
Estimate: 5 story points
Evaluation rule: Left-to-right (no BIDMAS/precedence in this story — see Notes and #22 (comment))

TC-01 — Two-operation expression (CLI single-expression mode)

  • Given the calculator CLI is available
  • When I run calculator cli "10 - 3"
  • Then 7 is printed to stdout
  • And the process exits with code 0

TC-02 — Three-operation expression, left-to-right (CLI single-expression)

  • Given the calculator CLI is available
  • When I run calculator cli "5 + 2 * 6"
  • Then 42 is printed to stdout (evaluated as (5 + 2) * 6, not BIDMAS 17)

TC-03 — Four-operation chain, left-to-right (CLI single-expression)

  • Given the calculator CLI is available
  • When I run calculator cli "8 / 2 + 3"
  • Then 7 is printed to stdout (evaluated as (8 / 2) + 3)

TC-04 — Subtraction and division chain (CLI single-expression)

  • Given the calculator CLI is available
  • When I run calculator cli "20 - 10 / 2"
  • Then 5 is printed to stdout (evaluated as (20 - 10) / 2)

TC-05 — Optional whitespace tolerated (CLI single-expression)

  • Given the calculator CLI is available
  • When I run calculator cli " 5 + 2 * 6 "
  • Then 42 is printed to stdout

TC-06 — Multi-operation expression (CLI interactive mode)

  • Given I run calculator cli and enter interactive mode
  • When I type 5 + 2 * 6 and press Enter
  • Then 42 is printed
  • And I can enter another expression without restarting

TC-07 — Multi-operation expression (GUI mode)

  • Given the calculator GUI is open
  • When I enter 5 + 2 * 6 via buttons or keyboard
  • Then the output displays 42

TC-08 — Invalid expression: trailing operator

  • Given the calculator CLI is available
  • When I run calculator cli "5 + 2 *"
  • Then a clear error message is shown
  • And no numeric result is produced

TC-09 — Invalid expression: missing operand between operators

  • Given the calculator CLI is available
  • When I run calculator cli "5 + * 6"
  • Then a clear error message is shown
  • And no numeric result is produced

TC-10 — Invalid expression: division by zero in a chain

  • Given the calculator CLI is available
  • When I run calculator cli "5 / 0 * 6"
  • Then a clear error message is shown
  • And no numeric result is produced

TC-11 — Invalid expression surfaced in CLI interactive mode

  • Given I am in CLI interactive mode
  • When I type 5 + 2 * and press Enter
  • Then a clear error message is shown
  • And I can enter another expression without the session crashing

TC-12 — Invalid expression surfaced in GUI mode

  • Given the calculator GUI is open
  • When I enter an invalid multi-operation expression such as 5 + * 6
  • Then an error is displayed on the output (consistent with existing GUI error behaviour)

TC-13 — Automated unit tests cover multi-operation evaluation

  • Given the project test suite
  • When I run the unit tests
  • Then tests pass for valid multi-operation expressions (including left-to-right examples above)
  • And tests pass for invalid multi-operation expressions (5 + 2 *, 5 + * 6, 5 / 0 * 6, etc.)

TC-14 — Single-operation expressions remain unaffected (regression)

  • Given the calculator CLI is available
  • When I run calculator cli "5 + 2"
  • Then 7 is printed to stdout
  • And existing single-operation behaviour is unchanged
## QA Testing Scripts **Story:** Support multiple operations in one expression **Estimate:** 5 story points **Evaluation rule:** Left-to-right (no BIDMAS/precedence in this story — see Notes and https://git.vylpes.xyz/RabbitLabs/calculator/issues/22#issuecomment-18503) ### TC-01 — Two-operation expression (CLI single-expression mode) - **Given** the calculator CLI is available - **When** I run `calculator cli "10 - 3"` - **Then** `7` is printed to stdout - **And** the process exits with code 0 ### TC-02 — Three-operation expression, left-to-right (CLI single-expression) - **Given** the calculator CLI is available - **When** I run `calculator cli "5 + 2 * 6"` - **Then** `42` is printed to stdout (evaluated as `(5 + 2) * 6`, not BIDMAS `17`) ### TC-03 — Four-operation chain, left-to-right (CLI single-expression) - **Given** the calculator CLI is available - **When** I run `calculator cli "8 / 2 + 3"` - **Then** `7` is printed to stdout (evaluated as `(8 / 2) + 3`) ### TC-04 — Subtraction and division chain (CLI single-expression) - **Given** the calculator CLI is available - **When** I run `calculator cli "20 - 10 / 2"` - **Then** `5` is printed to stdout (evaluated as `(20 - 10) / 2`) ### TC-05 — Optional whitespace tolerated (CLI single-expression) - **Given** the calculator CLI is available - **When** I run `calculator cli " 5 + 2 * 6 "` - **Then** `42` is printed to stdout ### TC-06 — Multi-operation expression (CLI interactive mode) - **Given** I run `calculator cli` and enter interactive mode - **When** I type `5 + 2 * 6` and press Enter - **Then** `42` is printed - **And** I can enter another expression without restarting ### TC-07 — Multi-operation expression (GUI mode) - **Given** the calculator GUI is open - **When** I enter `5 + 2 * 6` via buttons or keyboard - **Then** the output displays `42` ### TC-08 — Invalid expression: trailing operator - **Given** the calculator CLI is available - **When** I run `calculator cli "5 + 2 *"` - **Then** a clear error message is shown - **And** no numeric result is produced ### TC-09 — Invalid expression: missing operand between operators - **Given** the calculator CLI is available - **When** I run `calculator cli "5 + * 6"` - **Then** a clear error message is shown - **And** no numeric result is produced ### TC-10 — Invalid expression: division by zero in a chain - **Given** the calculator CLI is available - **When** I run `calculator cli "5 / 0 * 6"` - **Then** a clear error message is shown - **And** no numeric result is produced ### TC-11 — Invalid expression surfaced in CLI interactive mode - **Given** I am in CLI interactive mode - **When** I type `5 + 2 *` and press Enter - **Then** a clear error message is shown - **And** I can enter another expression without the session crashing ### TC-12 — Invalid expression surfaced in GUI mode - **Given** the calculator GUI is open - **When** I enter an invalid multi-operation expression such as `5 + * 6` - **Then** an error is displayed on the output (consistent with existing GUI error behaviour) ### TC-13 — Automated unit tests cover multi-operation evaluation - **Given** the project test suite - **When** I run the unit tests - **Then** tests pass for valid multi-operation expressions (including left-to-right examples above) - **And** tests pass for invalid multi-operation expressions (`5 + 2 *`, `5 + * 6`, `5 / 0 * 6`, etc.) ### TC-14 — Single-operation expressions remain unaffected (regression) - **Given** the calculator CLI is available - **When** I run `calculator cli "5 + 2"` - **Then** `7` is printed to stdout - **And** existing single-operation behaviour is unchanged
Smithy-bot removed their assignment 2026-09-10 12:06:59 +01:00
Vylpes removed their assignment 2026-09-10 13:14:38 +01:00
Vylpes added this to the 0.1 Sprint 2 project 2026-09-23 18:41:24 +01:00
Sign in to join this conversation.
No description provided.