Skip to content

Commit

Permalink
Add test for non-string tag for TaggedOperation circuit diagrams (#2800)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstrain115 committed Mar 3, 2020
1 parent cc457d3 commit 5da8f0f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cirq/ops/raw_types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,17 @@ def test_tagged_operation():


def test_circuit_diagram():

class TaggyTag:
"""Tag with a custom repr function to test circuit diagrams."""

def __repr__(self):
return 'TaggyTag()'

h = cirq.H(cirq.GridQubit(1, 1))
tagged_h = h.with_tags('tag1')
non_string_tag_h = h.with_tags(TaggyTag())

expected = cirq.CircuitDiagramInfo(wire_symbols=("H['tag1']",),
exponent=1.0,
connected=True,
Expand All @@ -479,6 +488,11 @@ def test_circuit_diagram():
assert c.to_text_diagram() == diagram_with_tags
assert c.to_text_diagram(include_tags=False) == diagram_without_tags

c = cirq.Circuit(non_string_tag_h)
diagram_with_non_string_tag = "(1, 1): ───H[TaggyTag()]───"
assert c.to_text_diagram() == diagram_with_non_string_tag
assert c.to_text_diagram(include_tags=False) == diagram_without_tags


def test_circuit_diagram_tagged_global_phase():
# Tests global phase operation
Expand Down

0 comments on commit 5da8f0f

Please sign in to comment.