def test(self):
     expected = [
         1,
         Fraction('3/2'),
         Fraction('11/6'),
         Fraction('25/12'),
         Fraction('137/60'),
         Fraction('49/20'),
         Fraction('363/140'),
         Fraction('761/280'),
         Fraction('7129/2520'),
         Fraction('7381/2520'),
     ]
     self.assertEqual(list(take(10, tn.harmonic_numbers())), expected)
 def test(self):
     self.assertEqual(list(take(10, hn.hexagonal_numbers())),
                      [1, 6, 15, 28, 45, 66, 91, 120, 153, 190])
def reciprocal(number):
    return Fraction(1, number)


fraction_example = Fraction(2, 3)
assert reciprocal(reciprocal(fraction_example)) == fraction_example


def strictly_positive_integers():
    return count(1)


def strictly_positive_reciprocals():
    return map(reciprocal, strictly_positive_integers())


def accumulated_strictly_positive_reciprocals():
    return accumulate(strictly_positive_reciprocals())


harmonic_numbers = accumulated_strictly_positive_reciprocals

if __name__ == '__main__':
    from itertoolsrecipes import take

    number_to_show = 10
    print('Harmonic Numbers; the first {}.'.format(number_to_show))
    for n in take(number_to_show, accumulated_strictly_positive_reciprocals()):
        print(n)
Beispiel #4
0
 def test_simple(self):
     self.assertEqual(list(itertoolsrecipes.take(3, range(5))), [0, 1, 2])
Beispiel #5
0
 def test_cycling(self):
     gen = badger.badger_mushroom_snake_generator()
     first_loop = take(len(badger.full), gen)
     second_loop = take(len(badger.full), gen)
     self.assertEqual(first_loop, second_loop)