Esempio n. 1
0
 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)])
Esempio n. 2
0
 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)])
Esempio n. 3
0
 def test_no_pad(self):
     xform = xf.partition(2)
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3, 4, 5])),
                      [(1, 2), (3, 4)])
Esempio n. 4
0
 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
Esempio n. 5
0
 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])
Esempio n. 6
0
 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,)])
Esempio n. 7
0
 def test_neg(self):
     xform = xf.random_sample(-1)
     self.assertEqual(list(xf.xiter(xform, range(100))), [])
Esempio n. 8
0
 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])
Esempio n. 9
0
 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])
Esempio n. 10
0
 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,)])
Esempio n. 11
0
 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'])
Esempio n. 12
0
 def test_reductions_init_only(self):
     xform = xf.reductions(lambda x, y: x + y, 'success')
     self.assertEqual(list(xf.xiter(xform, [])), ['success'])
Esempio n. 13
0
 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])
Esempio n. 14
0
 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)])
Esempio n. 15
0
 def test_empty(self):
     xform = xf.replace({1: 'one'})
     self.assertEqual(list(xf.xiter(xform, [])), [])
Esempio n. 16
0
 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,)])
Esempio n. 17
0
 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])
Esempio n. 18
0
 def test_interpose_some(self):
     xform = xf.interpose('s')
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), [1, 's', 2, 's', 3])
Esempio n. 19
0
 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,)])
Esempio n. 20
0
 def test_complete(self):
     xform = xf.partition_all(3)
     self.assertEqual(list(xf.xiter(xform, range(5))), [(0, 1, 2), (3, 4)])
Esempio n. 21
0
 def test_gt_1(self):
     xform = xf.random_sample(2)
     self.assertEqual(list(xf.xiter(xform, range(100))), list(range(100)))
Esempio n. 22
0
 def test_interpose_empty(self):
     xform = xf.interpose('s')
     self.assertEqual(list(xf.xiter(xform, [])), [])
Esempio n. 23
0
 def test_empty(self):
     xform = xf.random_sample(1)
     self.assertEqual(list(xf.xiter(xform, [])), [])
Esempio n. 24
0
 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'])
Esempio n. 25
0
 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,)])
Esempio n. 26
0
 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,)])
Esempio n. 27
0
 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,)])
Esempio n. 28
0
 def test_replace_some(self):
     xform = xf.replace({1: 'one', 2: 'two'})
     self.assertEqual(list(xf.xiter(xform, [1, 2, 3])), ['one', 'two', 3])
Esempio n. 29
0
 def test_no_pad_empty(self):
     xform = xf.partition(2)
     self.assertEqual(list(xf.xiter(xform, [])), [])
Esempio n. 30
0
 def test_partition_none(self):
     xform = xf.partition_by(None)
     self.assertEqual(list(xf.xiter(xform, [])), [])