Lines Matching refs:slice
26 def slice_indices(slice, length): argument
33 step = 1 if slice.step is None else evaluate_slice_index(slice.step)
46 if slice.start is None:
49 start = evaluate_slice_index(slice.start)
53 if slice.stop is None:
56 stop = evaluate_slice_index(slice.stop)
75 self.assertRaises(TypeError, slice)
76 self.assertRaises(TypeError, slice, 1, 2, 3, 4)
79 self.assertEqual(repr(slice(1, 2, 3)), "slice(1, 2, 3)")
83 self.assertRaises(TypeError, hash, slice(5))
85 slice(5).__hash__()
88 s1 = slice(1, 2, 3)
89 s2 = slice(1, 2, 3)
90 s3 = slice(1, 2, 4)
104 s1 = slice(BadCmp())
105 s2 = slice(BadCmp())
109 s1 = slice(1, BadCmp())
110 s2 = slice(1, BadCmp())
114 s1 = slice(1, 2, BadCmp())
115 s2 = slice(1, 2, BadCmp())
120 s = slice(1)
125 s = slice(1, 2)
130 s = slice(1, 2, 3)
139 s = slice(obj)
142 def check_indices(self, slice, length): argument
144 actual = slice.indices(length)
148 expected = slice_indices(slice, length)
153 if length >= 0 and slice.step != 0:
154 actual = range(*slice.indices(length))
155 expected = range(length)[slice]
159 self.assertEqual(slice(None ).indices(10), (0, 10, 1))
160 self.assertEqual(slice(None, None, 2).indices(10), (0, 10, 2))
161 self.assertEqual(slice(1, None, 2).indices(10), (1, 10, 2))
162 self.assertEqual(slice(None, None, -1).indices(10), (9, -1, -1))
163 self.assertEqual(slice(None, None, -2).indices(10), (9, -1, -2))
164 self.assertEqual(slice(3, None, -2).indices(10), (3, -1, -2))
166 self.assertEqual(slice(None, -9).indices(10), (0, 1, 1))
167 self.assertEqual(slice(None, -10).indices(10), (0, 0, 1))
168 self.assertEqual(slice(None, -11).indices(10), (0, 0, 1))
169 self.assertEqual(slice(None, -10, -1).indices(10), (9, 0, -1))
170 self.assertEqual(slice(None, -11, -1).indices(10), (9, -1, -1))
171 self.assertEqual(slice(None, -12, -1).indices(10), (9, -1, -1))
172 self.assertEqual(slice(None, 9).indices(10), (0, 9, 1))
173 self.assertEqual(slice(None, 10).indices(10), (0, 10, 1))
174 self.assertEqual(slice(None, 11).indices(10), (0, 10, 1))
175 self.assertEqual(slice(None, 8, -1).indices(10), (9, 8, -1))
176 self.assertEqual(slice(None, 9, -1).indices(10), (9, 9, -1))
177 self.assertEqual(slice(None, 10, -1).indices(10), (9, 9, -1))
180 slice(-100, 100 ).indices(10),
181 slice(None).indices(10)
184 slice(100, -100, -1).indices(10),
185 slice(None, None, -1).indices(10)
187 self.assertEqual(slice(-100, 100, 2).indices(10), (0, 10, 2))
196 s = slice(*slice_args)
199 self.check_indices(slice(0, 10, 1), -3)
203 slice(None).indices(-1)
207 slice(0, 10, 0).indices(5)
212 slice(0.0, 10, 1).indices(5)
214 slice(0, 10.0, 1).indices(5)
216 slice(0, 10, 1.0).indices(5)
218 slice(0, 10, 1).indices(5.0)
221 self.assertEqual(slice(0, 10, 1).indices(5), (0, 5, 1))
222 self.assertEqual(slice(MyIndexable(0), 10, 1).indices(5), (0, 5, 1))
223 self.assertEqual(slice(0, MyIndexable(10), 1).indices(5), (0, 5, 1))
224 self.assertEqual(slice(0, 10, MyIndexable(1)).indices(5), (0, 5, 1))
225 self.assertEqual(slice(0, 10, 1).indices(MyIndexable(5)), (0, 5, 1))
235 self.assertEqual(tmp, [(slice(1, 2), 42)])
238 s = slice(10, 20, 3)
248 o.s = slice(o)