def test_double_count(self):
     mirror_count = solution.alternate(lambda: itertools.count(1, 1),
                                       lambda: itertools.count(-1, -1))
     sequence = [next(mirror_count) for i in range(20)]
     self.assertEqual(
         sequence,
         [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8,
          -8, 9, -9, 10, -10])
 def test_cycle_count(self):
     mirror_count = solution.alternate(lambda: itertools.count(1, 10),
                                       lambda: itertools.cycle('ABC'))
     sequence = [next(mirror_count) for i in range(20)]
     self.assertEqual(
         sequence,
         [1, 'A', 11, 'B', 21, 'C', 31, 'A', 41, 'B',
          51, 'C', 61, 'A', 71, 'B', 81, 'C', 91, 'A'])
Beispiel #3
0
    def test_with_finishing_iterable(self):
        alternator = solution.alternate(lambda: repeat("He's coming in .."),
                                        lambda: iter([3, 2, 1]))

        self.assertEqual(list(alternator), ["He's coming in ..", 3,
                                            "He's coming in ..", 2,
                                            "He's coming in ..", 1,
                                            "He's coming in .."])
 def test_repeat_cycle(self):
     mirror_count = solution.alternate(lambda: itertools.repeat('ABC'),
                                       lambda: itertools.cycle('WXYZ'))
     sequence = [next(mirror_count) for i in range(20)]
     self.assertEqual(
         sequence,
         ['ABC', 'W', 'ABC', 'X', 'ABC', 'Y', 'ABC', 'Z', 'ABC', 'W',
          'ABC', 'X', 'ABC', 'Y', 'ABC', 'Z', 'ABC', 'W', 'ABC', 'X'])
Beispiel #5
0
 def test_with_seven_iterables(self):
     alternator = solution.alternate(lambda: count(0, 7),
                                     lambda: count(1, 7),
                                     lambda: count(2, 7),
                                     lambda: count(3, 7),
                                     lambda: count(4, 7),
                                     lambda: count(5, 7),
                                     lambda: count(6, 7))
     self.assertEqual([next(alternator] for i in range(49)],
                      list(range(49)))
    def test_cycle_repeat_count(self):
        mirror_count = solution.alternate(lambda: itertools.count(2, -10),
                                          lambda: itertools.repeat('KOK'),
                                          lambda:  itertools.cycle("ABCD"))

        sequence = [next(mirror_count) for i in range(30)]
        self.assertEqual(
            sequence,
            [2, 'KOK', 'A', -8, 'KOK', 'B', -18, 'KOK', 'C',  -28,
             'KOK', 'D', -38, 'KOK', 'A', -48, 'KOK', 'B', -58, 'KOK',
             'C', -68, 'KOK', 'D', -78, 'KOK', 'A', -88, 'KOK', 'B'])
Beispiel #7
0
    def test_mirror_count(self):
        mirror_count = solution.alternate(lambda: count(1, 1),
                                          lambda: count(-1, -1))

        self.assertEqual([next(mirror_count) for i in range(1000)],
                         [x for n in range(1, 501) for x in (n, -n)])
 def test_one_input(self):
     alternative_count = solution.alternate(lambda: \
                         itertools.chain([1, 3],
                         itertools.count(0,-2)))
     solution_count = [next(alternative_count) for i in range(10)] 
     self.assertEqual(solution_count, [1, 3, 0, -2, -4, -6, -8, -10, -12, -14]) 
 def test_no_parameters_passed(self):
     alternative_count = solution.alternate()
     self.assertRaises(StopIteration, next, alternative_count)