def test_large_nums(self): import sys ln = sys.maxsize + 1 r = Range(ln, 3 * ln, 1) o = range(ln, 3 * ln, 1) self.assertEqual(r._len, 2 * ln) self.assertEqual(r[0], o[0]) self.assertEqual(r[-1], r[-1]) self.assertIn(2 * ln, r) self.assertEqual(r.count(2 * ln), 1) self.assertEqual(r.index(2 * ln), o.index(2 * ln))
def test_index(self): r = Range(1, 10, 1) o = range(1, 10, 1) self.assertRaises(ValueError, r.index, 0) self.assertEqual(r.index(1), o.index(1)) self.assertEqual(r.index(9), o.index(9)) self.assertRaises(ValueError, r.index, 10) r = Range(1, 10, 3) o = range(1, 10, 3) self.assertRaises(ValueError, r.index, -2) self.assertEqual(r.index(1), o.index(1)) self.assertRaises(ValueError, r.index, 2) self.assertEqual(r.index(7), o.index(7)) self.assertRaises(ValueError, r.index, 9) self.assertRaises(ValueError, r.index, 10) r = Range(-5, 5, 1) o = range(-5, 5, 1) self.assertRaises(ValueError, r.index, -6) self.assertEqual(r.index(-3), o.index(-3)) self.assertEqual(r.index(0), o.index(0)) self.assertEqual(r.index(3), o.index(3)) self.assertRaises(ValueError, r.index, 5) r = Range(-5, 5, 3) o = range(-5, 5, 3) self.assertRaises(ValueError, r.index, -8) self.assertEqual(r.index(-5), o.index(-5)) self.assertRaises(ValueError, r.index, -4) self.assertRaises(ValueError, r.index, -3) self.assertEqual(r.index(-2), o.index(-2)) self.assertRaises(ValueError, r.index, -1) self.assertRaises(ValueError, r.index, 0) self.assertEqual(r.index(1), o.index(1)) self.assertRaises(ValueError, r.index, 2) self.assertRaises(ValueError, r.index, 3) self.assertEqual(r.index(4), o.index(4)) self.assertRaises(ValueError, r.index, 5) self.assertRaises(ValueError, r.index, 7) r = Range(5, -5, -1) o = range(5, -5, -1) self.assertRaises(ValueError, r.index, 6) self.assertEqual(r.index(3), o.index(3)) self.assertEqual(r.index(0), o.index(0)) self.assertEqual(r.index(-3), o.index(-3)) self.assertRaises(ValueError, r.index, -5) r = Range(5, -5, -3) o = range(5, -5, -3) self.assertRaises(ValueError, r.index, 8) self.assertEqual(r.index(5), o.index(5)) self.assertRaises(ValueError, r.index, 4) self.assertRaises(ValueError, r.index, 3) self.assertEqual(r.index(2), o.index(2)) self.assertRaises(ValueError, r.index, 1) self.assertRaises(ValueError, r.index, 0) self.assertEqual(r.index(-1), o.index(-1)) self.assertRaises(ValueError, r.index, -2) self.assertRaises(ValueError, r.index, -3) self.assertEqual(r.index(-4), o.index(-4)) self.assertRaises(ValueError, r.index, -5) self.assertRaises(ValueError, r.index, -7) r = Range(-1, -10, -1) o = range(-1, -10, -1) self.assertRaises(ValueError, r.index, 0) self.assertEqual(r.index(-1), o.index(-1)) self.assertEqual(r.index(-9), o.index(-9)) self.assertRaises(ValueError, r.index, -10) r = Range(-1, -10, -3) o = range(-1, -10, -3) self.assertRaises(ValueError, r.index, 2) self.assertEqual(r.index(-1), o.index(-1)) self.assertRaises(ValueError, r.index, -2) self.assertEqual(r.index(-7), o.index(-7)) self.assertRaises(ValueError, r.index, -9) self.assertRaises(ValueError, r.index, -10)