Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions tests/level_1_5/test_five_replace_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from functions.level_1_5.five_replace_word import replace_word

def test__replace_word__starts_with_case_irrelevant():
assert replace_word('the big black car', 'big', 'Black') == 'the Black black car'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 если case irrelevant - то это replace_word('the big black car', 'Big', 'Black'), искомое слово ищется без учета регистра букв



def test__replace_word__if_replace_word_not_find_in_text():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Можно еще явнее описать тест в названии, test__replace_word__unchanged_when_replace_word_not_found_in_text

assert replace_word('the big black car', 'red', 'small') == 'the big black car'

28 changes: 28 additions & 0 deletions tests/level_1_5/test_four_sentiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from functions.level_1_5.four_sentiment import check_tweet_sentiment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 кейсы найдены хорошие.
💡 попробую подкинуть еще, а что, если не задан good_words или bad_words, оба?
💡 а что, если пустой текст на входе
💡 а что, если текст полностью состоит из плохих слов и наоборот?


def test__check_tweet_sentiment__with_only_good_words():
text = 'This text with only good words'
good_words = ['good', 'best', 'perfect']
bad_words = ['bad', 'scary', 'terrible']
assert check_tweet_sentiment(text, good_words, bad_words) == 'GOOD'


def test__check_tweet_sentiment__with_only_bad_words():
text = 'This text with only bad words'
good_words = ['good', 'best', 'perfect']
bad_words = ['bad', 'scary', 'terrible']
assert check_tweet_sentiment(text, good_words, bad_words) == 'BAD'


def test__check_tweet_sentiment__with_equal_good_and_bad_words():
text = 'This text with good and bad words'
good_words = ['good', 'best', 'perfect']
bad_words = ['bad', 'scary', 'terrible']
assert check_tweet_sentiment(text, good_words, bad_words) == None


def test__check_tweet_sentiment__without_good_and_bad_words():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 во всех тестах этого модуля не хватает глагола в названии, описывающего поведение, описывается факт, что на входе, но не поведение

test__check_tweet_sentiment__return_none_when_no_good_and_bad_words_found

text = 'This text without needed words'
good_words = ['good', 'best', 'perfect']
bad_words = ['bad', 'scary', 'terrible']
assert check_tweet_sentiment(text, good_words, bad_words) == None
21 changes: 21 additions & 0 deletions tests/level_1_5/test_one_median.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from functions.level_1_5.one_median import get_median_value
import pytest


def test__get_median_value__with_empty_items():
assert get_median_value([]) == None


@pytest.mark.xfail
def test__get_median_value__with_even_len_of_items():
assert get_median_value([2, 1, 4, 3]) == 1


@pytest.mark.xfail(reason='Incorrect calculation')
def test__get_median_value__with_more_even_items():
assert get_median_value([2, 1, 4, 3, 5, 6]) == 3


@pytest.mark.xfail(reason='Incorrect calculation')
def test__get_median_value__with_odd_len_of_items():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 не хватает глагола, описывающего поведение

assert get_median_value([1, 3, 6, 8, 9]) == 6
20 changes: 20 additions & 0 deletions tests/level_1_5/test_three_first.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from functions.level_1_5.three_first import first
import pytest


def test__first__with_items():
assert first([5, 7, 1, 15]) == 5


def test__first__with_empty_items_and_default_is_not_set():
with pytest.raises(AttributeError):
first([])


def test__first__with_empty_items_and_default_is_none():
assert first([], None) == None


def test__first__with_empty_items_and_default_is_int():
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 есть то что на входе в названии, но не отражено поведение, что мы ожидаем увидеть

assert first([], 0) == 0

23 changes: 23 additions & 0 deletions tests/level_1_5/test_two_square_equation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from functions.level_1_5.two_square_equation import solve_square_equation
import pytest


def test__solve_square_equation__if_discriminant_is_negative():
assert solve_square_equation(1.0, 1.0, 1.0) == (None, None)


def test__solve_square_equation__if_discriminant_is_positive():
assert solve_square_equation(1.0, -3.0, 2.0) == (1.0, 2.0)


@pytest.mark.xfail
def test__solve_square_equation__if_discriminant_is_equal_to_zero():
assert solve_square_equation(1.0, -2.0, 1.0) == (1, None)


def test__solve_square_equation__if_square_coefficient_is_equal_to_zero():
assert solve_square_equation(0, 2.0, 1) == (-0.5, None)


def test__solve_square_equation__if_square_coefficient_and__linear_coefficients_are_equal_to_zero():
assert solve_square_equation(0, 0, 1) == (None, None)