diff --git a/tests/level_1_5/test_five_replace_word.py b/tests/level_1_5/test_five_replace_word.py new file mode 100644 index 00000000..b0d32bcc --- /dev/null +++ b/tests/level_1_5/test_five_replace_word.py @@ -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' + + +def test__replace_word__if_replace_word_not_find_in_text(): + assert replace_word('the big black car', 'red', 'small') == 'the big black car' + diff --git a/tests/level_1_5/test_four_sentiment.py b/tests/level_1_5/test_four_sentiment.py new file mode 100644 index 00000000..10618f19 --- /dev/null +++ b/tests/level_1_5/test_four_sentiment.py @@ -0,0 +1,28 @@ +from functions.level_1_5.four_sentiment import check_tweet_sentiment + +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(): + 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 \ No newline at end of file diff --git a/tests/level_1_5/test_one_median.py b/tests/level_1_5/test_one_median.py new file mode 100644 index 00000000..184549f2 --- /dev/null +++ b/tests/level_1_5/test_one_median.py @@ -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(): + assert get_median_value([1, 3, 6, 8, 9]) == 6 diff --git a/tests/level_1_5/test_three_first.py b/tests/level_1_5/test_three_first.py new file mode 100644 index 00000000..4b238b3f --- /dev/null +++ b/tests/level_1_5/test_three_first.py @@ -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(): + assert first([], 0) == 0 + diff --git a/tests/level_1_5/test_two_square_equation.py b/tests/level_1_5/test_two_square_equation.py new file mode 100644 index 00000000..853782ef --- /dev/null +++ b/tests/level_1_5/test_two_square_equation.py @@ -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) \ No newline at end of file