def test_init(start_value):
    cf = CalculatorFloat(start_value)
    assert cf.value == start_value
    assert cf.is_float
    cf2 = CalculatorFloat(cf)
    assert cf.value == start_value
    assert cf.is_float
def test_div(init):
    cf = CalculatorFloat(init[0])
    assert (cf / init[1]) == CalculatorFloat(init[2])
    cf /= init[1]
    assert cf == CalculatorFloat(init[2])
    cf = CalculatorFloat(init[1])
    assert (init[0] / cf) == CalculatorFloat(init[2])
def test_str_init():
    cf = CalculatorFloat("start_value")
    assert cf.value == "start_value"
    assert not cf.is_float
    cf2 = CalculatorFloat(cf)
    assert cf.value == "start_value"
    assert not cf.is_float
def test_mult(init):
    cf = CalculatorFloat(init[0])
    assert (cf * init[1]) == CalculatorFloat(init[2])
    cf *= init[1]
    assert cf == CalculatorFloat(init[2])
    cf = CalculatorFloat(init[1])
    assert (init[0] * cf) == CalculatorFloat(init[2])
def test_sub(init):
    cf = CalculatorFloat(init[0])
    assert (cf - init[1]) == CalculatorFloat(init[2])
    cf -= init[1]
    assert cf == CalculatorFloat(init[2])
    cf = CalculatorFloat(init[1])
    assert (init[0] - cf) == CalculatorFloat(init[2])
def test_add(init):
    print('test')
    cf = CalculatorFloat(init[0])
    assert (cf + init[1]) == CalculatorFloat(init[2])
    cf += init[1]
    assert cf == CalculatorFloat(init[2])
    cf = CalculatorFloat(init[1])
    assert (init[0] + cf) == CalculatorFloat(init[2])
def test_div_fail(init):
    cf = CalculatorFloat(init[0])
    with pytest.raises(ZeroDivisionError):
        (cf / init[1])
    with pytest.raises(ZeroDivisionError):
        cf /= init[1]
    with pytest.raises(ZeroDivisionError):
        cf = CalculatorFloat(init[1])
        (init[0] / cf)
def _execute_PragmaRandomNoise(
        operation: ops.PragmaRandomNoise,
        qureg: tqureg,
) -> None:
    applied_pauli = 0
    r0 = np.random.rand()
    rates = [(operation.depolarising_rate() / 4),
             (operation.depolarising_rate() / 4),
             ((operation.depolarising_rate() / 4)
              + (operation.dephasing_rate()))]
    rrates: List[float] = list()

    for r in rates:
        rrates.append(r.float())
    rates = rrates
    gate_time = float(operation.gate_time())
    rates = cast(List[CalculatorFloat], rates)
    # t0 = -np.log(r0) / np.sum(rates)
    probabilities = np.zeros((3,))
    for co, gamma in enumerate(rates):
        probabilities[co] = 0 if CalculatorFloat(gamma).isclose(0) else gamma
    if np.sum(probabilities) != 0:
        probabilities_normalised = probabilities / np.sum(probabilities)
    # max_iteration_counter = 0
    if r0 < 1 - gate_time * np.sum(rates):
        applied_pauli = 0
    else:
        applied_pauli = int(np.random.choice([1, 2, 3],
                                             p=probabilities_normalised))
    if applied_pauli == 0:
        return None
    else:
        quest_objects = [None,
                         qops.pauliX(),
                         qops.pauliY(),
                         qops.pauliZ()]
        quest_obj = cast(_PYQUEST, quest_objects[int(applied_pauli)])
        quest_obj(qureg=qureg, qubit=operation.qubit())
def test_float_abs(initial):
    t = abs(CalculatorFloat(initial[0]))
    assert t.isclose(initial[1])
def test_number():
    c = CalculatorFloat(1)
    c = CalculatorFloat(0.1)
def test_float_sin(initial):
    t = CalculatorFloat(initial[0]).sin()
    assert t.isclose(initial[1])
def test_failed_init():
    with pytest.raises(TypeError):
        cf = CalculatorFloat(dict())
def test_float_acos(initial):
    t = CalculatorFloat(initial[0]).acos()
    assert t.isclose(initial[1])
def test_cf():
    c = CalculatorFloat('test')
    c2 = CalculatorFloat(c)
    c = CalculatorFloat(1)
    c2 = CalculatorFloat(c)
def test_string():
    c = CalculatorFloat('test')
def test_float_isclose(initial):
    t = CalculatorFloat(initial[0]).isclose(initial[1])
    assert t == initial[2]
def test_float_cast(initial):
    cc = CalculatorFloat(initial[0])
    assert float(cc) == initial[1]
def test_float_cast_fail():
    cc = CalculatorFloat("a")
    with pytest.raises(ValueError):
        assert float(cc)
def test_from_pair(start_value):
    cf = CalculatorComplex.from_pair(*start_value)
    assert cf.real == CalculatorFloat(start_value[0])
    assert cf.imag == CalculatorFloat(start_value[1])