Skip to content

Commit

Permalink
1.14 - Implementação, decisão e asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuxbaum committed Apr 2, 2021
1 parent 360580d commit fed87d5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 1_introducao/14_max_generico.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Nesta implementação em Java, o tipo genérico 'Item' implementa o método
compara() que é assegurado pela interface 'Item'.
Como o Python permite que seja feita a implementação do comparador '>' através
do magic method '__gt__', foi decidido pela sua utilização.
"""


class Max:
def max(itens):
item_max = itens[0]
for item in itens[1:]:
if item > item_max:
item_max = item
return item_max


if __name__ == "__main__":
itens_teste_inteiro = [1, 2, 3, 4, 5]
assert Max.max(itens_teste_inteiro) == 5

itens_teste_string = ["zhiuh", "poas", "asd", "basd", "choi"]
assert Max.max(itens_teste_string) == "zhiuh"

0 comments on commit fed87d5

Please sign in to comment.