def test_add_different_units():
    a = np.random.randn(10)
    b = QA(a, 'm')
    c = QA(a, 's')
    with raises(UnitError):
        b + c
def test_add_same_units():
    a = np.random.randn(10)
    b = QA(a, 'm')
    c = b + b
    assert_almost_equal((b + b).view(np.ndarray), a + a)
    assert c.unit == b.unit
def test_unit():
    a = np.random.randn(10)
    b = QA(a, 'm')
    assert str(b.unit) == 'm'
Пример #4
0
def test_dir():
    a = np.random.randn(10)
    b = QA(a, 'm')
    assert len(b.__dir__()) > 10
def test_multiply_different_units():
    a = QA(np.random.randn(10), 'm')
    b = QA(np.random.randn(10), 's')
    c = a * b
    assert str(c.unit) == 'm*s'
    assert_almost_equal(c, a.view(np.ndarray) * b.view(np.ndarray))
Пример #6
0
def test_square():
    a = QA(np.random.randn(10), 'm')
    b = a**2
    assert_almost_equal(b, a.view(np.ndarray)**2)
    assert str(b.unit) == 'm^2'
Пример #7
0
def test_to():
    a = np.random.randn(10)
    b = QA(a, 'mm')
    c = b.to('m')
    assert_almost_equal((c+c).view(np.ndarray)*1e3, a+a)
def test_ufunc_fail():
    a = np.random.randn(10)
    b = QA(a, 'm')
    c = QA(a, 's')
    with raises(ValueError):
        b + c
def test_dir():
    a = np.random.randn(10)
    b = QA(a, 'm')
    assert len(b.__dir__()) > 10
Пример #10
0
def test_to():
    a = np.random.randn(10)
    b = QA(a, 'mm')
    c = b.to('m')
    assert_almost_equal((c + c).view(np.ndarray) * 1e3, a + a)
Пример #11
0
def test_to_multiple():
    a = np.random.randn(10)
    b = QA(a, 'm/s')
    with raises(ValueError):
        b.to('km/h', 'km/s')
Пример #12
0
def test_ufunc():
    a = np.random.randn(10)
    b = QA(a, 'm')
    assert_almost_equal((b + b).view(np.ndarray), a + a)
Пример #13
0
def test_power():
    a = QA(np.random.randn(10), 'm')
    b = a**3
    assert_almost_equal(b, a.view(np.ndarray)**3)
    assert str(b.unit) == 'm^3'
Пример #14
0
def test_square():
    a = QA(np.random.randn(10), 'm')
    b = a**2
    assert_almost_equal(b, a.view(np.ndarray)**2)
    assert str(b.unit) == 'm^2'
Пример #15
0
def test_subtract_same_units():
    a = QA(np.random.randn(10), 'm')
    b = QA(np.random.randn(10), 'm')
    assert_almost_equal((a - b).view(np.ndarray), a + b)
    assert a.unit == b.unit
Пример #16
0
def test_getattr():
    a = np.random.randn(10)
    b = QA(a, 'm')
    c = b.m
    assert_almost_equal(b, c)
Пример #17
0
def test_multiply_different_units():
    a = QA(np.random.randn(10), 'm')
    b = QA(np.random.randn(10), 's')
    c = a*b
    assert str(c.unit) == 'm*s'
    assert_almost_equal(c, a.view(np.ndarray)*b.view(np.ndarray))
Пример #18
0
def test_getattr_dropunit():
    a = np.random.randn(10)
    b = QA(a, 'm')
    c = b.m_
    assert_almost_equal(b, c)
Пример #19
0
def test_power():
    a = QA(np.random.randn(10), 'm')
    b = a**3
    assert_almost_equal(b, a.view(np.ndarray)**3)
    assert str(b.unit) == 'm^3'
Пример #20
0
def test_base_2():
    a = np.random.randn(10)
    b = QA(a, 'm/s')
    c = b.base
    assert_almost_equal(b, c)
Пример #21
0
def test_to_multiple():
    a = np.random.randn(10)
    b = QA(a, 'm/s')
    with raises(ValueError):
        b.to('km/h', 'km/s')
Пример #22
0
def test_repr():
    a = np.random.randn(10)
    b = QA(a, 'm')
    assert len(b.__repr__()) > 5
Пример #23
0
def test_repr():
    a = np.random.randn(10)
    b = QA(a, 'm')
    assert len(b.__repr__()) > 5
Пример #24
0
def test_subtract_different_units():
    a = QA(np.random.randn(10), 'm')
    b = QA(np.random.randn(10), 's')
    with raises(UnitError):
        a - b