def test_keysvalues_empty(): sl = SortedList([]) assert (sl._k == []) assert (sl._k == []) with pytest.raises(ValueError): sl.index(0)
def test_keysvalues_empty(): sl = SortedList([]) assert(sl._k == []) assert(sl._k == []) with pytest.raises(ValueError): sl.index(0)
def test_tuplelist(): data = [(3, 'a'), (4, 'v'), (1, 'z'), (5, 'b')] sl = SortedList(data, key=lambda x: x[1]) assert (sl._k == ['a', 'b', 'v', 'z']) assert (sl._v == [(3, 'a'), (5, 'b'), (4, 'v'), (1, 'z')]) assert (sl.index_lt((10, 'e')) == 1) assert (sl.index_le((10, 'e')) == 1) assert (sl.index_lt((5, 'b')) == 0) with pytest.raises(ValueError): sl.index((10, 'b')) with pytest.raises(ValueError): sl.index((3, 'b'))
def test_tuplelist(): data = [(3, 'a'), (4, 'v'), (1, 'z'), (5, 'b')] sl = SortedList(data, key=lambda x: x[1]) assert(sl._k == ['a', 'b', 'v', 'z']) assert(sl._v == [(3, 'a'), (5, 'b'), (4, 'v'), (1, 'z')]) assert(sl.index_lt((10, 'e')) == 1) assert(sl.index_le((10, 'e')) == 1) assert(sl.index_lt((5, 'b')) == 0) with pytest.raises(ValueError): sl.index((10, 'b')) with pytest.raises(ValueError): sl.index((3, 'b'))
def test_badindex(): sl = SortedList([3, 6, 1, 7, 0]) with pytest.raises(ValueError): sl.index(4)