Skip to content

Commit

Permalink
Incluido doctest e código para Trem com padrão GOF
Browse files Browse the repository at this point in the history
  • Loading branch information
renzon committed Apr 16, 2017
1 parent bab096b commit 94d51fb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions trens/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Esse arquvivo documeta o comportamento de um Trem

```python
>>> from trens.trem_gof import Trem
>>> t = Trem(4)
>>> for vagao in t:
... print(vagao)
vagao #1
vagao #2
vagao #3
vagao #4

```
2 changes: 2 additions & 0 deletions trens/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
24 changes: 24 additions & 0 deletions trens/trem_gof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Trem:
def __init__(self, num_vagoes):
self.num_vagoes = num_vagoes

def __iter__(self):
return IteradorTrem(self.num_vagoes)


class IteradorTrem:
def __init__(self, num_vagoes):
self.atual = 0
self.ultimo_vagao = num_vagoes - 1

def __next__(self):
if self.atual <= self.ultimo_vagao:
self.atual += 1
return 'vagao #%s' % (self.atual)
else:
raise StopIteration()


if __name__ == '__main__':
for vagao in Trem(4):
print(vagao)

0 comments on commit 94d51fb

Please sign in to comment.