예제 #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))
예제 #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)
예제 #3
0
 def test_one_element(self):
     assert_equal(list(base.pairs([1])), [])
예제 #4
0
 def test_tuple(self):
     assert_equal(list(base.pairs((1, 2, 3))), [(1, 2), (2, 3)])
예제 #5
0
 def test_empty(self):
     assert_equal(list(base.pairs([])), [])
예제 #6
0
 def test_iterable(self):
     assert_true(isinstance(base.pairs([1, 2]), collections.Iterable))
예제 #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)
예제 #8
0
 def test_one_element(self):
     assert_equal(list(base.pairs([1])), [])
예제 #9
0
 def test_tuple(self):
     assert_equal(list(base.pairs((1, 2, 3))), [(1, 2), (2, 3)])
예제 #10
0
 def test_empty(self):
     assert_equal(list(base.pairs([])), [])
예제 #11
0
 def test_iterable(self):
     assert_true(isinstance(base.pairs([1, 2]), collections.Iterable))