Exemple #1
0
def test_basic_qubit_hash():
	fake_engine = "Fake"
	qubit0 = _qubit.BasicQubit(fake_engine, 0)
	qubit1 = _qubit.BasicQubit(fake_engine, 1)
	assert hash(qubit0) != hash(qubit1)
	qubit0.id = -1
	qubit1.id = -1
	# Important that weakref.WeakSet in projectq.cengines._main.py works.
	assert hash(qubit0) != hash(qubit1)
Exemple #2
0
def test_basic_qubit_comparison(id0, id1, expected):
    fake_engine = "Fake"
    fake_engine2 = "Fake2"
    qubit0 = _qubit.BasicQubit(fake_engine, id0)
    qubit1 = _qubit.BasicQubit(fake_engine, id1)
    qubit2 = _qubit.BasicQubit(fake_engine2, id0)
    # Different engines
    assert not (qubit2 == qubit0)
    assert not (qubit2 == qubit1)
    assert qubit2 != qubit0
    assert qubit2 != qubit1
    # Same engines
    assert (qubit0 == qubit1) == expected
Exemple #3
0
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)
Exemple #4
0
def test_basic_qubit_str(qubit_id):
    fake_engine = "Fake"
    qubit = _qubit.BasicQubit(fake_engine, qubit_id)
    assert str(qubit) == str(qubit_id)