Exemple #1
0
def test_tophysicalquantity_1():
    # conversion of PQ array elements to PQ array
    a = [
        PhysicalQuantity(1, 'mm'),
        PhysicalQuantity(2, 'm'),
        PhysicalQuantity(3, 'mm')
    ]
    b = nw.tophysicalquantity(a)
    assert_almost_equal(b.value, np.array([1, 2000, 3]))
def test_tophysicalquantity_2():
    # single value
    a = 1
    b = nw.tophysicalquantity(a)
    assert a == b
def test_tophysicalquantity_1():
    # conversion of PQ array elements to PQ array
    a = [PhysicalQuantity(1, "mm"), PhysicalQuantity(2, "m"), PhysicalQuantity(3, "mm")]
    b = nw.tophysicalquantity(a)
    assert_almost_equal(b.value, np.array([1, 2000, 3]))
def test_tophysicalquantity_5():
    # already an array
    a = [1, 2, 3] * PhysicalQuantity(1, "mm")
    b = nw.tophysicalquantity(a)
    assert_almost_equal(a.value, b.value)
    assert a.unit == b.unit
def test_tophysicalquantity_2():
    # single value
    a = 1
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
def test_tophysicalquantity_8():
    a = [PhysicalQuantity(1, 'm'), PhysicalQuantity(1, 'm')]
    b = nw.tophysicalquantity(a)
    assert_almost_equal(a[0].value, b[0].value)
    assert a[0].unit == b.unit
def test_tophysicalquantity_7():
    # don't allow different units
    a = [ PhysicalQuantity(1, 'm'), PhysicalQuantity(1, 's')]
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
Exemple #8
0
def test_tophysicalquantity_4():
    # single value
    a = PhysicalQuantity(2, 'Hz')
    b = nw.tophysicalquantity(a)
    assert a == b
Exemple #9
0
def test_tophysicalquantity_2():
    # single value
    a = 1
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
Exemple #10
0
def test_tophysicalquantity_8():
    a = [PhysicalQuantity(1, 'm'), PhysicalQuantity(1, 'm')]
    b = nw.tophysicalquantity(a)
    assert_almost_equal(a[0].value, b[0].value)
    assert a[0].unit == b.unit
Exemple #11
0
def test_tophysicalquantity_7():
    # don't allow different units
    a = [PhysicalQuantity(1, 'm'), PhysicalQuantity(1, 's')]
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
Exemple #12
0
def test_tophysicalquantity_6():
    # no units
    a = [1, 2, 3]
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
Exemple #13
0
def test_tophysicalquantity_5():
    # already an array
    a = [1, 2, 3] * PhysicalQuantity(1, 'mm')
    b = nw.tophysicalquantity(a)
    assert_almost_equal(a.value, b.value)
    assert a.unit == b.unit
def test_tophysicalquantity_3():
    # single value
    a = 1
    b = nw.tophysicalquantity(a, "Hz")
    assert a == b.value
def test_tophysicalquantity_6():
    # no units
    a = [1, 2, 3]
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
def test_tophysicalquantity_4():
    # single value
    a = PhysicalQuantity(2, "Hz")
    b = nw.tophysicalquantity(a)
    assert a == b
Exemple #17
0
def test_tophysicalquantity_3():
    # single value
    a = 1
    b = nw.tophysicalquantity(a, 'Hz')
    assert a == b.value