munich-quantum-toolkit / munich-quantum-toolkit/debugger

✅ Add unit-level tests for `parseClassicConditionExpression`

Open
#469 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
21
Forks
7
Avg merge
9h 28m
Merged PRs (30d)
42

Description

🤖 AI text below 🤖

Problem statement

parseClassicConditionExpression (in src/common/parsing/CodePreprocessing.cpp) has no direct unit tests. Every test that exercises it today lives in test/test_custom_code.cpp and runs the full end-to-end pipeline: load QASM code, spin up a DDSimulationState, run the simulation, and inspect amplitudes or classical bits.

Two problems with that coverage:

  • A parser bug shows up as a failed amplitude assertion, not as "the parser returned the wrong ClassicCondition". Localizing the root cause takes longer than it should.
  • Edge cases of the parser itself (malformed input, whitespace, leading paren, trailing garbage, invalid brackets, empty operand) are not systematically covered because writing a full QASM program to trigger each one is disproportionate.

Surfaced during the review of PR #463 while considering the follow-ups for parseClassicConditionExpression.

Proposed solution

Add a fixture (either in the existing test_parsing.cpp or in a new file) that calls parseClassicConditionExpression directly with a string and checks the returned std::optional<ClassicCondition> against expected values. Cover:

  • Valid cases: one test per comparator (==, !=, <, <=, >, >=), bracketed forms (c[0] == 1), bare register (c), bare bit (c[0]), input with leading (, input with surrounding whitespace.
  • Invalid cases: empty string, missing operand on either side, non-numeric right-hand side, malformed brackets (open only, close only, index empty, non-digit index, bracket not at the end), out-of-range integer literal.
  • Document currently permissive behavior (e.g. c2] accepted as a register name, @# accepted). These tests can start green against the current behavior and flip to expect std::nullopt once #468 lands.
Out of scope
  • Unit tests for other parsers in the file (parseFunctionDefinition, parseClassicControlledGate, etc.). Same idea, separate issue.
  • Testing parseBitRegisterRef directly. It lives in the anonymous namespace of the .cpp; the tests here cover it indirectly through parseClassicConditionExpression, which is what the outside world sees.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with parseClassicConditionExpression in src/common/parsing/CodePreprocessing.cpp and review the existing coverage in test/test_custom_code.cpp. Add a fixture in test_parsing.cpp or a new test file that checks the returned std::optional for the listed valid, invalid, and permissive cases. Done means the parser is tested directly across all specified inputs, including behavior that may change with issue #468.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.