-
Notifications
You must be signed in to change notification settings - Fork 55
Level 1.5 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Level 1.5 #9
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| env | ||
| **/__pycache__/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,7 @@ | |
|
|
||
|
|
||
| def test_change_copy_item(): | ||
| pass | ||
| assert change_copy_item('Banana') == 'Copy of Banana' | ||
| assert change_copy_item('Copy of Banana') == 'Copy of Banana (2)' | ||
| assert change_copy_item('Copy of Banana (7)') == 'Copy of Banana (8)' | ||
| assert change_copy_item('Banana', 5) == 'Banana' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Почему-то в одном тесте собраны четыре разные теста. Разделить бы.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Актуально для почти всех тестов ниже |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,25 @@ | ||
| import datetime | ||
| import decimal | ||
|
|
||
| from functions.level_1.four_bank_parser import BankCard, SmsMessage, Expense, parse_ineco_expense | ||
|
|
||
|
|
||
| def test_parse_ineco_expense(): | ||
| pass | ||
| sms = SmsMessage( | ||
| text="Вы купили 0.23 Эфира, *1234 18.05.23 23:59 MEWWALLET authcode 5005", | ||
| author="MewWallet", | ||
| sent_at=datetime.datetime.now(), | ||
| ) | ||
|
|
||
| cards = [ | ||
| BankCard("1234", "Pavel Mager"), | ||
| BankCard("5678", "Pavel Mager"), | ||
| ] | ||
|
|
||
| expected_output = Expense( | ||
| amount=decimal.Decimal("0.23"), | ||
| card=cards[0], | ||
| spent_in="MEWWALLET", | ||
| spent_at=datetime.datetime.strptime("18.05.23 23:59", "%d.%m.%y %H:%M"), | ||
| ) | ||
| assert parse_ineco_expense(sms, cards) == expected_output | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Разбить бы по AAA |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| from functions.level_1.two_date_parser import compose_datetime_from | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| def test_compose_datetime_from(): | ||
| pass | ||
| date = compose_datetime_from('Bla-bla', '11:15') | ||
| today = datetime.today() | ||
| assert date == datetime(today.year, today.month, today.day, int(date.hour), int(date.minute)) | ||
| date = compose_datetime_from('tomorrow', '13:40') | ||
| assert date == datetime(today.year, today.month, today.day + 1, int(date.hour), int(date.minute)) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from functions.level_1_5.five_replace_word import replace_word | ||
|
|
||
|
|
||
| def test__replace_word__with_replaces(): | ||
| text = 'I have the power that my father never dreamed of! NEVER !!!' | ||
| replace_from = 'never' | ||
| replace_to = 'always' | ||
| exp_output = 'I have the power that my father always dreamed of! always !!!' | ||
| assert replace_word(text, replace_from, replace_to) == exp_output | ||
|
|
||
| def test__replace_word__without_replaces(): | ||
| text = 'I have the power that my father never dreamed of! NEVER !!!' | ||
| replace_from = 'Sponge' | ||
| replace_to = 'Bob' | ||
| assert replace_word(text, replace_from, replace_to) == text |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from functions.level_1_5.four_sentiment import check_tweet_sentiment | ||
|
|
||
|
|
||
| def test__check_tweet_sentiment__without_any_bad_or_good_words(): | ||
| text = "This is an ordinary text, without any emotional expressions." | ||
| good_words = set() | ||
| bad_words = set() | ||
| assert check_tweet_sentiment(text, good_words, bad_words) == None | ||
|
|
||
| def test__check_tweet_sentiment__with_the_same_number_of_words(): | ||
| text = "Very good, so good, it'so good, Jesus! But I hate it! It's disgusting! I hate it! I FUCKING HATE IT YOU HEAR ME?" | ||
| good_words = {'good,', 'jesus!'} | ||
| bad_words = {'hate', 'fucking'} | ||
| assert check_tweet_sentiment(text, good_words, bad_words) == None | ||
|
|
||
| def test__check_tweet_sentiment__normal_expecting_BAD_response(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Капс в названиях тестов лучше не использовать |
||
| text = "You motherfucker, come on, you little ass… fuck with me, eh?! You fucking little asshole, dickhead, cocksucker… You fuckin’ — come on, come fuck with me! I’ll get your ass, you jerk! Oh, you fuckhead, motherfucker! Fuck all you and your family! Come on, you cocksucker, slime bucket, shitface, turdball! Come on, you scum sucker, you fucking with me?! Come on, you asshole!" | ||
| good_words = {'family!', 'handsome', 'smart'} | ||
| bad_words = {'fuck', 'fucking', 'ass...'} | ||
| assert check_tweet_sentiment(text, good_words, bad_words) == 'BAD' | ||
|
|
||
| def test__check_tweet_sentiment__normal_expecting_GOOD_response(): | ||
| text = "I love this place! it's perfect to suicide for sure. i love it!" | ||
| good_words = {'love'} | ||
| bad_words = {'suicide'} | ||
| assert check_tweet_sentiment(text, good_words, bad_words) == 'GOOD' | ||
| 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 | ||
|
|
||
|
|
||
| """Хотелось бы сразу заметить, что функция и нормальные тесты невозможны""" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Во-первых, комментарий в формате докстринги принято ставить сразу после дефа. Этот комментарий нужно писать с помощью решётки. Сейчас это строковой литерал. Во-вторых, в этом комментарии пропущено слово и можно на изи неправильно его понять. Ну и в-третьих очень даже возможно написать нормальные тесты на функцию с багом. |
||
| def test__get_median_value__empty_list(): | ||
| assert get_median_value([]) is None | ||
|
|
||
| def test__get_median_value__list_with_odd_numbers_elem(): | ||
| assert get_median_value([3, 7, 4]) == 4 | ||
|
|
||
| def test__get_median_value__list_with_even_numbers_elem(): | ||
| with pytest.raises(IndexError): | ||
| get_median_value([1, 3, 5, 7]) | ||
|
|
||
| def test__get_median_value__list_with_1_elem(): | ||
| with pytest.raises(IndexError): | ||
| get_median_value([1]) | ||
|
|
||
| def test__get_median_value__list_with_negative_numb(): | ||
| assert get_median_value([-5, -10, -1, -6, -8]) == -6 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from functions.level_1_5.three_first import first | ||
| import pytest | ||
|
|
||
| def test__first__list_of_numbers(): | ||
| assert first([1, 2, 3, 4, 5]) == 1 | ||
|
|
||
| def test__first__list_of_numbers_with_default_value(): | ||
| assert first([1, 2, 3, 4, 5], 10) == 1 | ||
|
|
||
| def test__first__empty_list_with_default_value(): | ||
| assert first([], 'There is no numbers') == 'There is no numbers' | ||
|
|
||
| def test__first__empty_list_without_default_value(): | ||
| with pytest.raises(AttributeError): | ||
| first([]) | ||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут я бы ещё кейсов поискал |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from functions.level_1_5.two_square_equation import solve_square_equation | ||
|
|
||
|
|
||
| def test__solve_square_equation__no_roots(): | ||
| assert solve_square_equation(1.0, 0.0, 1.0) == (None, None) | ||
|
|
||
| def test__solve_square_equation__one_root(): | ||
| assert solve_square_equation(1, -2, 1) == (1.0, 1.0) | ||
|
|
||
| def test__solve_square_equation__two_roots(): | ||
| assert solve_square_equation(1, -3, 2) == (1.0, 2.0) | ||
|
|
||
| def test__solve_square_equation__linear(): | ||
| assert solve_square_equation(0, 2, -1) == (0.5, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут и дальше название тестов так себе