Ejemplo n.º 1
0
def _crossover_at(seq1, seq2, xovers):
    # takes two sequences and a single crossover point or a list of points
    if not isinstance(xovers, Iterable):
        xovers = [xovers]
    cycle_seq = cycle((seq1, seq2))

    # iter. of start and stop points for sections
    xovers = chain((None,), xovers, (None,))
    parent_point_zip = izip(cycle_seq, base.pairs(xovers))

    segments = tuple(parent[start_stop[0]:start_stop[1]]
                     for parent, start_stop in parent_point_zip)

    return tuple(chain(*segments))
Ejemplo n.º 2
0
 def test_many_elements(self):
     ps = list(base.pairs([x for x in xrange(15)]))
     assert_equal(len(ps), 14)
     for p in ps:
         assert_equal(p[0], p[1] - 1)
Ejemplo n.º 3
0
 def test_one_element(self):
     assert_equal(list(base.pairs([1])), [])
Ejemplo n.º 4
0
 def test_tuple(self):
     assert_equal(list(base.pairs((1, 2, 3))), [(1, 2), (2, 3)])
Ejemplo n.º 5
0
 def test_empty(self):
     assert_equal(list(base.pairs([])), [])
Ejemplo n.º 6
0
 def test_iterable(self):
     assert_true(isinstance(base.pairs([1, 2]), collections.Iterable))
Ejemplo n.º 7
0
 def test_many_elements(self):
     ps = list(base.pairs([x for x in xrange(15)]))
     assert_equal(len(ps), 14)
     for p in ps:
         assert_equal(p[0], p[1] - 1)
Ejemplo n.º 8
0
 def test_one_element(self):
     assert_equal(list(base.pairs([1])), [])
Ejemplo n.º 9
0
 def test_tuple(self):
     assert_equal(list(base.pairs((1, 2, 3))), [(1, 2), (2, 3)])
Ejemplo n.º 10
0
 def test_empty(self):
     assert_equal(list(base.pairs([])), [])
Ejemplo n.º 11
0
 def test_iterable(self):
     assert_true(isinstance(base.pairs([1, 2]), collections.Iterable))