def testHarmonic(self): py.test.raises(ValueError, funcs.harmonic, -1) py.test.raises(ValueError, funcs.harmonic, 0) assert funcs.harmonic(1) == fractions.Fraction(1, 1) assert funcs.harmonic(2) == fractions.Fraction(3, 2) assert funcs.harmonic(3) == fractions.Fraction(11, 6) assert funcs.harmonic(4) == fractions.Fraction(25, 12) assert funcs.harmonic(5) == fractions.Fraction(137, 60) assert funcs.harmonic(6) == fractions.Fraction(49, 20) assert funcs.harmonic(7) == fractions.Fraction(363, 140) assert funcs.harmonic(8) == fractions.Fraction(761, 280) assert funcs.harmonic(9) == fractions.Fraction(7129, 2520) assert funcs.harmonic(10) == fractions.Fraction(7381, 2520)
def testGeneralizedHarmonic(self): py.test.raises(ValueError, funcs.harmonic_g, -1, 1) py.test.raises(ValueError, funcs.harmonic_g, 0, 1) assert funcs.harmonic_g(10, 1) == funcs.harmonic(10) assert funcs.harmonic_g(2, 1) == fractions.Fraction(3, 2) assert funcs.harmonic_g(3, 2) == fractions.Fraction(49, 36) assert funcs.harmonic_g(4, 4) == fractions.Fraction(22369, 20736) assert funcs.harmonic_g(2, 3) == fractions.Fraction(9, 8) assert funcs.harmonic_g(4, 2) == fractions.Fraction(205, 144) assert funcs.harmonic_g(4, 4) == fractions.Fraction(22369, 20736)