-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incluido doctest e código para Trem com padrão GOF
- Loading branch information
renzon
committed
Apr 16, 2017
1 parent
bab096b
commit 94d51fb
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, unicode_literals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |