Skip to content
This repository was archived by the owner on Oct 16, 2019. It is now read-only.

Update tests.py #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions homework/tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import math

def test_even_fucntion():
"""
Необходимо реализовать функцию even_filter, которая получает неограниченное количество аргументов
и возвращает из них только четные.
"""

def even_filter(*args):
pass

def even_filter(*args):
my_list = []
for arg in args:
if not isinstance(arg, int):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вкусовщина, но я бы объединил в 1 строку:

if isinstance(arg, int) and arg % 2 == 0:
    my_list.append(arg)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

точно! так эффективнее... спс

continue
if arg % 2 == 0:
my_list.append(arg)
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():
Expand All @@ -16,7 +26,10 @@ def test_increment_decorator():
декрорируемую функцию.
"""
def increment_derocator(func):
pass
def wrapper(value):
value += 1
return func(value)
return wrapper

@increment_derocator
def returner(value):
Expand All @@ -41,12 +54,14 @@ def __init__(self, x, y):

class Segment():
def __init__(self, p1, p2):
pass

self.p1 = p1
self.p2 = p2

def length(self):
return 0

return math.sqrt(pow(self.p1.x - self.p2.x , 2) + pow(self.p1.y - self.p2.y , 2))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь перед запятой лишний (по гайдам) пробел. И JFYI в питоне есть и функция возведения в степень, и оператор - **, можно пользоваться и тем, и тем, но оператор, кажется, чаще используют:

a ** 2 == pow(a, 2)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробел убрал. за оператор ** спасибо, буду использовать в будущем.

p1 = Point(0, 0)
p2 = Point(3, 4)

assert Segment(p1, p2).length() == 5.0
assert Segment(p2, p1).length() == 5.0