Exemplo n.º 1
0
def test_human_time():
    items = [
        # (expected, value, err)

        # scales
        ("1.00ns", 1e-9),
        ("1.10μs", 1.1e-6),
        ("1.12ms", 1.12e-3),
        ("1.12s", 1.123),
        ("1.13s", 1.126),
        ("1.00m", 60),
        ("2.00h", 3600 * 2),

        # err
        ("1.00±1ns", 1e-9, 1e-9),
        ("1.00±0.1ns", 1e-9, 0.1e-9),
        ("1.00±0.01ns", 1e-9, 0.01e-9),
        ("1.00±0.01ns", 1e-9, 0.006e-9),
        ("1.00±0ns", 1e-9, 0.001e-9),
    ]

    for item in items:
        expected = item[0]
        got = util.human_time(*item[1:])
        assert got == expected, item
        got = util.human_value(item[1], 'seconds', *item[2:])
        assert got == expected, item
Exemplo n.º 2
0
def test_human_time():
    items = [
        # (expected, value, err)

        # scales
        ("1.00ns", 1e-9),
        ("1.10μs", 1.1e-6),
        ("1.12ms", 1.12e-3),
        ("1.12s", 1.123),
        ("1.13s", 1.126),
        ("1.00m", 60),
        ("2.00h", 3600*2),

        # err
        ("1.00±1ns", 1e-9, 1e-9),
        ("1.00±0.1ns", 1e-9, 0.1e-9),
        ("1.00±0.01ns", 1e-9, 0.01e-9),
        ("1.00±0.01ns", 1e-9, 0.006e-9),
        ("1.00±0ns", 1e-9, 0.001e-9),
    ]

    for item in items:
        expected = item[0]
        got = util.human_time(*item[1:])
        assert got == expected, item
        got = util.human_value(item[1], 'seconds', *item[2:])
        assert got == expected, item