Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
e02_list_test.py 6.69 KB
Copy Edit Raw Blame History
高强 authored 2022-04-20 17:00 . First draft finished
import pytest
import e02_list_quiz as q
@pytest.mark.parametrize(
"lst, res",
[
[[2, 3, -1, 5, 0, 4], [4, 9, 25, 16]],
[[1, -1, 2, -2, 3, -3], [1, 4, 9]],
[[-2, -3, -1], []],
],
)
def test_001(lst, res):
assert q.f001(lst) == res
@pytest.mark.parametrize(
"lst, res",
[
[["/home", "/home/qiang", "/etc"], 4],
[["https://www.cueb.edu.cn", "www.baidu.com"], 2],
[["pystudy", "exercise"], 0],
],
)
def test_002(lst, res):
assert q.f002(lst) == res
@pytest.mark.parametrize(
"n, output",
[
[3, "L\nLL\nLLL"],
[5, "L\nLL\nLLL\nLLLL\nLLLLL"],
],
)
def test_003(n, output, capsys):
q.f003(n)
out, err = capsys.readouterr()
assert out == output + "\n"
@pytest.mark.parametrize(
"lst, item, expected",
[
[[3, 1, 2], 0, [3, 1, 2, 0]],
[["d", "f", "b"], "a", ["d", "f", "b", "a"]],
],
)
def test_004(lst, item, expected):
res = q.f004(lst, item)
assert res is None
assert lst == expected
@pytest.mark.parametrize(
"lst, item, expected",
[
[[3, 1, 2], 0, [3, 1, 2, 0]],
[["d", "f", "b"], "a", ["d", "f", "b", "a"]],
],
)
def test_005(lst, item, expected):
lst_bak = lst.copy()
res = q.f005(lst, item)
assert lst == lst_bak
assert res is not lst
assert res == expected
@pytest.mark.parametrize(
"lst, args, expected",
[
[[3, 1, 2], (5, 0), [3, 1, 2, 5, 0]],
[["d", "f", "b"], ("a", "h", "c"), ["d", "f", "b", "a", "h", "c"]],
],
)
def test_006(lst, args, expected):
res = q.f006(lst, *args)
assert res is None
assert lst == expected
@pytest.mark.parametrize(
"lst, item, expected",
[
[[3, 1, 2], 0, [3, 1, 2, 0]],
[["d", "f", "b"], "a", ["d", "f", "b", "a"]],
],
)
def test_007(lst, item, expected):
lst_bak = lst.copy()
res = q.f007(lst, item)
assert lst == lst_bak
assert res is not lst
assert res == expected
@pytest.mark.parametrize(
"lst, n, expected",
[
[[3, 1, 2, 5, 6], 2, [2, 5, 6]],
[["d", "f", "b", "a", "h", "c"], 4, ["h", "c"]],
],
)
def test_008(lst, n, expected):
lst_bak = lst.copy()
res = q.f008(lst, n)
assert lst == lst_bak
assert res is not lst
assert res == expected
@pytest.mark.parametrize(
"lst, n, expected",
[
[[3, 1, 2, 5, 6], 2, [3, 1, 5, 6]],
[["d", "f", "b", "a", "h", "c"], 1, ["d", "c"]],
],
)
def test_009(lst, n, expected):
lst_bak = lst.copy()
res = q.f009(lst, n)
assert lst == lst_bak
assert res is not lst
assert res == expected
@pytest.mark.parametrize(
"lst, n, expected",
[
[[3, 1, 2, 5, 6], 2, [3, 1, 2]],
[["d", "f", "b", "a", "h", "c"], 3, ["d", "f", "b"]],
],
)
def test_010(lst, n, expected):
res = q.f010(lst, n)
assert res is None
assert lst == expected
@pytest.mark.parametrize(
"lst, expected",
[
[[3, None, 2, 5, 6], [3, 2, 5, 6, None]],
[[None, "f", "b", "a", None, "c"], ["f", "b", "a", "c", None, None]],
],
)
def test_011(lst, expected):
lst_bak = lst.copy()
res = q.f011(lst)
assert lst == lst_bak
assert res is not lst
assert res == expected
@pytest.mark.parametrize(
"lst, expected",
[
[[3, None, 2, 5, 6], [3, 2, 5, 6, None]],
[[None, "f", "b", "a", None, "c"], ["f", "b", "a", "c", None, None]],
],
)
def test_012(lst, expected):
res = q.f012(lst)
assert res is None
assert lst == expected
@pytest.mark.parametrize(
"hosts, ports, expected",
[
[
["www.cueb.edu.cn", "www.baidu.com", "www.google.com"],
[80, 443, 22],
["www.cueb.edu.cn:80", "www.baidu.com:443", "www.google.com:22"],
]
],
)
def test_013(hosts, ports, expected):
assert q.f013(hosts, ports) == expected
@pytest.mark.parametrize(
"lst, expected",
[
[[3, 1, 2], [2, 1, 3]],
[["d", "f", "b"], ["b", "f", "d"]],
],
)
def test_014(lst, expected):
res = q.f014(lst)
assert res is None
assert lst == expected
@pytest.mark.parametrize(
"lst, expected",
[[[3, 1, 2], [2, 1, 3]], [["d", "f", "b"], ["b", "f", "d"]]],
)
def test_015(lst, expected):
lst_bak = lst.copy()
res = q.f015(lst)
assert list(res) == expected
assert lst == lst_bak
@pytest.mark.parametrize(
"lst, expected",
[
[[3, 1, 2], [1, 2, 3]],
[["d", "f", "b"], ["b", "d", "f"]],
],
)
def test_016(lst, expected):
res = q.f016(lst)
assert res is None
assert lst == expected
@pytest.mark.parametrize(
"lst, expected",
[[[3, 1, 2], [1, 2, 3]], [["d", "f", "b"], ["b", "d", "f"]]],
)
def test_017(lst, expected):
lst_bak = lst.copy()
res = q.f017(lst)
assert list(res) == expected
assert lst == lst_bak
@pytest.mark.parametrize(
"lst, expected",
[[[3, 1, -2], [1, -2, 3]], [[4, 1, -3, 2], [1, 2, -3, 4]]],
)
def test_018(lst, expected):
lst_bak = lst.copy()
res = q.f018(lst)
assert list(res) == expected
assert lst == lst_bak
@pytest.mark.parametrize(
"lst, expected",
[
[[(4, 3), (5, 1), (3, 1)], [(4, 3), (3, 1), (5, 1)]],
[[(4, -3), (5, 5), (1, 2), (3, 1)], [(1, 2), (5, 5), (3, 1), (4, -3)]],
],
)
def test_019(lst, expected):
lst_bak = lst.copy()
res = q.f019(lst)
assert list(res) == expected
assert lst == lst_bak
@pytest.mark.parametrize(
"lst, order, expected",
[
[
["良好", "不及格", "优秀", "良好"],
["优秀", "良好", "及格", "不及格"],
["优秀", "良好", "良好", "不及格"],
],
[
["Tue", "Fri", "Tue", "Fri", "Mon"],
["Mon", "Tue", "Wen", "Thu", "Fri", "Sat", "Sun"],
["Mon", "Tue", "Tue", "Fri", "Fri"],
],
],
)
def test_020(lst, order, expected):
lst_bak = lst.copy()
res = q.f020(lst, order)
assert list(res) == expected
assert lst == lst_bak
@pytest.mark.parametrize(
"lst, expected",
[
[
[
["aaa", "bbb", "ccc"],
[3.112, 4.721, 1.874],
],
[
["aaa", 3.112],
["bbb", 4.721],
["ccc", 1.874],
],
],
[
[
["ddd", "eee"],
[8.764, 4.329],
[0.926, 3.927],
[5.551, 7.452],
],
[
["ddd", 8.764, 0.926, 5.551],
["eee", 4.329, 3.927, 7.452],
],
],
],
)
def test_021(lst, expected):
lst_bak = lst.copy()
res = q.f021(lst)
assert list(res) == expected
assert lst == lst_bak
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化