コード例 #1
0
def test_to_float():
    # positive_numbers
    assert float(EngUnit('220k')) == 220000.0
    assert float(EngUnit('220m')) == 0.220

    # negative_numbers
    assert float(EngUnit('-220k')) == -220000.0
    assert float(EngUnit('-220m')) == -0.220
コード例 #2
0
def test_to_str():
    # positive_numbers
    assert str(EngUnit('220') == '220')
    assert str(EngUnit('220ohm') == '220ohm')

    # negative_numbers
    assert str(EngUnit('-220') == '-220')
    assert str(EngUnit('-220ohm') == '-220ohm')
コード例 #3
0
def test_to_int():
    # positive_numbers
    assert int(EngUnit('220k')) == 220000
    assert int(EngUnit('220m')) == 0

    # negative_numbers
    assert int(EngUnit('-220k')) == -220000
    assert int(EngUnit('-220m')) == -0
コード例 #4
0
def test_ge():
    # positive_numbers
    assert EngUnit('220kohm') >= EngUnit('219000ohm')
    assert EngUnit('220kohm') >= EngUnit('220000ohm')

    with pytest.raises(AttributeError):
        EngUnit('220kohm') >= 219000

    # negative_numbers
    assert EngUnit('-220kohm') <= EngUnit('-219000ohm')
    assert EngUnit('-220kohm') <= EngUnit('-220000ohm')

    with pytest.raises(AttributeError):
        EngUnit('-220kohm') <= -219000
コード例 #5
0
def test_to_str_large():
    # positive_numbers
    assert str(EngUnit('220kHz')) == '220kHz'
    assert str(EngUnit('220000')) == '220k'
    assert str(EngUnit(220000)) == '220k'
    assert str(EngUnit(220000.00)) == '220k'
    assert str(EngUnit(220001.25)) == '220k'

    # negative_numbers
    assert str(EngUnit('-220kHz')) == '-220kHz'
    assert str(EngUnit('-220000')) == '-220k'
    assert str(EngUnit(-220000)) == '-220k'
    assert str(EngUnit(-220000.00)) == '-220k'
    assert str(EngUnit(-220001.25)) == '-220k'
コード例 #6
0
def test_to_str_small():
    # positive_numbers
    assert str(EngUnit('220mohm')) == '220mohm'
    assert str(EngUnit('0.220')) == '220m'
    assert str(EngUnit(0.220)) == '220m'
    assert str(EngUnit(0.220000125)) == '220m'

    # negative_numbers
    assert str(EngUnit('-220mohm')) == '-220mohm'
    assert str(EngUnit('-0.220')) == '-220m'
    assert str(EngUnit(-0.220)) == '-220m'
    assert str(EngUnit(-0.220000125)) == '-220m'
コード例 #7
0
def test_gt():
    # positive_numbers
    assert EngUnit('220kohm') > EngUnit('219000ohm')

    with pytest.raises(AttributeError):
        EngUnit('220kohm') > 219000

    # negative_numbers
    assert EngUnit('-220kohm') < EngUnit('-219000ohm')

    with pytest.raises(AttributeError):
        EngUnit('-220kohm') < -219000
コード例 #8
0
def test_lt():
    # positive_numbers
    assert EngUnit('220kohm') < EngUnit('221000ohm')

    with pytest.raises(AttributeError):
        EngUnit('220kohm') < 221000
コード例 #9
0
def test_eq():
    # positive_numbers
    assert EngUnit('220k') == EngUnit(220000)
    assert EngUnit('220k') == 220000
    assert EngUnit('220k') == 220000.0

    assert 220000 == EngUnit('220k')
    assert 220000.0 == EngUnit('220k')

    with pytest.raises(AttributeError):
        EngUnit('220mHz') == EngUnit('0.220ohm')
    with pytest.raises(AttributeError):
        EngUnit('220mHz') == 10
    with pytest.raises(AttributeError):
        EngUnit('220mHz') == 10.0

    # negative_numbers
    assert EngUnit('-220k') == EngUnit(-220000)
    assert EngUnit('-220k') == -220000
    assert EngUnit('-220k') == -220000.0

    assert -220000 == EngUnit('-220k')
    assert -220000.0 == EngUnit('-220k')

    with pytest.raises(AttributeError):
        EngUnit('-220mHz') == EngUnit('-0.220ohm')
    with pytest.raises(AttributeError):
        EngUnit('-220mHz') == -10
    with pytest.raises(AttributeError):
        EngUnit('-220mHz') == -10.0
コード例 #10
0
def test_div():
    # positive_numbers
    assert str(EngUnit('220ms') / EngUnit('2s')) == '110ms/s'
    assert str(EngUnit('220ms') / EngUnit('2')) == '110ms'
    assert str(EngUnit('220m') / EngUnit('2s')) == '110m/s'

    assert str(EngUnit('220ms') / 2) == '110ms'
    assert str(EngUnit('220ms') / 2.0) == '110ms'

    assert str(2 / EngUnit('220ms')) == '9.09/s'
    assert str(2.0 / EngUnit('220ms')) == '9.09/s'

    # negative_numbers
    assert str(EngUnit('-220ms') / EngUnit('-2s')) == '110ms/s'
    assert str(EngUnit('-220ms') / EngUnit('-2')) == '110ms'
    assert str(EngUnit('-220m') / EngUnit('-2s')) == '110m/s'

    assert str(EngUnit('-220ms') / -2) == '110ms'
    assert str(EngUnit('-220ms') / -2.0) == '110ms'

    assert str(-2 / EngUnit('-220ms')) == '9.09/s'
    assert str(-2.0 / EngUnit('-220ms')) == '9.09/s'
コード例 #11
0
def test_mul():
    # positive_numbers
    assert str(EngUnit('220ms') * EngUnit('2Hz')) == '440msHz'
    assert str(EngUnit('220ms') * EngUnit('2')) == '440ms'
    assert str(EngUnit('220m') * EngUnit('2s')) == '440ms'

    assert str(EngUnit('220ms') * 2) == '440ms'
    assert str(EngUnit('220ms') * 2.0) == '440ms'

    assert str(2 * EngUnit('220ms')) == '440ms'
    assert str(2.0 * EngUnit('220ms')) == '440ms'

    # negative_numbers
    assert str(EngUnit('-220ms') * EngUnit('-2Hz')) == '440msHz'
    assert str(EngUnit('-220ms') * EngUnit('-2')) == '440ms'
    assert str(EngUnit('-220m') * EngUnit('-2s')) == '440ms'

    assert str(EngUnit('-220ms') * -2) == '440ms'
    assert str(EngUnit('-220ms') * -2.0) == '440ms'

    assert str(-2 * EngUnit('-220ms')) == '440ms'
    assert str(-2.0 * EngUnit('-220ms')) == '440ms'
コード例 #12
0
def test_sub():
    # positive_numbers
    assert str(EngUnit('220mHz') - EngUnit('10mHz')) == '210mHz'
    assert str(EngUnit('220mohm') - EngUnit('220uohm')) == '219.78mohm'
    assert str(EngUnit('220m') - EngUnit('220n')) == '220m'

    assert str(EngUnit('220m') - 0.01) == '210m'
    assert str(0.220 - EngUnit('0.01')) == '210m'

    with pytest.raises(AttributeError):
        EngUnit('220mHz') - EngUnit('10m')
    with pytest.raises(AttributeError):
        EngUnit('10m') - EngUnit('220mHz')
    with pytest.raises(AttributeError):
        10.0 - EngUnit('220mHz')

    # negative_numbers
    assert str(EngUnit('-220mHz') - EngUnit('-10mHz')) == '-210mHz'
    assert str(EngUnit('-220mohm') - EngUnit('-220uohm')) == '-219.78mohm'
    assert str(EngUnit('-220m') - EngUnit('-220n')) == '-220m'

    assert str(EngUnit('-220m') - -0.01) == '-210m'
    assert str(-0.220 - EngUnit('-0.01')) == '-210m'

    with pytest.raises(AttributeError):
        EngUnit('-220mHz') - EngUnit('-10m')
    with pytest.raises(AttributeError):
        EngUnit('-10m') - EngUnit('-220mHz')
    with pytest.raises(AttributeError):
        -10.0 - EngUnit('-220mHz')
コード例 #13
0
def test_add():
    # positive_numbers
    assert str(EngUnit('220mHz') + EngUnit('10mHz')) == '230mHz'
    assert str(EngUnit('220mohm') + EngUnit('220uohm')) == '220.22mohm'
    assert str(EngUnit('220m') + EngUnit('220n')) == '220m'

    assert str(EngUnit('220m') + 0.01) == '230m'
    assert str(0.01 + EngUnit('220m')) == '230m'

    with pytest.raises(AttributeError):
        EngUnit('220mHz') + EngUnit('10m')
    with pytest.raises(AttributeError):
        EngUnit('10m') + EngUnit('220mHz')

    # negative_numbers
    assert str(EngUnit('-220mHz') + EngUnit('-10mHz')) == '-230mHz'
    assert str(EngUnit('-220mohm') + EngUnit('-220uohm')) == '-220.22mohm'
    assert str(EngUnit('-220m') + EngUnit('-220n')) == '-220m'

    assert str(EngUnit('-220m') + -0.01) == '-230m'
    assert str(-0.01 + EngUnit('-220m')) == '-230m'

    with pytest.raises(AttributeError):
        EngUnit('-220mHz') + EngUnit('-10m')
    with pytest.raises(AttributeError):
        EngUnit('-10m') + EngUnit('-220mHz')
コード例 #14
0
def eng(str_units):
    return str(EngUnit(str_units))