def test_basic_qubit_hash(): fake_engine = "Fake" a = _qubit.BasicQubit(fake_engine, 1) b = _qubit.BasicQubit(fake_engine, 1) c = _qubit.WeakQubitRef(fake_engine, 1) assert a == b and hash(a) == hash(b) assert a == c and hash(a) == hash(c) # For performance reasons, low ids should not collide. assert len({hash(_qubit.BasicQubit(fake_engine, e)) for e in range(100)}) == 100 # Important that weakref.WeakSet in projectq.cengines._main.py works. # When id is -1, expect reference equality. x = _qubit.BasicQubit(fake_engine, -1) y = _qubit.BasicQubit(fake_engine, -1) # Note hash(x) == hash(y) isn't technically a failure, but it's surprising. assert x != y and hash(x) != hash(y)
def test_weak_qubit_ref(): # Test that there is no deallocate gate qubit = _qubit.WeakQubitRef("Engine without deallocate_qubit()", 0) with pytest.raises(AttributeError): qubit.__del__()