def teste_sortear(self): lt_res = [0, 8, 2, 4, 5, 6, 7, 9, 1, 3] lt_res.reverse() # sortear() usa pop(), que funciona do fim para o começo t = Tombola(range(10), self.fnrand) for i in range(len(t)): res = t.sortear() assert lt_res[i] == res, '%s != %s' % (lt_res[i], res)
def teste_misturar_1000(self): t = Tombola(range(1000)) str0 = repr(t) t.misturar() # existe a minúscula chance de 1:1000! (1 para fatorial de 1000) # de que o resultado seja idêntico por acaso... assert repr(t) != str0
class YTombola( OFS.SimpleItem.Item, # A simple Principia object. Not Folderish. Persistent, # Make us persistent. Yaah! Acquisition.Implicit, # Uh, whatever. AccessControl.Role.RoleManager, # Security manager. ): """Tombola class.""" meta_type = "YTombola" def __init__(self, id, title, bolas): """initialise a new instance of Tombola""" self.tombola = Tombola(bolas) # apply(Tombola.__init__, (self, bolas)) self.id = id self.title = title # self.tombola.__allow_access_to_unprotected_subobjects__ = 1 # self.sortear = self.tombola.sortear def sortear(self): """sorteia o próximo item""" return self.tombola.sortear() def __getattr__(self, attr): if hasattr(self.tombola, attr): return getattr(self.tombola, attr) else: raise AttributeError, "procuramos mas não achamos '%s'" % attr manage_options = ( {"label": "Edit", "action": "manage_main"}, {"label": "View", "action": ""}, # invocar a própria instância (call->index_html) {"label": "Security", "action": "manage_access"}, {"label": "Sortear", "action": "sortear"}, ) __ac_permissions__ = ( ("View management screens", ("manage_tabs", "manage_main")), ("Change permissions", ("manage_access",)), ("Change Tômbola", ("manage_edit",)), ("View Tômbola", ("",)), ("Use Tômbola", ("sortear", "misturar")), ) index_html = HTMLFile("index", globals()) # View Interface manage_main = HTMLFile("tombolaEdit", globals()) # Management Interface def manage_edit(self, title, bolas, REQUEST=None): """proc""" self.title = title self.bolas = bolas if REQUEST is not None: return MessageDialog(title="Edited", message="Properties for %s changed." % self.id, action="./manage_main")
import doctest from Tombola import Tombola,BingoCage,LotteryBlower,TombolList print(Tombola.__subclasses__()) print(Tombola._abc_registry())
def __init__(self, id, title, bolas): """initialise a new instance of Tombola""" self.id = id self.title = title Tombola.__init__(self, bolas)
def __init__(self, id, title, bolas): """initialise a new instance of Tombola""" Tombola.__init__(self, bolas) #apply(Tombola.__init__, (self, bolas)) self.id = id self.title = title
class Teste_Tombola(unittest.TestCase): def setUp(self): gera_rand = whrandom.whrandom(1,1,1) # assegurar séries aleatórias idênticas self.fnrand = gera_rand.random self.t10 = Tombola(range(10), whrandom.whrandom(1,1,1).random) def teste_fnrand(self): rndres = [0.0169309061997, 0.895253911238, 0.111491021216, 0.939526796411, 0.128229855101, 0.178003992983, 0.299827082495, 0.349718406372, 0.0592874602539, 0.821979314656] for i in xrange(len(rndres)): rnd = self.fnrand() assert str(rndres[i]) == str(rnd), 'séries aleatórias diferem: %s != %s' % (rndres[i], rnd) def teste_repr(self): t = Tombola([1]) assert repr(t) == '[1]' def teste_len(self): t = Tombola([1]) assert len(t) == 1 def teste_len2(self): for i in [2,4,10,100,1000,23456]: t = Tombola(range(i)) assert len(t) == i def teste_init(self): t = Tombola(range(3), self.fnrand) assert repr(t) == '[0, 2, 1]' assert len(t) == 3 def teste_init2(self): t = Tombola(('abacate', 'banana', 'caju'), self.fnrand) assert repr(t) == "['abacate', 'caju', 'banana']" assert len(t) == 3 def teste_init3(self): t = Tombola('XYZ', self.fnrand) assert repr(t) == "['X', 'Z', 'Y']" assert len(t) == 3 def teste_misturar(self): self.t10.misturar(self.fnrand) assert repr(self.t10) == "[0, 1, 2, 5, 6, 7, 9, 3, 8, 4]" def teste_misturar_1(self): t = Tombola([1]) str0 = repr(t) t.misturar() assert repr(t) == str0 def teste_misturar_1000(self): t = Tombola(range(1000)) str0 = repr(t) t.misturar() # existe a minúscula chance de 1:1000! (1 para fatorial de 1000) # de que o resultado seja idêntico por acaso... assert repr(t) != str0 def teste_sortear(self): lt_res = [0, 8, 2, 4, 5, 6, 7, 9, 1, 3] lt_res.reverse() # sortear() usa pop(), que funciona do fim para o começo t = Tombola(range(10), self.fnrand) for i in range(len(t)): res = t.sortear() assert lt_res[i] == res, '%s != %s' % (lt_res[i], res) def teste_call(self): lt_res = [0, 8, 2, 4, 5, 6, 7, 9, 1, 3] lt_res.reverse() # sortear() usa pop(), que funciona do fim para o começo t = Tombola(range(10), self.fnrand) for i in range(len(t)): res = t() assert lt_res[i] == res, '%s != %s' % (lt_res[i], res) def teste_sortear_exception(self): t = Tombola(range(3)) t.sortear() t.sortear() t.sortear() self.assertRaises(TombolaVazia, t.sortear)
def teste_sortear_exception(self): t = Tombola(range(3)) t.sortear() t.sortear() t.sortear() self.assertRaises(TombolaVazia, t.sortear)
def teste_misturar_1(self): t = Tombola([1]) str0 = repr(t) t.misturar() assert repr(t) == str0
def setUp(self): gera_rand = whrandom.whrandom(1,1,1) # assegurar séries aleatórias idênticas self.fnrand = gera_rand.random self.t10 = Tombola(range(10), whrandom.whrandom(1,1,1).random)