def test_split_without_cutting_points_raises_error(self): ll = LabelList(idx='test', labels=[Label('a', 0.0, 9.0), Label('c', 9.0, 12.0)]) with pytest.raises(ValueError): ll.split([])
def test_split_with_shift_and_overlap(self): ll = LabelList('test', labels=[ Label('alpha', start=0.0, end=30.0), Label('bravo', start=20.0, end=42.0) ]) res = ll.split([12.0, 24.0], shift_times=True, overlap=2.0) for x in res: print(x.labels) assert res == [ LabelList(idx='test', labels=[ Label('alpha', 0.0, 14.0), ]), LabelList(idx='test', labels=[ Label('alpha', 0.0, 16.0), Label('bravo', 10.0, 16.0), ]), LabelList(idx='test', labels=[ Label('alpha', 0.0, 8.0), Label('bravo', 0.0, 20.0), ]) ]
def test_split_unsorted_label_list(self): ll = LabelList(idx='test', labels=[ Label('a', 0.0, 4.0), Label('c', 9.0, 12.0), Label('b', 4.0, 8.0) ]) res = ll.split([1.9, 6.2, 10.5]) assert res == [ LabelList(idx='test', labels=[ Label('a', 0.0, 1.9), ]), LabelList(idx='test', labels=[ Label('a', 1.9, 4.0), Label('b', 4.0, 6.2), ]), LabelList(idx='test', labels=[ Label('b', 6.2, 8.0), Label('c', 9.0, 10.5), ]), LabelList(idx='test', labels=[ Label('c', 10.5, 12.0), ]), ]
def test_split_with_overlap(self): ll = LabelList(idx='test', labels=[ Label('a', 0.0, 4.0), Label('b', 4.0, 8.0), Label('c', 9.0, 12.0) ]) res = ll.split([1.9, 6.2, 10.5], overlap=2.0) assert res == [ LabelList(idx='test', labels=[ Label('a', 0.0, 3.9) ]), LabelList(idx='test', labels=[ Label('a', 0, 4.0), Label('b', 4.0, 8.0) ]), LabelList(idx='test', labels=[ Label('b', 4.2, 8.0), Label('c', 9.0, 12.0)] ), LabelList(idx='test', labels=[ Label('c', 9.0, 12.0) ]), ]
def test_split_with_cutting_point_after_last_label(self): ll = LabelList(idx='test', labels=[Label('a', 0.0, 4.0), Label('c', 4.0, 8.9)]) res = ll.split([10.5]) assert len(res) == 2 assert len(res[0]) == 2 assert len(res[1]) == 0
def test_split_cutting_point_on_boundary_doesnot_split_label(self): ll = LabelList(idx='test', labels=[Label('a', 0.0, 9.0), Label('c', 9.0, 12.0)]) res = ll.split([9.0]) assert len(res) == 2 assert len(res[0]) == 1 assert len(res[1]) == 1
def test_split_single_label_that_doesnt_start_at_zero(self): ll = LabelList(idx='test', labels=[Label('c', 8.0, 12.0)]) res = ll.split([11.2], shift_times=True) assert len(res) == 2 assert len(res[0]) == 1 assert sorted(res[0])[0] == Label('c', 8.0, 11.2) assert len(res[1]) == 1 assert sorted(res[1])[0] == Label('c', 0.0, pytest.approx(0.8))
def test_split_label_within_cutting_points_is_included(self): ll = LabelList(idx='test', labels=[ Label('a', 0.0, 4.0), Label('b', 4.0, 8.0), Label('c', 9.0, 12.0) ]) res = ll.split([1.9, 10.5]) assert len(res[1]) == 3 assert sorted(res[1])[1].value == 'b' assert sorted(res[1])[1].start == 4.0 assert sorted(res[1])[1].end == 8.0
def test_split_first_label_not_splitted(self): ll = LabelList(idx='test', labels=[Label('a', 0.0, 9.0), Label('c', 9.0, 12.0)]) res = ll.split([11.2], shift_times=True) assert len(res) == 2 assert len(res[0]) == 2 assert sorted(res[0])[0] == Label('a', 0.0, 9.0) assert sorted(res[0])[1] == Label('c', 9.0, 11.2) assert len(res[1]) == 1 assert sorted(res[1])[0] == Label('c', 0.0, pytest.approx(0.8))
def test_split_with_shifting_start_and_endtime(self): ll = LabelList(idx='test', labels=[Label('a', 0.0, 9.0), Label('c', 9.0, 12.0)]) res = ll.split([4.2], shift_times=True) assert len(res) == 2 assert len(res[0]) == 1 assert sorted(res[0])[0].value == 'a' assert sorted(res[0])[0].start == 0.0 assert sorted(res[0])[0].end == 4.2 assert len(res[1]) == 2 assert sorted(res[1])[0] == Label('a', 0.0, 4.8) assert sorted(res[1])[1] == Label('c', 4.8, 7.8)
def test_split_with_endless_label(self): ll = LabelList( idx='test', labels=[Label('a', 0.0, 4.0), Label('c', 4.0, float('inf'))]) res = ll.split([1.9, 10.5]) assert len(res) == 3 assert len(res[2]) == 1 assert sorted(res[1])[1].value == 'c' assert sorted(res[1])[1].start == 4.0 assert sorted(res[1])[1].end == 10.5 assert sorted(res[2])[0].value == 'c' assert sorted(res[2])[0].start == 10.5 assert sorted(res[2])[0].end == float('inf')
def test_split_with_overlap_label_only_touches_overlap_time(self): ll = LabelList(idx='test', labels=[ Label('a', 2.0, 5.0), Label('b', 7.0, 8.0), ]) res = ll.split([6.2, 10.5], overlap=2.0) assert res == [ LabelList(idx='test', labels=[ Label('a', 2.0, 5.0), Label('b', 7.0, 8.0), ]), LabelList(idx='test', labels=[ Label('a', 4.2, 5.0), Label('b', 7.0, 8.0), ]), LabelList(idx='test', labels=[]) ]