コード例 #1
0
def test1():
    q = Quantity(1, 'km')
    assert_eq(q.SI, Quantity(1000, 'm'))

    q = Quantity(1, 'm')
    assert_eq(q, q.tounit('m'))
    q2 = q.copy()
    q.inunit('m')
    assert_eq(q, q2)
コード例 #2
0
def test_derived_units3():
    a = Quantity(2., 'brou', {'brou': Quantity(2., 'bra'),
                              'bra': Quantity(2., 'bri'),
                              'bri': Quantity(2., 'bro'),
                              'bro': Quantity(2, 'bru'),
                              'bru': Quantity(2., 'stop')})
    b = a.tounit('bra')
    assert b.magnitude == 4
    b = a.tounit('bri')
    assert b.magnitude == 8
    b = a.tounit('bro')
    assert b.magnitude == 16
    b = a.tounit('bru')
    assert b.magnitude == 32
    b = a.tounit('stop')
    assert b.magnitude == 64
    b = a.SI
    assert b.magnitude == 64
    assert b.unit == 'stop'