From eb72dbacc758fa1e098558d7f83bfb2e9a1e839f Mon Sep 17 00:00:00 2001 From: Nick_Zur Date: Tue, 13 Sep 2022 16:41:00 +0300 Subject: [PATCH] Added tests --- main.py | 15 +-------------- tests/test_list.py | 24 ++++++++++++++++++++++++ tests/test_set.py | 23 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 tests/test_list.py create mode 100644 tests/test_set.py diff --git a/main.py b/main.py index 5596b44..86cf704 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,3 @@ -# This is a sample Python script. - -# Press Shift+F10 to execute it or replace it with your code. -# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. - def print_hi(name): - # Use a breakpoint in the code line below to debug your script. - print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. - - -# Press the green button in the gutter to run the script. -if __name__ == '__main__': - print_hi('PyCharm') - -# See PyCharm help at https://www.jetbrains.com/help/pycharm/ + print("Hello_World") diff --git a/tests/test_list.py b/tests/test_list.py new file mode 100644 index 0000000..232facd --- /dev/null +++ b/tests/test_list.py @@ -0,0 +1,24 @@ +import pytest + + +def test_list_len(): + list = [1, 2, 3, 4] + assert len(list) == 4 + + +@pytest.mark.parametrize("test_data, expected_result", [([0, 1, 2, 3, 4], [0, 1, 2, 3, 4]), # отсортированные положит числа + ([4, 3, 2, 1, 0], [0, 1, 2, 3, 4]), # неотсортированные положит числа + ([-4, -3, -2, -1, 0], [-4, -3, -2, -1, 0]), # отсортированные негатив числа + ([-3, -4, -1, -2, 0], [-4, -3, -2, -1, 0]), # неотсортированные негатив числа + ([-4, 5, 1, 1, 0], [-4, 0, 1, 1, 5])]) # неотсортированные негатив и позитив числа +def test_list_sort(test_data, expected_result): + list = test_data + list.sort() + assert list == expected_result + +def test_list_remove(): + list = [1,2,3] + try: + assert list.remove(4) + except ValueError: + pass diff --git a/tests/test_set.py b/tests/test_set.py new file mode 100644 index 0000000..6e0a131 --- /dev/null +++ b/tests/test_set.py @@ -0,0 +1,23 @@ +import pytest + + +def test_set_add_new_element(): + a = {1, 2, 2, 3, 0} + assert 3 in a + + +@pytest.mark.parametrize("test_data1, test_data2, expected_result", [({1, 2, 2, 4}, {5, 6, 1, 0}, {1}), #входит один элемент + ({1, 2, 2, 4}, {5, 6, 6, 0}, set()), #ни один не входит + ({1, 2, 2, 3, 4}, {1, 2, 6, 7, 3}, {1, 2, 3}), #входят несколько элементов + ]) +def test_set_intersection(test_data1, test_data2, expected_result): + a = test_data1 + b = test_data2 + assert a.intersection(b) == expected_result + + +def test_set_from_list(): + try: + assert set([[1, 2], [2, 3], [1, 2], [2, 5]]) + except TypeError: + pass