Lines Matching full:range
47 self.assertEqual(list(range(3)), [0, 1, 2])
48 self.assertEqual(list(range(1, 5)), [1, 2, 3, 4])
49 self.assertEqual(list(range(0)), [])
50 self.assertEqual(list(range(-3)), [])
51 self.assertEqual(list(range(1, 10, 3)), [1, 4, 7])
52 self.assertEqual(list(range(5, -5, -3)), [5, 2, -1, -4])
58 self.assertEqual(list(range(a, a+2)), [a, a+1])
59 self.assertEqual(list(range(a+2, a, -1)), [a+2, a+1])
60 self.assertEqual(list(range(a+4, a, -2)), [a+4, a+2])
62 seq = list(range(a, b, c))
67 seq = list(range(b, a, -c))
72 seq = list(range(-a, -b, -c))
77 self.assertRaises(TypeError, range)
78 self.assertRaises(TypeError, range, 1, 2, 3, 4)
79 self.assertRaises(ValueError, range, 1, 2, 0)
81 self.assertRaises(TypeError, range, 0.0, 2, 1)
82 self.assertRaises(TypeError, range, 1, 2.0, 1)
83 self.assertRaises(TypeError, range, 1, 2, 1.0)
84 self.assertRaises(TypeError, range, 1e100, 1e101, 1e101)
86 self.assertRaises(TypeError, range, 0, "spam")
87 self.assertRaises(TypeError, range, 0, 42, "spam")
89 self.assertEqual(len(range(0, sys.maxsize, sys.maxsize-1)), 2)
91 r = range(-sys.maxsize, sys.maxsize, 2)
97 "range expected at least 1 argument, got 0"
99 range()
103 "range expected at most 3 arguments, got 6"
105 range(1, 2, 3, 4, 5, 6)
108 x = range(10**20, 10**20+10, 3)
112 x = range(10**20+10, 10**20, 3)
117 x = range(10**20, 10**20+10, -3)
122 x = range(10**20+10, 10**20, -3)
127 # Now test range() with longs
128 for x in [range(-2**100),
129 range(0, -2**100),
130 range(0, 2**100, -1)]:
138 self.assertEqual(list(range(a, a+2)), [a, a+1])
139 self.assertEqual(list(range(a+2, a, -1)), [a+2, a+1])
140 self.assertEqual(list(range(a+4, a, -2)), [a+4, a+2])
142 seq = list(range(a, b, c))
149 seq = list(range(b, a, -c))
156 seq = list(range(-a, -b, -c))
177 x = range(a, b)
195 x = range(a, b)
214 x = range(a, b, c)
233 x = range(a, b, c)
249 self.assertRaises(TypeError, range)
250 self.assertRaises(TypeError, range, 1, 2, 3, 4)
251 self.assertRaises(ValueError, range, 1, 2, 0)
253 self.assertRaises(ValueError, range, a, a + 1, int(0))
254 self.assertRaises(TypeError, range, 1., 1., 1.)
255 self.assertRaises(TypeError, range, 1e100, 1e101, 1e101)
256 self.assertRaises(TypeError, range, 0, "spam")
257 self.assertRaises(TypeError, range, 0, 42, "spam")
260 self.assertRaises(TypeError, range, 0.0)
261 self.assertRaises(TypeError, range, 0, 0.0)
262 self.assertRaises(TypeError, range, 0.0, 0)
263 self.assertRaises(TypeError, range, 0.0, 0.0)
264 self.assertRaises(TypeError, range, 0, 0, 1.0)
265 self.assertRaises(TypeError, range, 0, 0.0, 1)
266 self.assertRaises(TypeError, range, 0, 0.0, 1.0)
267 self.assertRaises(TypeError, range, 0.0, 0, 1)
268 self.assertRaises(TypeError, range, 0.0, 0, 1.0)
269 self.assertRaises(TypeError, range, 0.0, 0.0, 1)
270 self.assertRaises(TypeError, range, 0.0, 0.0, 1.0)
273 u = range(2)
278 u = range(-2, 3)
292 a = range(4)
295 a = range(-2, 3)
297 self.assertEqual(range(1, 10, 3).index(4), 1)
298 self.assertEqual(range(1, -10, -3).index(-5), 2)
300 self.assertEqual(range(10**20).index(1), 1)
301 self.assertEqual(range(10**20).index(10**20 - 1), 10**20 - 1)
303 self.assertRaises(ValueError, range(1, 2**100, 2).index, 2**87)
304 self.assertEqual(range(1, 2**100, 2).index(2**87+1), 2**86)
306 self.assertEqual(range(10).index(ALWAYS_EQ), 0)
318 self.assertEqual(list(range(I(bignum), I(bignum + 1))), [bignum])
319 self.assertEqual(list(range(I(smallnum), I(smallnum + 1))), [smallnum])
325 self.assertRaises(RuntimeError, range, IX())
332 self.assertRaises(TypeError, range, IN())
335 self.assertEqual(range(10)[:I(5)], range(5))
338 range(0, 10)[:IX()]
341 range(0, 10)[:IN()]
344 self.assertEqual(range(3).count(-1), 0)
345 self.assertEqual(range(3).count(0), 1)
346 self.assertEqual(range(3).count(1), 1)
347 self.assertEqual(range(3).count(2), 1)
348 self.assertEqual(range(3).count(3), 0)
349 self.assertIs(type(range(3).count(-1)), int)
350 self.assertIs(type(range(3).count(1)), int)
351 self.assertEqual(range(10**20).count(1), 1)
352 self.assertEqual(range(10**20).count(10**20), 0)
353 self.assertEqual(range(3).index(1), 1)
354 self.assertEqual(range(1, 2**100, 2).count(2**87), 0)
355 self.assertEqual(range(1, 2**100, 2).count(2**87+1), 1)
357 self.assertEqual(range(10).count(ALWAYS_EQ), 10)
359 self.assertEqual(len(range(sys.maxsize, sys.maxsize+10)), 10)
362 self.assertEqual(repr(range(1)), 'range(0, 1)')
363 self.assertEqual(repr(range(1, 2)), 'range(1, 2)')
364 self.assertEqual(repr(range(1, 2, 3)), 'range(1, 2, 3)')
369 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
372 r = range(*t)
379 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
381 it = itorg = iter(range(*t))
382 data = list(range(*t))
399 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
400 r = range(2**65, 2**65+2)
412 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
413 r = range(20)
426 # because the range validation step was eating the exception
429 range([], 1, -1)
432 # Non-integer objects *equal* to any of the range's items are supposed
433 # to be contained in the range.
434 self.assertIn(1.0, range(3))
435 self.assertIn(True, range(3))
436 self.assertIn(1+0j, range(3))
438 self.assertIn(ALWAYS_EQ, range(3))
444 self.assertNotIn(C2(), range(3))
446 self.assertIn(int(C2()), range(3))
448 # Check that the range.__contains__ optimization is only
452 self.assertIn(C3(11), range(10))
453 self.assertIn(C3(11), list(range(10)))
456 r = range(0, 101, 2)
464 r = range(0, -20, -1)
470 r = range(0, -20, -2)
476 r = range(0)
480 r = range(0, -10)
498 iter1 = range(start, end, step)
500 test_id = "range({}, {}, {})".format(start, end, step)
504 iter1 = reversed(range(start, end, step))
506 test_id = "reversed(range({}, {}, {}))".format(start, end, step)
510 # verify range iterators instances cannot be created by
512 rangeiter_type = type(iter(range(0)))
514 long_rangeiter_type = type(iter(range(1 << 1000)))
522 for r in [range(10),
523 range(0),
524 range(1, 9, 3),
525 range(8, 0, -3),
526 range(sys.maxsize+1, sys.maxsize+10),
538 r = range(10)
546 r = range(9, -1, -1)
554 r = range(0, 10, 2)
562 r = range(9, -1, -2)
572 for r in [range(10),
573 range(0),
574 range(1, 9, 3),
575 range(8, 0, -3),
576 range(sys.maxsize+1, sys.maxsize+10),
581 r = range(*slice(1, 18, 2).indices(20))
590 test_ranges = [range(0), range(0, -1), range(1, 1, 3),
591 range(1), range(5, 6), range(5, 6, 2),
592 range(5, 7, 2), range(2), range(0, 4, 2),
593 range(0, 5, 2), range(0, 6, 2)]
613 self.assertIs(range(0) == (), False)
614 self.assertIs(() == range(0), False)
615 self.assertIs(range(2) == [0, 1], False)
618 self.assertEqual(range(0, 2**100 - 1, 2),
619 range(0, 2**100, 2))
620 self.assertEqual(hash(range(0, 2**100 - 1, 2)),
621 hash(range(0, 2**100, 2)))
622 self.assertNotEqual(range(0, 2**100, 2),
623 range(0, 2**100 + 1, 2))
624 self.assertEqual(range(2**200, 2**201 - 2**99, 2**100),
625 range(2**200, 2**201, 2**100))
626 self.assertEqual(hash(range(2**200, 2**201 - 2**99, 2**100)),
627 hash(range(2**200, 2**201, 2**100)))
628 self.assertNotEqual(range(2**200, 2**201, 2**100),
629 range(2**200, 2**201 + 1, 2**100))
633 range(0) < range(0)
635 range(0) > range(0)
637 range(0) <= range(0)
639 range(0) >= range(0)
643 # test the start, stop and step attributes of range objects
644 self.assert_attrs(range(0), 0, 0, 1)
645 self.assert_attrs(range(10), 0, 10, 1)
646 self.assert_attrs(range(-10), 0, -10, 1)
647 self.assert_attrs(range(0, 10, 1), 0, 10, 1)
648 self.assert_attrs(range(0, 10, 3), 0, 10, 3)
649 self.assert_attrs(range(10, 0, -1), 10, 0, -1)
650 self.assert_attrs(range(10, 0, -3), 10, 0, -3)