diff --git a/unittests/nvqpp/integration/draw_tester.cpp b/unittests/nvqpp/integration/draw_tester.cpp index 5d51c60a052..e4fab5609cd 100644 --- a/unittests/nvqpp/integration/draw_tester.cpp +++ b/unittests/nvqpp/integration/draw_tester.cpp @@ -132,3 +132,25 @@ CUDAQ_TEST(LatexDrawTester, skipsNonGateInstructions) { EXPECT_EQ(expected_str, cudaq::detail::getLaTeXString(trace)); } + +CUDAQ_TEST(DrawTester, skipsNonGateInstructions) { + // Regression test: a measurement in the middle of the trace must not + // misalign the instruction indices used by the layers and the boxes. + cudaq::Trace trace; + trace.appendInstruction("h", {}, {}, {{2, 2}}); + trace.appendMeasurement("mz", {{2, 2}}); + trace.appendInstruction("x", {}, {}, {{2, 2}}); + + // clang-format off + const std::string expected_str = R"( +q0 : ────────── + +q1 : ────────── + ╭───╮╭───╮ +q2 : ┤ h ├┤ x ├ + ╰───╯╰───╯ +)"; + // clang-format on + + EXPECT_EQ(expected_str, cudaq::detail::draw(trace)); +}