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_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):
    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(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_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_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_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)
Exemplo n.º 8
0
    def __init__(
        self, key1=CalculatorFloat(1), key2=CalculatorComplex(1j)) -> None:
        """Initialize no_propagation_class_aware class

        Args:
            key1: documentation for key1
            key2: documentation for key2
        """
        self.key1 = CalculatorFloat(key1)
        self.key2 = CalculatorComplex(key2)
Exemplo n.º 9
0
def float_sin(val: IntoCalculatorFloat) -> CalculatorFloat:
    """Return sine of value.

    Args:
        val: float value

    Returns:
        CalculatorFloat
    """
    value = CalculatorFloat(val)
    return value.sin()
Exemplo n.º 10
0
def float_acos(val: IntoCalculatorFloat) -> CalculatorFloat:
    """Return acos of value.

    Args:
        val: float value

    Returns:
        CalculatorFloat
    """
    value = CalculatorFloat(val)
    return value.acos()
Exemplo n.º 11
0
def float_atan2(a: IntoCalculatorFloat,
                b: IntoCalculatorFloat) -> CalculatorFloat:
    """Return atan2 of two CalculatorFloats.

    Args:
        a: first argument
        b: second argument

    Returns:
        CalculatorFloat
    """
    a_cf = CalculatorFloat(a)
    return a_cf.atan2(b)
Exemplo n.º 12
0
class simple_class_aware(object):

    _qonfig_defaults_dict = {
        'key1': {
            'doc': 'documentation for key1',
            'default': CalculatorFloat(1)
        },
        'key2': {
            'doc': 'documentation for key2',
            'default': CalculatorComplex(1j)
        },
    }

    def __init__(
        self, key1=CalculatorFloat(1), key2=CalculatorComplex(1j)) -> None:
        """Initialize simple_class_aware class

        Args:
            key1: documentation for key1
            key2: documentation for key2
        """
        self.key1 = CalculatorFloat(key1)
        self.key2 = CalculatorComplex(key2)

    @classmethod
    def from_qonfig(
            cls, config: Qonfig['simple_class_aware']) -> 'simple_class_aware':
        return cls(key1=config['key1'], key2=config['key2'])

    def to_qonfig(self) -> 'Qonfig[simple_class_aware]':
        config: Qonfig['simple_class_aware'] = Qonfig(self.__class__)
        config['key1'] = self.key1
        config['key2'] = self.key2
        return config
Exemplo n.º 13
0
def test_simple_to_dict():
    config = Qonfig(simple_class_aware)
    simple_dict = {
        'qonfig_name': 'test_qonfig.simple_class_aware',
        'key1': CalculatorFloat(1),
        'key2': CalculatorComplex(1j)
    }
    assert simple_dict == config.to_dict()
def test_float_cast(initial):
    cc = CalculatorFloat(initial[0])
    assert float(cc) == initial[1]
def test_float_abs(initial):
    t = abs(CalculatorFloat(initial[0]))
    assert t.isclose(initial[1])
def test_float_sin(initial):
    t = CalculatorFloat(initial[0]).sin()
    assert t.isclose(initial[1])
def test_float_acos(initial):
    t = CalculatorFloat(initial[0]).acos()
    assert t.isclose(initial[1])
def test_float_isclose(initial):
    t = CalculatorFloat(initial[0]).isclose(initial[1])
    assert t == initial[2]
def test_failed_init():
    with pytest.raises(TypeError):
        cf = CalculatorFloat(dict())
Exemplo n.º 20
0
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])
def test_float_cast_fail():
    cc = CalculatorFloat("a")
    with pytest.raises(ValueError):
        assert float(cc)