コード例 #1
0
def test___add__():
    assert kg + kg == si.Physical(2, si.Dimensions(1, 0, 0, 0, 0, 0, 0), 1)
    assert m + ft == si.Physical(1.3048, si.Dimensions(0, 1, 0, 0, 0, 0, 0), 1)
    assert ft + m == si.Physical(1.3048, si.Dimensions(0, 1, 0, 0, 0, 0, 0),
                                 1 / 0.3048)
    assert N + lb == si.Physical(5.4482216152605005,
                                 si.Dimensions(1, 1, -2, 0, 0, 0, 0), 1)
    assert lb + N == si.Physical(5.4482216152605005,
                                 si.Dimensions(1, 1, -2, 0, 0, 0, 0),
                                 0.22480894309971047)
    assert ft + 3 == si.Physical(1.2192, si.Dimensions(0, 1, 0, 0, 0, 0, 0),
                                 1 / 0.3048)
    with pytest.raises(ValueError):
        kg + m
        N + psf
コード例 #2
0
def test__get_derived_unit():
    func = phf._get_derived_unit
    assert func(si.Dimensions(1, 1, -2, 0, 0, 0, 0), env_dims) == {
        "N": {
            "Dimension": si.Dimensions(kg=1, m=1, s=-2, A=0, cd=0, K=0, mol=0),
            "Factor": 1,
        }
    }
    assert func(si.Dimensions(1, 0, 0, 0, 0, 0, 0), env_dims) == {}
    assert func(si.Dimensions(1, 0, -2, 0, 0, 0, 0), env_dims) == {
        "N_m": {
            "Dimension": si.Dimensions(kg=1, m=0, s=-2, A=0, cd=0, K=0, mol=0),
            "Factor": 1,
            "Symbol": "N/m",
        }
    }
    assert func(si.Dimensions(1, 1, 1, 1, 1, 1, 1), env_dims) == {}
コード例 #3
0
def test___pow__():
    assert N**2 == si.Physical(1, si.Dimensions(2, 2, -4, 0, 0, 0, 0), 1)
    assert ft**3 == si.Physical(0.3048**3, si.Dimensions(0, 3, 0, 0, 0, 0, 0),
                                (1 / 0.3048)**3)
コード例 #4
0
def test___rsub__():
    assert 2 - ft == si.Physical(0.3048, si.Dimensions(0, 1, 0, 0, 0, 0, 0),
                                 1 / 0.3048)
    assert 10 - N == si.Physical(9, si.Dimensions(1, 1, -2, 0, 0, 0, 0), 1)
コード例 #5
0
def test__check_dims_parallel():
    assert phf._check_dims_parallel((3, 2, 1, 0), (6, 4, 2, 0))
    assert phf._check_dims_parallel(si.Dimensions(1, 2, -2, 0, 0, 0, 0),
                                    si.Dimensions(-1, -2, 2, 0, 0, 0, 0))