complete draft: update from Atlas

This commit is contained in:
Luciano Ramalho
2021-06-09 00:13:02 -03:00
parent 08a4001b43
commit 135eca25d9
43 changed files with 4705 additions and 3240 deletions

View File

@@ -5,7 +5,7 @@ import random
from tombola import Tombola
class LotteryBlower(Tombola):
class LottoBlower(Tombola):
def __init__(self, iterable):
self._balls = list(iterable) # <1>
@@ -17,14 +17,14 @@ class LotteryBlower(Tombola):
try:
position = random.randrange(len(self._balls)) # <2>
except ValueError:
raise LookupError('pick from empty BingoCage')
raise LookupError('pick from empty LottoBlower')
return self._balls.pop(position) # <3>
def loaded(self): # <4>
return bool(self._balls)
def inspect(self): # <5>
return tuple(sorted(self._balls))
return tuple(self._balls)
# end::LOTTERY_BLOWER[]

View File

@@ -28,7 +28,7 @@ class Tombola(abc.ABC): # <1>
except LookupError:
break
self.load(items) # <7>
return tuple(sorted(items))
return tuple(items)
# end::TOMBOLA_ABC[]

View File

@@ -1,4 +1,5 @@
# tag::TOMBOLA_RUNNER[]
#!/usr/bin/env python3
import doctest
from tombola import Tombola
@@ -13,8 +14,7 @@ TEST_MSG = '{0:16} {1.attempted:2} tests, {1.failed:2} failed - {2}'
def main(argv):
verbose = '-v' in argv
real_subclasses = Tombola.__subclasses__() # <2>
virtual_subclasses = list(Tombola._abc_registry) # <3>
virtual_subclasses = [tombolist.TomboList] # <3>
for cls in real_subclasses + virtual_subclasses: # <4>
test(cls, verbose)
@@ -33,4 +33,3 @@ def test(cls, verbose=False):
if __name__ == '__main__':
import sys
main(sys.argv)
# end::TOMBOLA_RUNNER[]

View File

@@ -11,8 +11,8 @@ Create and load instance from iterable::
>>> globe = ConcreteTombola(balls)
>>> globe.loaded()
True
>>> globe.inspect()
(0, 1, 2)
>>> sorted(globe.inspect())
[0, 1, 2]
Pick and collect balls::

View File

@@ -18,6 +18,6 @@ class TomboList(list): # <2>
return bool(self) # <6>
def inspect(self):
return tuple(sorted(self))
return tuple(self)
# Tombola.register(TomboList) # <7>