Пример #1
0
def test_basic_gate_compare():
    gate1 = _basics.BasicGate()
    gate2 = _basics.BasicGate()
    assert gate1 == gate2
    assert not (gate1 != gate2)
    gate3 = _basics.MatrixGate()
    gate3.matrix = np.matrix([[1, 0], [0, -1]])
    assert gate1 != gate3
    gate4 = _basics.MatrixGate()
    gate4.matrix = [[1, 0], [0, -1]]
    assert gate4 == gate3
Пример #2
0
def test_matrix_gate():
    gate1 = _basics.MatrixGate()
    gate2 = _basics.MatrixGate()
    with pytest.raises(TypeError):
        assert gate1 == gate2
    gate3 = _basics.MatrixGate([[0, 1], [1, 0]])
    gate4 = _basics.MatrixGate([[0, 1], [1, 0]])
    gate5 = _basics.MatrixGate([[1, 0], [0, -1]])
    assert gate3 == gate4
    assert gate4 != gate5
    with pytest.raises(TypeError):
        assert gate1 != gate3
    with pytest.raises(TypeError):
        assert gate3 != gate1
    gate6 = _basics.BasicGate()
    assert gate6 != gate1
    assert gate6 != gate3
    assert gate1 != gate6
    assert gate3 != gate6
    gate7 = gate5.get_inverse()
    gate8 = _basics.MatrixGate([[1, 0], [0, (1 + 1j) / math.sqrt(2)]])
    assert gate7 == gate5
    assert gate7 != gate8
    gate9 = _basics.MatrixGate([[1, 0], [0, (1 - 1j) / math.sqrt(2)]])
    gate10 = gate9.get_inverse()
    assert gate10 == gate8
    assert gate3 == X
    assert X == gate3
    assert str(gate3) == "MatrixGate([[0, 1], [1, 0]])"
    assert hash(gate3) == hash("MatrixGate([[0, 1], [1, 0]])")