Conversation
| pontos=[self._transformar_em_ponto(a) for a in self._passaros+self._obstaculos+self._porcos] | ||
|
|
||
| return pontos | ||
| return [ | ||
| self._transformar_em_ponto(a) | ||
| for a in self._passaros + self._obstaculos + self._porcos | ||
| ] |
There was a problem hiding this comment.
Function Fase.calcular_pontos refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if s == sys.stdin: | ||
| return True | ||
| return False | ||
| return any(s == sys.stdin for s in i) |
There was a problem hiding this comment.
Function ouvir_teclado_fn refactored with the following changes:
- Use any() instead of for loop (
use-any)
| if eh_windows: | ||
| ouvir_teclado = msvcrt.kbhit | ||
| else: | ||
| ouvir_teclado = ouvir_teclado_fn | ||
|
|
||
| ouvir_teclado = msvcrt.kbhit if eh_windows else ouvir_teclado_fn |
There was a problem hiding this comment.
Lines 29-33 refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| entrada = ouvir_teclado() | ||
| if entrada: | ||
| if entrada := ouvir_teclado(): |
There was a problem hiding this comment.
Function _jogar refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| rebobina(delta_t, fase, passo / velocidade_rebobina, tempo_final, | ||
| 'Rebobinando %s vezes mais rápido!' % velocidade_rebobina) | ||
| rebobina( | ||
| delta_t, | ||
| fase, | ||
| passo / velocidade_rebobina, | ||
| tempo_final, | ||
| f'Rebobinando {velocidade_rebobina} vezes mais rápido!', | ||
| ) | ||
|
|
||
| velocidade_replay = 1 | ||
| _animar(delta_t, fase, passo / velocidade_replay, tempo, 'Replay %s vezes mais rápido!' % velocidade_replay) | ||
| _animar( | ||
| delta_t, | ||
| fase, | ||
| passo / velocidade_replay, | ||
| tempo, | ||
| f'Replay {velocidade_replay} vezes mais rápido!', | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function animar refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| for i in range(5): | ||
| for _ in range(5): | ||
| fase.adicionar_passaro(PassaroVermelho(30, 30)) | ||
| # Adicionar Pássaros Amarelos | ||
| for i in range(30): | ||
| for _ in range(30): |
There was a problem hiding this comment.
Lines 18-21 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| self.assertEqual(x_esperado, round(x_calculado), 'valor real de x = %s' % x_calculado) | ||
| self.assertEqual(y_esperado, round(y_calculado), 'valor real de y = %s' % y_calculado) | ||
| self.assertEqual(status_esperado, passaro.status, '(x = %s, y = %s)' % (x_calculado, y_calculado)) | ||
| self.assertEqual( | ||
| x_esperado, round(x_calculado), f'valor real de x = {x_calculado}' | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| y_esperado, round(y_calculado), f'valor real de y = {y_calculado}' | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| status_esperado, | ||
| passaro.status, | ||
| f'(x = {x_calculado}, y = {y_calculado})', | ||
| ) |
There was a problem hiding this comment.
Function PassaroBaseTests.assert_passaro_posicao refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| porcos = [Porco(1, 1) for i in range(2)] # criando 2 porcos | ||
| passaros = [PassaroAmarelo(1, 1) for i in range(2)] # criando 2 pássaros | ||
| porcos = [Porco(1, 1) for _ in range(2)] | ||
| passaros = [PassaroAmarelo(1, 1) for _ in range(2)] |
There was a problem hiding this comment.
Function FaseTestes.teste_acabou_com_porcos_e_passaros refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
This removes the following comments ( why? ):
# criando 2 porcos
# criando 2 pássaros
| porcos = [Porco(1, 1) for i in range(2)] | ||
| passaros = [PassaroAmarelo(1, 1) for i in range(2)] | ||
| porcos = [Porco(1, 1) for _ in range(2)] | ||
| passaros = [PassaroAmarelo(1, 1) for _ in range(2)] |
There was a problem hiding this comment.
Function FaseTestes.teste_status refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| expected = set([Ponto(3, 3, 'A'), Ponto(3, 3, 'A'), Ponto(31, 10, 'O'), Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@'), Ponto(3, 3, 'V')]) | ||
| expected = { | ||
| Ponto(3, 3, 'A'), | ||
| Ponto(3, 3, 'A'), | ||
| Ponto(31, 10, 'O'), | ||
| Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@'), | ||
| Ponto(3, 3, 'V'), | ||
| } | ||
|
|
||
| self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(0))) | ||
|
|
||
| fase_exemplo.lancar(45, 1) | ||
|
|
||
| # i variando de 1 até 2.9 | ||
| for i in range(100, 300, 1): | ||
| for i in range(100, 300): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
|
|
||
| fase_exemplo.lancar(63, 3) | ||
|
|
||
| # i variando de 3 até 3.9 | ||
| for i in range(300, 400, 1): | ||
| for i in range(300, 400): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
|
|
||
| fase_exemplo.lancar(23, 4) | ||
|
|
||
| expected = set([Ponto(32, 11, 'v'), Ponto(17, 25, 'A'), Ponto(3, 3, 'A'), Ponto(31, 10, ' '), Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@')]) | ||
| expected = { | ||
| Ponto(32, 11, 'v'), | ||
| Ponto(17, 25, 'A'), | ||
| Ponto(3, 3, 'A'), | ||
| Ponto(31, 10, ' '), | ||
| Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '@'), | ||
| } | ||
|
|
||
|
|
||
| self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(4))) | ||
|
|
||
| # i variando de 4 até 6.9 | ||
| for i in range(400, 700, 1): | ||
| for i in range(400, 700): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
|
|
||
| expected = set( | ||
| [Ponto(32, 11, 'v'), Ponto(57, 30, 'A'), Ponto(70, 2, 'a'), Ponto(31, 10, ' '), Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '+')]) | ||
| expected = { | ||
| Ponto(32, 11, 'v'), | ||
| Ponto(57, 30, 'A'), | ||
| Ponto(70, 2, 'a'), | ||
| Ponto(31, 10, ' '), | ||
| Ponto(78, 1, '@'), | ||
| Ponto(70, 1, '+'), | ||
| } | ||
|
|
||
|
|
||
| self.assertSetEqual(expected, set(fase_exemplo.calcular_pontos(7))) | ||
|
|
||
| # i variando de 7 até 8.49 | ||
| for i in range(700, 849, 1): | ||
| for i in range(700, 849): | ||
| fase_exemplo.calcular_pontos(i / 100) | ||
| print(fase_exemplo.calcular_pontos(8.5)) | ||
|
|
||
| expected = set([Ponto(32, 11, 'v'), Ponto(77, 0, 'a'), Ponto(70, 2, 'a'), Ponto(31, 10, ' '), Ponto(78, 1, '+'), | ||
| Ponto(70, 1, '+')]) | ||
| expected = { | ||
| Ponto(32, 11, 'v'), | ||
| Ponto(77, 0, 'a'), | ||
| Ponto(70, 2, 'a'), | ||
| Ponto(31, 10, ' '), | ||
| Ponto(78, 1, '+'), | ||
| Ponto(70, 1, '+'), | ||
| } | ||
|
|
There was a problem hiding this comment.
Function FaseTestes.teste_calcular_pontos refactored with the following changes:
- Unwrap a constant iterable constructor. (
unwrap-iterable-construction) - Replace range(x, y, 1) with range(x, y) (
remove-unit-step-from-range)
Branch
simplesrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
simplesbranch, then run:Help us improve this pull request!