def test_timeserie_toevents():
    a = TimeSerie([1, 2, 3], t0=1, fs=2, name="a")
    e1, e2, e3 = a.to_events()
    assert compare_events(e1, Event(1, t=1, name="a"))
    assert compare_events(e2, Event(2, 1.5, name="a"))
    assert compare_events(e3, Event(3, 2.0, name="a"))
    return True
def test_statechangearray_toevents():
    a = StateChangeArray([1, 3, 5, 7], t=[1, 2, 4, 8], name="a")
    e1, e2, e3, e4 = a.to_events()
    assert compare_events(e1, Event(1, t=1, name="a"))
    assert compare_events(e2, Event(3, t=2, name="a"))
    assert compare_events(e3, Event(5, t=4, name="a"))
    assert compare_events(e4, Event(7, t=8, name="a"))
    return True
def test_statechangearray_fromevents():
    a1 = Event(1, t=1, name="a")
    a2 = Event(3, t=2, name="a")
    a3 = Event(5, t=4, name="a")
    a4 = Event(7, t=8, name="a")
    a = StateChangeArray.from_events([a1, a2, a3, a4])
    assert compare_statechangearrays(
        a, StateChangeArray([1, 3, 5, 7], t=[1, 2, 4, 8], name="a"))
    a5 = Event(9, t=6, name="a")
    with pytest.raises(ValueError):
        b = StateChangeArray.from_events([a1, a2, a3, a4, a5])
    return True
def test_event_init():
    a = Event(1)
    assert a.value == 1
    assert a.t == 0
    assert a.name == ""
    assert a.validity == 1
    start = pytz.utc.localize(dt.datetime(2000, 1, 1))
    b = Event(2, t=start)
    assert b.value == 2
    assert b.t == 946684800.0
    start = dt.datetime(2000, 1, 1)
    c = Event(2, t=start)
    assert c.value == 2
    assert c.t == 946684800.0
    d = Event(3, t=3, name="d")
    assert d.value == 3
    assert d.t == 3
    assert d.name == "d"
    e = Event(4, t=4, name="e", validity=0)
    assert e.value == 4
    assert e.t == 4
    assert e.name == "e"
    assert e.validity == 0
    return True
def test_event_state():
    a = Event(4, t=4, name="a", validity=1)
    assert a.state == a.value
    a.validity = 0
    assert a.state == "?"
    return True
def test_event_repr():
    a = Event(1, t=0, name="a")
    assert repr(a) == "Event(1, t=0, name='a')"
    return True
def test_report_toevent():
    a = Report(1, 3, name="a")
    a_start, a_end = a.to_events()
    assert compare_events(a_start, Event(1, t=1, name="a"))
    assert compare_events(a_end, Event(0, t=3, name="a"))
    return True