def test_recursivity(self): for n in range(2, 10): for k in range(1, n): with self.subTest(name='({}, {})'.format(n, k)): self.assertEqual( mathbox.binomial(n, k), mathbox.binomial(n - 1, k - 1) + mathbox.binomial(n - 1, k))
def setUp(self): super().setUp() self.M = [4, 3, 2] self.h_vec = { 1: np.arange(1, binomial(self.M[0], 1) + 1), 2: np.arange(1, binomial(self.M[1] + 1, 2) + 1), 3: np.arange(1, binomial(self.M[2] + 2, 3) + 1) } self.h_tri = { 1: np.array([1, 2, 3, 4]), 2: np.array([[1, 2, 3], [0, 4, 5], [0, 0, 6]]), 3: np.array([[[1, 2], [0, 3]], [[0, 0], [0, 4]]]) } self.h_sym = { 1: np.array([1, 2, 3, 4]), 2: np.array([[1., 1, 3 / 2], [1, 4, 5 / 2], [3 / 2, 5 / 2, 6]]), 3: np.array([[[1., 2 / 3], [2 / 3, 1]], [[2 / 3, 1], [1, 4]]]) }
def setUp(self): self.M = 4 self.h_vec = { 2: np.arange(1, binomial(self.M + 1, 2) + 1), 3: np.arange(1, binomial(self.M + 2, 3) + 1) } self.h_tri = { 2: np.array([[1, 2, 3, 4], [0, 5, 6, 7], [0, 0, 8, 9], [0, 0, 0, 10]]), 3: np.array([[[1, 2, 3, 4], [0, 5, 6, 7], [0, 0, 8, 9], [0, 0, 0, 10]], [[0, 0, 0, 0], [0, 11, 12, 13], [0, 0, 14, 15], [0, 0, 0, 16]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 17, 18], [0, 0, 0, 19]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 20]]]) } self.h_sym = { 2: np.array([[1, 1, 1.5, 2], [1, 5, 3, 3.5], [1.5, 3, 8, 4.5], [2, 3.5, 4.5, 10]]), 3: np.array([[[1., 2 / 3, 1, 4 / 3], [2 / 3, 5 / 3, 1, 7 / 6], [1, 1, 8 / 3, 1.5], [4 / 3, 7 / 6, 1.5, 10 / 3]], [[2 / 3, 5 / 3, 1, 7 / 6], [5 / 3, 11, 4, 13 / 3], [1, 4, 14 / 3, 2.5], [7 / 6, 13 / 3, 2.5, 16 / 3]], [[1, 1, 8 / 3, 1.5], [1, 4, 14 / 3, 2.5], [8 / 3, 14 / 3, 17, 6], [1.5, 2.5, 6, 19 / 3]], [[4 / 3, 7 / 6, 1.5, 10 / 3], [7 / 6, 13 / 3, 2.5, 16 / 3], [1.5, 2.5, 6, 19 / 3], [10 / 3, 16 / 3, 19 / 3, 20]]]) }
def test_symmetry(self): for n in range(1, 10): for k in range(1, n): with self.subTest(name='({}, {})'.format(n, k)): self.assertEqual(mathbox.binomial(n, k), mathbox.binomial(n, n - k))
def test_n_choose_n(self): for n in range(1, 10): with self.subTest(i=n): self.assertEqual(mathbox.binomial(n, n), 1)
def test_form_as_list(self): M = self.Mmax N = self.Nmax val = binomial(M + N, N) - 1 + binomial(M, 2) nb_coeff = series_nb_coeff(N, M, form=self.form_list) self.assertEqual(nb_coeff, val)
def test_nb_coeff_triangular_form(self): for N, M in self.iter_obj: with self.subTest(i=(N, M)): nb_coeff = series_nb_coeff(N, M, form='tri') self.assertEqual(nb_coeff, binomial(M + N, N) - 1)
def test_nb_coeff_symmetric_form(self): for N, M in self.iter_obj: with self.subTest(i=(N, M)): nb_coeff = kernel_nb_coeff(N, M, form='sym') self.assertEqual(nb_coeff, binomial(M + N - 1, N))