result = 1
for i in xrange(1, abs(n)+1):
result *= i
- if n >= 0:
- return result
- else:
- return -result
+ assert n >= 0
+ return result
def binomial(n, k):
- if not 0 <= k <= n:
- return 0
+ assert 0 <= k <= n
if k == 0 or k == n:
return 1
# calculate n!/k! as one product, avoiding factors that
def add_input(section, text, entry):
if section not in sections:
sections[section] = []
- sections[section].append(T.div[text, ": ", entry])
+ sections[section].extend([T.div[text, ": ", entry], "\n"])
def add_output(section, entry):
if section not in sections:
sections[section] = []
- sections[section].append(T.div[entry])
+ sections[section].extend([entry, "\n"])
def build_section(section):
return T.fieldset[T.legend[section], sections[section]]
from twisted.internet import defer
from twisted.web import client, error, http
from twisted.python import failure, log
-from allmydata import webish, interfaces, dirnode, uri
+from allmydata import webish, interfaces, dirnode, uri, provisioning
from allmydata.encode import NotEnoughPeersError
from allmydata.util import fileutil
import itertools
d.addCallback(_check2)
return d
+ def test_provisioning_math(self):
+ self.failUnlessEqual(provisioning.binomial(10, 0), 1)
+ self.failUnlessEqual(provisioning.binomial(10, 1), 10)
+ self.failUnlessEqual(provisioning.binomial(10, 2), 45)
+ self.failUnlessEqual(provisioning.binomial(10, 9), 10)
+ self.failUnlessEqual(provisioning.binomial(10, 10), 1)
+
def test_provisioning(self):
d = self.GET("/provisioning/")
def _check(res):
def _check2(res):
self.failUnless('Tahoe Provisioning Tool' in res)
self.failUnless("Share space consumed: 167.01TB" in res)
+
+ fields = {'filled': True,
+ "num_users": int(50e6),
+ "files_per_user": 1000,
+ "space_per_user": int(5e9),
+ "sharing_ratio": 1.0,
+ "encoding_parameters": "25-of-100-50",
+ "num_servers": 30000,
+ "ownership_mode": "E",
+ "drive_failure_model": "U",
+ "drive_size": 1000,
+ "download_rate": 1000,
+ "upload_rate": 100,
+ "delete_rate": 100,
+ "lease_timer": 7,
+ }
+ return self.POST("/provisioning/", **fields)
d.addCallback(_check2)
+ def _check3(res):
+ self.failUnless("Share space consumed: huge!" in res)
+ fields = {'filled': True}
+ return self.POST("/provisioning/", **fields)
+ d.addCallback(_check3)
+ def _check4(res):
+ self.failUnless("Share space consumed:" in res)
+ d.addCallback(_check4)
return d
def test_start_html(self):