Skip to content

Commit 7c05850

Browse files
committed
improve -Wrote the limit algorithm test with pytest.
1 parent 92691ed commit 7c05850

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.pyc
22
*.swp
33
.idea/
4+
.venv/

limit.py renamed to limit/limit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def limit_struct(array: list[int], min: int=None, max: int=None):
2121
result.append(val)
2222
elif (max) and val <= max:
2323
result.append(val)
24+
elif min is None:
25+
result = []
2426
else:
2527
result.append(min)
2628

@@ -35,3 +37,6 @@ def limit_python(array: list[int], min: int=None, max: int=None):
3537
min_check = lambda val: True if min is None else (val >= min)
3638
max_check = lambda val: True if max is None else (val <= max)
3739
return [val for val in array if min_check(val) and max_check(val)]
40+
41+
42+
print(limit_struct([]))

limit/test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import unittest
2+
import pytest
3+
from .limit import limit_struct
4+
5+
6+
class TestLimit:
7+
def test_limit_struct(self):
8+
assert limit_struct([1, 2, 3, 4, 5], min=3) == [3, 4, 5]
9+
assert limit_struct([1, 2, 3, 4, 5], max=3) == [1, 2, 3]
10+
assert limit_struct([1, 2, 3, 4, 5], min=3, max=3) == [3]
11+
assert limit_struct([]) == []

0 commit comments

Comments
 (0)