exec('{0}("{0}")'.format(style))
def test_shortening(self):
- """ test function shortened """
+ """ test function head_and_tail """
- # test iterating over shortened works
+ # test iterating over head_and_tail works
orig = tuple(range(10))
- for elem in shortened(orig):
+ for elem in head_and_tail(orig):
pass
# test non-shortening
- self.assertEqual(list(shortened(range(3))), list(range(3)))
+ self.assertEqual(list(head_and_tail(range(3))), list(range(3)))
# test shortening with indexable iter
- short = tuple(shortened(tuple(range(100)), skip_elem=None))
+ short = tuple(head_and_tail(tuple(range(100)), skip_elem=None))
expect = tuple(range(20)) + tuple(range(80,100))
self.assertEqual(short, expect)
self.assertEqual(len(short), 40)
# test strange cases: no head, no tail, no skip
- short = tuple(shortened(orig, n_head=2, n_tail=0, skip_elem=None))
+ short = tuple(head_and_tail(orig, n_head=2, n_tail=0, skip_elem=None))
self.assertEqual(short, (0, 1))
- short = tuple(shortened(orig, n_head=0, n_tail=2, skip_elem=None))
+ short = tuple(head_and_tail(orig, n_head=0, n_tail=2, skip_elem=None))
self.assertEqual(short, (8, 9))
- short = tuple(shortened(orig, n_head=0, n_tail=0, skip_elem=None))
+ short = tuple(head_and_tail(orig, n_head=0, n_tail=0, skip_elem=None))
self.assertEqual(len(short), 0)
- short = tuple(shortened(orig, n_head=0, n_tail=0, skip_elem="Hi!"))
+ short = tuple(head_and_tail(orig, n_head=0, n_tail=0, skip_elem="Hi!"))
self.assertEqual(short, ("Hi!",))
# test n_head + n_tail == n_elems
- short = tuple(shortened(orig, n_head=5, n_tail=5))
+ short = tuple(head_and_tail(orig, n_head=5, n_tail=5))
self.assertEqual(short, orig)
- short = tuple(shortened(orig, n_head=10, n_tail=0))
+ short = tuple(head_and_tail(orig, n_head=10, n_tail=0))
self.assertEqual(short, orig)
- short = tuple(shortened(orig, n_head=9, n_tail=1))
+ short = tuple(head_and_tail(orig, n_head=9, n_tail=1))
self.assertEqual(short, orig)
- short = tuple(shortened(orig, n_head=1, n_tail=9))
+ short = tuple(head_and_tail(orig, n_head=1, n_tail=9))
self.assertEqual(short, orig)
- short = tuple(shortened(orig, n_head=0, n_tail=10))
+ short = tuple(head_and_tail(orig, n_head=0, n_tail=10))
self.assertEqual(short, orig)
# test shortening with non-indexable iter without len()
for elem in range(100):
yield elem
- short = tuple(shortened(my_iter(), n_elems=100, skip_elem=None))
+ short = tuple(head_and_tail(my_iter(), n_elems=100, skip_elem=None))
expect = tuple(range(20)) + tuple(range(80,100))
self.assertEqual(short, expect)