コード例 #1
0
 def test_combinations_arbitrary_values(self):
     """combinations(n,k) should equal results from spreadsheet"""
     results = {
         30: {0: 1, 1: 30, 5: 142506, 18: 86493225, 29: 30, 30: 1},
         173: {0: 1, 1: 173, 5: 1218218079, 18: 1.204353e24, 29: 7.524850e32, 30: 3.611928e33},
         1000: {0: 1, 1: 1000, 5: 8.2502913e12, 18: 1.339124e38, 29: 7.506513e55, 30: 2.429608e57},
         4382: {0: 1, 1: 4382, 5: 1.343350e16, 18: 5.352761e49, 29: 4.184411e74, 30: 6.0715804e76},
     }
     for n in self.standards[3:]:
         for k in (0, 1, 5, 18, 29, 30):
             self.assertFloatEqualRel(combinations(n, k), results[n][k], 1e-5)
コード例 #2
0
 def test_combinations_arbitrary_values(self):
     """combinations(n,k) should equal results from spreadsheet"""
     results = {
         30:{0:1, 1:30, 5:142506, 18:86493225, 29:30, 30:1},
         173:{0:1, 1:173, 5:1218218079, 18:1.204353e24, 29:7.524850e32, \
              30:3.611928e33},
         1000:{0:1, 1:1000, 5:8.2502913e12, 18:1.339124e38,29:7.506513e55, \
               30:2.429608e57},
         4382:{0:1, 1:4382, 5:1.343350e16, 18:5.352761e49, 29:4.184411e74, \
               30:6.0715804e76},
               }
     for n in self.standards[3:]:
         for k in (0, 1, 5, 18, 29, 30):
             self.assertFloatEqualRel(combinations(n,k), results[n][k], 1e-5)
コード例 #3
0
 def test_combinations_symmetry(self):
     """combinations(n,k) should equal combinations(n,n-k)"""
     for n in self.standards[3:]:
         for k in (0, 1, 5, 18):
             self.assertEquals(combinations(n, k), combinations(n, n-k))
コード例 #4
0
 def test_combinations_zero_k(self):
     """combinations should return 1 if k is zero"""
     for n in self.standards:
         self.assertEqual(combinations(n, 0), 1)
コード例 #5
0
 def test_combinations_k_equals_n_minus_1(self):
     """combinations should return n if k=(n-1)"""
     for n in self.standards[1:]:
         self.assertEqual(combinations(n, n-1), n)
コード例 #6
0
 def test_combinations_k_equals_n(self):
     """combinations should return 1 if k = n"""
     for n in self.standards:
         self.assertEqual(combinations(n,n), 1)