Пример #1
0
 def test_generate_next_line(self):
     for n in (10, 100, 1000, 10000):
         expected = [
             a + b for a, b in zip(chain(zero(), pascal(n)),
                                   chain(pascal(n), zero()))
         ]
         result = list(pascal(n + 1))
         self.assertEqual(result, expected)
Пример #2
0
 def test_n0(self):
     self.assertEqual(list(pascal(0)), [1])
Пример #3
0
 def test_negative_int(self):
     with self.assertRaises(ValueError):
         next(pascal(-1))
Пример #4
0
 def test_alternate_sum(self):
     for n in (10, 100, 1000, 10000):
         self.assertEqual(sum(alternate(pascal(n))), 0)
Пример #5
0
 def test_sum(self):
     for n in (10, 100, 1000, 10000):
         self.assertEqual(sum(pascal(n)), 2**n)
Пример #6
0
 def test_one_third(self):
     p = pascal(1 / 3)
     result = [next(p) for _ in range(4)]
     expected = [1, 1 / 3, -1 / 9, 5 / 81]
     assert_allclose(result, expected, rtol=1e-10)
Пример #7
0
 def test_n5(self):
     self.assertEqual(list(pascal(5)), [1, 5, 10, 10, 5, 1])
Пример #8
0
 def test_n1(self):
     self.assertEqual(list(pascal(1)), [1, 1])