def test_index_valueerror(self): """The index method should raise a ValueError if item not in list""" for n in TestLazySorted.test_lengths: xs = range(n) for rep in xrange(5): random.shuffle(xs) ls = LazySorted(xs) self.assertRaises(ValueError, lambda: ls.index(-1)) self.assertRaises(ValueError, lambda: ls.index(n)) self.assertRaises(ValueError, lambda: ls.index(5.5))
def test_index_nonunique(self): """The index method should work in the presence of nonunique items""" for a in xrange(1, 32): for b in xrange(1, 32): xs = a * ["a"] + b * ["b"] for rep in xrange(3): random.shuffle(xs) ls = LazySorted(xs) self.assertEqual(ls.index("b"), a) self.assertEqual(ls.index("a"), 0) for rep in xrange(3): random.shuffle(xs) ls = LazySorted(xs) self.assertEqual(ls.index("a"), 0) self.assertEqual(ls.index("b"), a)
def test_simple_index(self): """The index method should work""" for n in TestLazySorted.test_lengths: xs = range(n) ys = range(n) for rep in xrange(5): random.shuffle(xs) random.shuffle(ys) ls = LazySorted(xs) for y in ys: self.assertEqual(ls.index(y), y)