From bce2cd87583a4e85934641c7ed1c8e31f11e332b Mon Sep 17 00:00:00 2001 From: uai-ekb <40247454+uai-ekb@users.noreply.github.com> Date: Fri, 15 Jun 2018 17:06:50 +0500 Subject: [PATCH 1/5] Update tests.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Отказался от однострочника и добавил исключение на то, что если аргумент не может быть разделен на 2 (например, из-за типа аргумента) --- homework/tests.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/homework/tests.py b/homework/tests.py index 90a295b..35c154e 100644 --- a/homework/tests.py +++ b/homework/tests.py @@ -4,10 +4,22 @@ def test_even_fucntion(): и возвращает из них только четные. """ - def even_filter(*args): - pass + def even_filter(*args): + my_list = [] + for arg in args: + try: + arg % 2 == 0 + except TypeError: + continue + if arg % 2 == 0: + my_list.append(arg) + else: + pass + return my_list + assert even_filter(1, 2, 3, 4, 5, 6) == [2, 4, 6] + assert even_filter(8, 1, 2, 3, 4, 5, 6, "qwe", "asd", 8 , 8) == [8, 2, 4, 6, 8, 8] def test_increment_decorator(): From c4b23dfe8c34a99424d011e6e5fafdaae52ef50f Mon Sep 17 00:00:00 2001 From: uai-ekb <40247454+uai-ekb@users.noreply.github.com> Date: Sun, 17 Jun 2018 23:11:30 +0500 Subject: [PATCH 2/5] Update tests.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit вроде все. --- homework/tests.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/homework/tests.py b/homework/tests.py index 35c154e..c4649f1 100644 --- a/homework/tests.py +++ b/homework/tests.py @@ -28,7 +28,11 @@ def test_increment_decorator(): декрорируемую функцию. """ def increment_derocator(func): - pass + def wrapper(value): + value +=1 + func(value) + return value + return wrapper @increment_derocator def returner(value): @@ -53,12 +57,16 @@ def __init__(self, x, y): class Segment(): def __init__(self, p1, p2): - pass - + self.x1 = p1.x + self.y1 = p1.y + self.x2 = p2.x + self.y2 = p2.y + def length(self): - return 0 - + return math.sqrt(pow(self.x1 - self.x2 , 2) + pow(self.y1 - self.y2 , 2)) + p1 = Point(0, 0) p2 = Point(3, 4) + assert Segment(p1, p2).length() == 5.0 assert Segment(p2, p1).length() == 5.0 From 3b3621aafe2845d71f52616882f8a7c302edc473 Mon Sep 17 00:00:00 2001 From: uai-ekb <40247454+uai-ekb@users.noreply.github.com> Date: Sun, 17 Jun 2018 23:38:34 +0500 Subject: [PATCH 3/5] Update tests.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit забыл импорт math --- homework/tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homework/tests.py b/homework/tests.py index c4649f1..b11fc33 100644 --- a/homework/tests.py +++ b/homework/tests.py @@ -1,3 +1,5 @@ +import math + def test_even_fucntion(): """ Необходимо реализовать функцию even_filter, которая получает неограниченное количество аргументов From c0ab041a46b0083e68973e520043db8d24caccd7 Mon Sep 17 00:00:00 2001 From: uai-ekb <40247454+uai-ekb@users.noreply.github.com> Date: Mon, 18 Jun 2018 01:16:59 +0500 Subject: [PATCH 4/5] Update tests.py --- homework/tests.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/homework/tests.py b/homework/tests.py index b11fc33..c22e458 100644 --- a/homework/tests.py +++ b/homework/tests.py @@ -10,14 +10,10 @@ def test_even_fucntion(): def even_filter(*args): my_list = [] for arg in args: - try: - arg % 2 == 0 - except TypeError: + if not isinstance(arg, int): continue if arg % 2 == 0: my_list.append(arg) - else: - pass return my_list assert even_filter(1, 2, 3, 4, 5, 6) == [2, 4, 6] @@ -31,9 +27,8 @@ def test_increment_decorator(): """ def increment_derocator(func): def wrapper(value): - value +=1 - func(value) - return value + value += 1 + return func(value) return wrapper @increment_derocator @@ -59,13 +54,11 @@ def __init__(self, x, y): class Segment(): def __init__(self, p1, p2): - self.x1 = p1.x - self.y1 = p1.y - self.x2 = p2.x - self.y2 = p2.y + self.p1 = p1 + self.p2 = p2 def length(self): - return math.sqrt(pow(self.x1 - self.x2 , 2) + pow(self.y1 - self.y2 , 2)) + return math.sqrt(pow(self.p1.x - self.p2.x , 2) + pow(self.p1.y - self.p2.y , 2)) p1 = Point(0, 0) p2 = Point(3, 4) From e0fa4653bdf755c020cf247608684c4b5b59e00a Mon Sep 17 00:00:00 2001 From: uai-ekb <40247454+uai-ekb@users.noreply.github.com> Date: Wed, 20 Jun 2018 20:06:52 +0500 Subject: [PATCH 5/5] Update tests.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Учел замечания и предложения. --- homework/tests.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/homework/tests.py b/homework/tests.py index c22e458..cd990c3 100644 --- a/homework/tests.py +++ b/homework/tests.py @@ -10,9 +10,7 @@ def test_even_fucntion(): def even_filter(*args): my_list = [] for arg in args: - if not isinstance(arg, int): - continue - if arg % 2 == 0: + if isinstance(arg, int) and arg % 2 == 0: my_list.append(arg) return my_list @@ -58,7 +56,7 @@ def __init__(self, p1, p2): self.p2 = p2 def length(self): - return math.sqrt(pow(self.p1.x - self.p2.x , 2) + pow(self.p1.y - self.p2.y , 2)) + return math.sqrt(pow(self.p1.x - self.p2.x, 2) + pow(self.p1.y - self.p2.y, 2)) p1 = Point(0, 0) p2 = Point(3, 4)