コード例 #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]))
コード例 #2
0
def test_tophysicalquantity_2():
    # single value
    a = 1
    b = nw.tophysicalquantity(a)
    assert a == b
コード例 #3
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]))
コード例 #4
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
コード例 #5
0
def test_tophysicalquantity_2():
    # single value
    a = 1
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
コード例 #6
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
コード例 #7
0
def test_tophysicalquantity_7():
    # don't allow different units
    a = [ PhysicalQuantity(1, 'm'), PhysicalQuantity(1, 's')]
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
コード例 #8
0
def test_tophysicalquantity_4():
    # single value
    a = PhysicalQuantity(2, 'Hz')
    b = nw.tophysicalquantity(a)
    assert a == b
コード例 #9
0
def test_tophysicalquantity_2():
    # single value
    a = 1
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
コード例 #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
コード例 #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)
コード例 #12
0
def test_tophysicalquantity_6():
    # no units
    a = [1, 2, 3]
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
コード例 #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
コード例 #14
0
def test_tophysicalquantity_3():
    # single value
    a = 1
    b = nw.tophysicalquantity(a, "Hz")
    assert a == b.value
コード例 #15
0
def test_tophysicalquantity_6():
    # no units
    a = [1, 2, 3]
    with raises(UnitError):
        b = nw.tophysicalquantity(a)
コード例 #16
0
def test_tophysicalquantity_4():
    # single value
    a = PhysicalQuantity(2, "Hz")
    b = nw.tophysicalquantity(a)
    assert a == b
コード例 #17
0
def test_tophysicalquantity_3():
    # single value
    a = 1
    b = nw.tophysicalquantity(a, 'Hz')
    assert a == b.value