def test_timeserie_neq(): a = TimeSerie([1, 2, 3], name="a", fs=1, t0=1) eq_1 = a != a assert compare_timeseries( eq_1, BooleanTimeSerie([False, False, False], t0=1, name="(a != a)", fs=1)) eq_2 = a != 1 assert compare_timeseries( eq_2, BooleanTimeSerie([False, True, True], t0=1, fs=1, name="")) b = TimeSerie([1, 2, 3], fs=2, name="b", t0=1) with pytest.raises(ValueError): eq_4 = a != b return True
def test_timeserie_or(): a = TimeSerie([True, True, False, False], name="a", fs=1, t0=1) b = BooleanTimeSerie([True, False, True, False], name="b", fs=1, t0=1) c = TimeSerie([1, 2, 3, 4], name="c", fs=1, t0=1) d = BooleanTimeSerie([True, True, True, True], name="d", fs=2, t0=3) and_1 = a | b assert compare_timeseries( and_1, BooleanTimeSerie([True, True, True, False], name="(a | b)", fs=1, t0=1)) with pytest.raises(ValueError): and_2 = a | c with pytest.raises(ValueError): and_3 = b | d return True
def test_timeserie_greaterequalthen(): a = TimeSerie([1, 2, 3], name="a", fs=1, t0=1) b = TimeSerie([3, 1, 3], name="b", fs=1, t0=1) lt_1 = a >= b assert compare_timeseries( lt_1, BooleanTimeSerie([False, True, True], t0=1, fs=1, name="(a >= b)")) lt_2 = a >= 2 assert compare_timeseries( lt_2, BooleanTimeSerie([False, True, True], t0=1, fs=1, name="")) c = TimeSerie([7, 8, 9, 0], name="c", fs=1, t0=0) with pytest.raises(ValueError): eq_3 = a >= c return True
def test_timeserie_lessthen(): a = TimeSerie([1, 2, 3], name="a", fs=1, t0=1) b = TimeSerie([3, 1, 5], name="b", fs=1, t0=1) lt_1 = b < a assert compare_timeseries( lt_1, BooleanTimeSerie([False, True, False], t0=1, fs=1, name="(b < a)")) lt_2 = a < 2 assert compare_timeseries( lt_2, BooleanTimeSerie([True, False, False], t0=1, fs=1, name="")) c = TimeSerie([7, 8, 9, 0], name="c", fs=1, t0=0) with pytest.raises(ValueError): eq_3 = a < c return True
def test_timeserie_invert(): a = TimeSerie([True, False], name="a", fs=1, t0=1) b = TimeSerie([1, 2, 3, 4], name="b", fs=1, t0=1) invert_1 = ~a assert compare_timeseries( invert_1, BooleanTimeSerie([False, True], name="(~a)", fs=1, t0=1)) with pytest.raises(ValueError): invert_2 = ~b return True
def test_booleantimeserie_repr(): a = BooleanTimeSerie([False, False, False, True, True, True], fs=2, t0=1, name="a") assert ( repr(a) == "BooleanTimeSerie([False, False, False, True, True, True], t0=1, name='a', fs=2)" ) return True
def test_timeserie_tobool(): a = TimeSerie([0, 0, 0, 1, 2, 3], t0=1, fs=2, name="a") b = a.to_bool(inplace=False) assert compare_timeseries( b, BooleanTimeSerie([False, False, False, True, True, True], t0=1, fs=2, name="a"), ) a.to_bool(inplace=True) assert compare_timeseries(a, b) return True
def test_booleantimeserie_properties(): a = BooleanTimeSerie([False, True, False], name="a", fs=2, t0=1) assert a.hz == a.fs a.hz = 1 assert a.fs == 1 b = BooleanTimeSerie([True, True, True], name="a", fs=1, t0=1) b.data = [False, True, False] assert isinstance(b.data, np.ndarray) assert all(b.data == [False, True, False]) assert compare_timeseries(a, b) with pytest.raises(ValueError): a.data = [1, 2, 3] return True
def test_timeserie_interpolate(): a = TimeSerie([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], t0=0, fs=1, name="a") t_new = np.arange(0, 9 + 0.5, 0.5) b = a.interpolate(t_new, inplace=False) assert compare_timeseries( b, TimeSerie(np.arange(1, 10.5, 0.5), t0=0, fs=2, name="a")) a.interpolate(t_new, inplace=True) assert compare_timeseries(a, b) c = BooleanTimeSerie([False, False, True, True, True, False, False], t0=1, fs=1, name="c") t_new = np.arange(1, 7 + 0.5, 0.5) d = c.interpolate(t_new, inplace=False) assert compare_timeseries( d, BooleanTimeSerie(3 * [False] + 7 * [True] + 3 * [False], t0=1, fs=2, name="c"), ) c.interpolate(t_new, inplace=True) assert compare_timeseries(c, d) return True
def test_booleantimeserie_init(): with pytest.raises(ValueError): a = BooleanTimeSerie([1, 2, 3], fs=1, t0=1, name="a") return True