コード例 #1
0
def test_statechangearray_invert():
    a = StateChangeArray([True, False, True, False], t=[2, 4, 6, 8], name="a")
    not_a = ~a
    assert compare_statechangearrays(
        not_a,
        BooleanStateChangeArray([False, True, False, True],
                                t=[2, 4, 6, 8],
                                name="(~a)"),
    )
    with pytest.raises(ValueError):
        b = StateChangeArray([1, 2, 3, 4], t=[2, 4, 6, 8], name="b")
        not_b = ~b
    return True
コード例 #2
0
def test_statechangearray_or():
    a = StateChangeArray([True, False, True, False], t=[2, 4, 6, 8], name="a")
    b = StateChangeArray([True, False, True, False], t=[3, 5, 7, 9], name="b")
    with pytest.raises(ValueError):
        a_and_1 = a | 1
    c = StateChangeArray([2, 4, 6, 8], t=[1, 3, 4, 6], name="c")
    with pytest.raises(ValueError):
        a_and_c = a | c
    a_and_b = a | b
    assert compare_statechangearrays(
        a_and_b,
        BooleanStateChangeArray([True, False, True, False],
                                t=[2, 5, 6, 9],
                                name="(a | b)"),
    )
    a_and_a = a | a
    a_ = a
    a_.name = "(a | a)"
    assert compare_statechangearrays(a_and_a, a_)
    return True
コード例 #3
0
def test_statechangearray_exor():
    a = StateChangeArray([True, False, True, False], t=[2, 4, 6, 8], name="a")
    b = StateChangeArray([True, False, True, False], t=[3, 5, 7, 9], name="b")
    with pytest.raises(ValueError):
        a_and_1 = a ^ 1
    c = StateChangeArray([2, 4, 6, 8], t=[1, 3, 4, 6], name="c")
    with pytest.raises(ValueError):
        a_and_c = a ^ c
    a_and_b = a ^ b
    assert compare_statechangearrays(
        a_and_b,
        BooleanStateChangeArray(
            [False, True, False, True, False, True, False],
            t=[3, 4, 5, 6, 7, 8, 9],
            name="(a ^ b)",
        ),
    )
    a_and_a = a ^ a
    a_ = a
    a_.name = "(a ^ a)"
    assert compare_statechangearrays(
        a_and_a, BooleanStateChangeArray([False], t=[2], name="(a ^ a)"))
    return True
コード例 #4
0
def test_statechangearray_totimeseries():
    a = StateChangeArray([1, 3, 5, 7], t=[1, 2, 4, 7], name="a")
    ts_a = a.to_timeseries(fs=2)
    assert compare_timeseries(
        ts_a,
        TimeSerie([1, 1, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 7],
                  t0=1,
                  fs=2,
                  name="a"))
    b = StateChangeArray([1, 3, 5, 7], t=[1, 2, 2.25, 4])
    with pytest.raises(ValueError):
        ts_b = b.to_timeseries(fs=2)
    with pytest.raises(NameError):
        b.to_timeseries(fs=2, method="nonExistingMethod")
    c = StateChangeArray([1, 3, 5, 7], t=[1, 2, 4, 8], name="c")
    ts_c = c.to_timeseries(fs=2, method="interpolate")
    assert compare_timeseries(
        ts_c,
        TimeSerie(
            [1, 2, 3, 3.5, 4, 4.5, 5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75, 7],
            t0=1,
            fs=2,
            name="c",
        ),
    )
    return True
コード例 #5
0
def test_statechangearray_timerule():
    a = StateChangeArray(
        [False, True, False, True, False, True, False],
        t=[0, 5, 10, 20, 30, 45, 60],
        name="a",
    )
    a_timerule_1 = a.timerule(1)
    assert compare_statechangearrays(a_timerule_1, a)
    b = StateChangeArray(
        [False, True, False, True, False, True, False],
        t=[0, 5, 10, 20, 30, 45, 60],
        name="b",
    )
    b_timerule_6 = b.timerule(6)
    assert compare_statechangearrays(
        b_timerule_6,
        StateChangeArray([False, True, False, True, False],
                         t=[0, 20, 30, 45, 60],
                         name="b"),
    )
    c = StateChangeArray(
        [False, True, False, True, False, True, False],
        t=[0, 5, 10, 20, 30, 45, 60],
        name="c",
    )
    c_timerule_11 = c.timerule(11)
    assert compare_statechangearrays(
        c_timerule_11,
        StateChangeArray([False, True, False], t=[0, 45, 60], name="c"))
    d = StateChangeArray(
        [False, True, False, True, False, True, False],
        t=[0, 5, 10, 20, 30, 45, 60],
        name="d",
    )
    d_timerule_11 = d.timerule(11, when=False, operator="<")
    assert compare_statechangearrays(
        d_timerule_11,
        StateChangeArray([False, True, False, True, False],
                         t=[0, 5, 10, 20, 60],
                         name="d"),
    )
    y = StateChangeArray(
        [False, True, False, True, False, True, False],
        t=[0, 5, 10, 20, 30, 45, 60],
        name="y",
    )
    y.timerule(6, inplace=True)
    assert compare_statechangearrays(
        y,
        StateChangeArray([False, True, False, True, False],
                         t=[0, 20, 30, 45, 60],
                         name="y"),
    )
    z = StateChangeArray([1, 2, 1, 2, 1, 2, 1],
                         t=[0, 5, 10, 20, 30, 45, 60],
                         name="z")
    with pytest.raises(ValueError):
        z_time_6 = z.timerule(6)
    return True