def test_count_simple(self): rng = Range(0, 10, 2) self.assertEqual(rng.count(4), 1)
def test_index_float(self): rng = Range(0, 1.0, .2) self.assertEqual(rng.index(.4), 2)
def test_index_negative_step(self): rng = Range(3.7, 1.2, -.3) self.assertEqual(rng.index(3.1), 2)
def test_index_int(self): rng = Range(0, 10, 2) self.assertEqual(rng.index(4), 2)
def test_float_desc_to_asc(self): rng = Range(1.0, 0, -.2) rng.reverse() self.assertEqual(rng.start, 0) self.assertEqual(rng.stop, 1.0) self.assertEqual(rng.step, .2)
def test_int_desc_to_asc(self): rng = Range(10, 0, -2) rng.reverse() self.assertEqual(rng.start, 0) self.assertEqual(rng.stop, 10) self.assertEqual(rng.step, 2)
def test_enumerate_float(self): rng = Range(0, .4, .2) items = [i for i in rng.enumerate()] self.assertEqual(items, [(0, 0), (1, .2), (2, .4)])
def test_enumerate_int(self): rng = Range(0, 4, 2) items = [i for i in rng.enumerate()] self.assertEqual(items, [(0, 0), (1, 2), (2, 4)])