Пример #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)])
Пример #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)])
Пример #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)])
Пример #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
Пример #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])
Пример #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,)])
Пример #7
0
 def test_neg(self):
     xform = xf.random_sample(-1)
     self.assertEqual(list(xf.xiter(xform, range(100))), [])
Пример #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])
Пример #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])
Пример #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,)])
Пример #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'])
Пример #12
0
 def test_reductions_init_only(self):
     xform = xf.reductions(lambda x, y: x + y, 'success')
     self.assertEqual(list(xf.xiter(xform, [])), ['success'])
Пример #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])
Пример #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)])
Пример #15
0
 def test_empty(self):
     xform = xf.replace({1: 'one'})
     self.assertEqual(list(xf.xiter(xform, [])), [])
Пример #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,)])
Пример #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])
Пример #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])
Пример #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,)])
Пример #20
0
 def test_complete(self):
     xform = xf.partition_all(3)
     self.assertEqual(list(xf.xiter(xform, range(5))), [(0, 1, 2), (3, 4)])
Пример #21
0
 def test_gt_1(self):
     xform = xf.random_sample(2)
     self.assertEqual(list(xf.xiter(xform, range(100))), list(range(100)))
Пример #22
0
 def test_interpose_empty(self):
     xform = xf.interpose('s')
     self.assertEqual(list(xf.xiter(xform, [])), [])
Пример #23
0
 def test_empty(self):
     xform = xf.random_sample(1)
     self.assertEqual(list(xf.xiter(xform, [])), [])
Пример #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'])
Пример #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,)])
Пример #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,)])
Пример #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,)])
Пример #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])
Пример #29
0
 def test_no_pad_empty(self):
     xform = xf.partition(2)
     self.assertEqual(list(xf.xiter(xform, [])), [])
Пример #30
0
 def test_partition_none(self):
     xform = xf.partition_by(None)
     self.assertEqual(list(xf.xiter(xform, [])), [])