def test_start_stop(): s = channel.Slice(channel.TimeSeries([14, 15, 16, 17], [4, 6, 8, 10])) np.testing.assert_allclose(s.start, 4) np.testing.assert_allclose(s.stop, 10 + 1) s = channel.Slice(channel.Continuous([14, 15, 16, 17], 4, 2)) np.testing.assert_allclose(s.start, 4) np.testing.assert_allclose(s.stop, 12) s = channel.Slice(channel.TimeTags([14, 15, 16, 17])) np.testing.assert_allclose(s.start, 14) np.testing.assert_allclose(s.stop, 17 + 1) s = channel.Slice(channel.TimeTags([14, 15, 16, 17], 4, 30)) np.testing.assert_allclose(s.start, 4) np.testing.assert_allclose(s.stop, 30)
def test_timetags_indexing(): s = channel.Slice(channel.TimeTags([10, 20, 30, 40, 50, 60])) np.testing.assert_equal(s[0:100].data, [10, 20, 30, 40, 50, 60]) np.testing.assert_equal(s[10:100].data, [10, 20, 30, 40, 50, 60]) np.testing.assert_equal(s[15:100].data, [20, 30, 40, 50, 60]) np.testing.assert_equal(s[10:60].data, [10, 20, 30, 40, 50]) np.testing.assert_equal(s[10:55].data, [10, 20, 30, 40, 50]) np.testing.assert_equal(s[11:50].data, [20, 30, 40]) np.testing.assert_equal(s[20:].data, [20, 30, 40, 50, 60]) np.testing.assert_equal(s[:50].data, [10, 20, 30, 40]) with pytest.raises(IndexError) as exc: assert s[1] assert str(exc.value) == "Scalar indexing is not supported, only slicing" with pytest.raises(IndexError) as exc: assert s[1:2:3] assert str(exc.value) == "Slice steps are not supported" s = channel.Slice(channel.TimeTags([])) assert len(s[10:30].data) == 0
def test_slice_properties(): size = 5 s = channel.Slice(channel.TimeSeries(np.random.rand(size), np.random.rand(size))) assert len(s) == size assert s.sample_rate is None s = channel.Slice(channel.Continuous(np.random.rand(size), start=0, dt=1)) assert len(s) == size assert s.sample_rate == 1e9 size = 10 s = channel.Slice(channel.TimeTags(np.arange(0, size, dtype=np.int64))) assert len(s) == size assert s.sample_rate is None s = channel.empty_slice assert len(s) == 0 assert s.sample_rate is None