From fed87d58db5482e23978e0e4c123633b25225ea7 Mon Sep 17 00:00:00 2001 From: Vitor Buxbaum Date: Fri, 2 Apr 2021 19:06:34 -0300 Subject: [PATCH] =?UTF-8?q?1.14=20-=20Implementa=C3=A7=C3=A3o,=20decis?= =?UTF-8?q?=C3=A3o=20e=20asserts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1_introducao/14_max_generico.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 1_introducao/14_max_generico.py diff --git a/1_introducao/14_max_generico.py b/1_introducao/14_max_generico.py new file mode 100644 index 0000000..0a9ccd4 --- /dev/null +++ b/1_introducao/14_max_generico.py @@ -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"