Exemple #1
0
def test_iter():
  ss = SliceSet()

  counted = 0
  for sl in ss:
    counted += 1
  assert counted == 0

  for k in range(0, 100, 2):
    ss.add(slice(k, k+1))

  for sl in ss:
    counted += 1
  assert counted == 50
Exemple #2
0
def test_missing_full_with_omission():
  mi = lambda sl: list(ss.missing_in(sl))

  ss = SliceSet()
  assert mi(slice(0, 100)) == [slice(0, 100)]

  ss = SliceSet()
  ss.add(slice(20, 40))
  assert mi(slice(0, 19)) == [slice(0, 19)]
  assert mi(slice(0, 20)) == [slice(0, 20)]
  assert mi(slice(0, 21)) == [slice(0, 20)]
  assert mi(slice(40, 60)) == [slice(40, 60)]
  assert mi(slice(39, 60)) == [slice(40, 60)]
  assert mi(slice(41, 60)) == [slice(41, 60)]
  assert mi(slice(20, 40)) == []
  assert mi(slice(20, 41)) == [slice(40, 41)]
  assert mi(slice(0, 60)) == [slice(0, 20), slice(40, 60)]

  ss = SliceSet()
  ss.add(slice(20, 29))
  ss.add(slice(31, 40))
  assert mi(slice(0, 19)) == [slice(0, 19)]
  assert mi(slice(0, 20)) == [slice(0, 20)]
  assert mi(slice(0, 21)) == [slice(0, 20)]
  assert mi(slice(19, 30)) == [slice(19, 20), slice(29, 30)]
  assert mi(slice(40, 60)) == [slice(40, 60)]
  assert mi(slice(39, 60)) == [slice(40, 60)]
  assert mi(slice(41, 60)) == [slice(41, 60)]
  assert mi(slice(20, 40)) == [slice(29,31)]
  assert mi(slice(20, 41)) == [slice(29,31), slice(40, 41)]
  assert mi(slice(0, 60)) == [slice(0, 20), slice(29,31), slice(40, 60)]
Exemple #3
0
def test_set_merge():
  ss = SliceSet()
  ss.add(slice(0, 1))
  assert len(ss.slices) == 1
  ss.add(slice(2, 3))
  assert len(ss.slices) == 2
  ss.add(slice(1, 2))
  assert len(ss.slices) == 1
  assert ss.slices == [slice(0,3)]
Exemple #4
0
def test_multi_merge():
  ss = SliceSet()
  for k in range(-100, 100, 2):
    ss.add(slice(k, k+1))
  assert len(ss.slices) == 100

  for k in range(50):
    assert slice(k, k+2) not in ss

  ss.add(slice(0,100))
  assert len(ss.slices) == 51
  ss.add(slice(-100,100))
  assert len(ss.slices) == 1
Exemple #5
0
def test_many_missing():
  ss = SliceSet()
  for k in range(0, 20, 2):
    ss.add(slice(k, k + 1))
  assert list(ss.missing_in(slice(10, 30))) == [
    slice(11, 12), slice(13, 14), slice(15, 16), slice(17, 18), slice(19, 30)]
Exemple #6
0
def make_single(slc):
  ss = SliceSet()
  ss.add(slc)
  return ss