def test_reduced(self): xform = xf.comp(xf.partition_by(lambda x: x % 2 == 0), xf.take(2)) self.assertEqual(list(xf.xiter(xform, [1, 3, 2, 4, 5, 7])), [(1, 3), (2, 4)])
def test_partition_with_smaller_step_reduced_during_complete(self): xform = xf.comp(xf.partition_all(3, 1), xf.take(4)) self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5])), [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5)])
def test_no_pad(self): xform = xf.partition(2) self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5])), [(1, 2), (3, 4)])
def test_fraction(self): xform = xf.random_sample(0.5) vals = set(range(1000)) results = set(xf.xiter(xform, vals)) self.assertTrue(results.issubset(vals)) self.assertTrue(0 < len(results) < 1000) # Very unlikely to be false
def test_reduced(self): xform = xf.comp(xf.random_sample(1), xf.take(2)) self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4])), [1, 2])
def test_complete(self): xform = xf.comp(xf.replace({1: 'one'}), xf.partition_all(2)) self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), [('one', 2), (3,)])
def test_neg(self): xform = xf.random_sample(-1) self.assertEqual(list(xf.xiter(xform, range(100))), [])
def test_reductions_no_init(self): xform = xf.reductions(xf.multi_arity(lambda: 100, None, sum_rf)) self.assertEqual(list(xf.xiter(xform, [1, 2])), [100, 101, 103])
def test_reductions_reduced(self): xform = xf.comp(xf.reductions(lambda x, y: x + y, 1), xf.take(3)) self.assertEqual(list(xf.xiter(xform, [2, 3, 4, 5])), [1, 3, 6])
def test_reductions_init_only_complete(self): xform = xf.comp(xf.reductions(lambda x, y: x + y, [1, 2, 3]), xf.cat, xf.partition_all(2)) self.assertEqual(list(xf.xiter(xform, [])), [(1, 2), (3,)])
def test_reductions_init_only_reduced(self): xform = xf.comp(xf.reductions(lambda x, y: x + y, 'success'), xf.take(1)) self.assertEqual(list(xf.xiter(xform, [])), ['success'])
def test_reductions_init_only(self): xform = xf.reductions(lambda x, y: x + y, 'success') self.assertEqual(list(xf.xiter(xform, [])), ['success'])
def test_reductions_some(self): xform = xf.reductions(lambda x, y: x + y, 1) self.assertEqual(list(xf.xiter(xform, [2, 3])), [1, 3, 6])
def test_complete(self): xform = xf.comp(xf.partition_by(lambda x: x % 2 == 0), xf.take(2)) self.assertEqual(list(xf.xiter(xform, [2, 4, 6, 1, 3, 5, 8])), [(2, 4, 6), (1, 3, 5)])
def test_empty(self): xform = xf.replace({1: 'one'}) self.assertEqual(list(xf.xiter(xform, [])), [])
def test_complete(self): xform = xf.comp(xf.reductions(lambda x, y: x + y, 1), xf.partition_all(2)) self.assertEqual(list(xf.xiter(xform, [2, 3])), [(1, 3), (6,)])
def test_reduced(self): xform = xf.comp(xf.replace({1: 'one'}), xf.take(2)) self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4])), ['one', 2])
def test_interpose_some(self): xform = xf.interpose('s') self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), [1, 's', 2, 's', 3])
def test_partition_with_smaller_step(self): xform = xf.partition_all(3, 1) self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5])), [(1, 2, 3), (2, 3, 4), (3, 4, 5), (4, 5), (5,)])
def test_complete(self): xform = xf.partition_all(3) self.assertEqual(list(xf.xiter(xform, range(5))), [(0, 1, 2), (3, 4)])
def test_gt_1(self): xform = xf.random_sample(2) self.assertEqual(list(xf.xiter(xform, range(100))), list(range(100)))
def test_interpose_empty(self): xform = xf.interpose('s') self.assertEqual(list(xf.xiter(xform, [])), [])
def test_empty(self): xform = xf.random_sample(1) self.assertEqual(list(xf.xiter(xform, [])), [])
def test_reduced(self): xform = xf.comp(xf.interpose('s'), xf.take(4)) self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), [1, 's', 2, 's'])
def test_complete(self): xform = xf.comp(xf.random_sample(1), xf.partition_all(2)) self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), [(1, 2), (3,)])
def test_complete(self): xform = xf.comp(xf.interpose('s'), xf.partition_all(2)) self.assertEqual(list(xf.xiter(xform, [1, 2])), [(1, 's'), (2,)])
def test_partition_with_larger_step(self): xform = xf.partition_all(2, 4) self.assertEqual(list(xf.xiter(xform, range(1, 10))), [(1, 2), (5, 6), (9,)])
def test_replace_some(self): xform = xf.replace({1: 'one', 2: 'two'}) self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), ['one', 'two', 3])
def test_no_pad_empty(self): xform = xf.partition(2) self.assertEqual(list(xf.xiter(xform, [])), [])
def test_partition_none(self): xform = xf.partition_by(None) self.assertEqual(list(xf.xiter(xform, [])), [])