diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index c45bcbfcc..69bad0e20 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -26,7 +26,8 @@ jobs: continue-on-error: true - name: Test with pytest run: | - coverage run -m pytest tests/tests_1b.py -v -s + coverage run -m pytest tests/tests_1b.py -v -s + coverage run -m pytest tests/tests_1c.py -v -s - name: Generate Coverage Report run: | coverage report -m \ No newline at end of file diff --git a/labs/lab_1/lab_1c.py b/labs/lab_1/lab_1c.py index 40cf98db3..5f1369e56 100644 --- a/labs/lab_1/lab_1c.py +++ b/labs/lab_1/lab_1c.py @@ -24,7 +24,7 @@ def max_subarray_sum(nums: list[int]) -> int: for num in nums: max_current = max(num, max_current + num) - if max_current < max_global: + if max_current > max_global: max_global = max_current return max_global diff --git a/tests/tests_1c.py b/tests/tests_1c.py new file mode 100644 index 000000000..306242ae7 --- /dev/null +++ b/tests/tests_1c.py @@ -0,0 +1,17 @@ +""" +tests_1b.py + +This module contains unit tests for the max_subarray_sum function defined in lab_1b.py. +""" + +import pytest +from labs.lab_1.lab_1c import max_subarray_sum + +def test(): + assert max_subarray_sum([-2,1,-3,4,-1,2,1,-5,4]) == 6 + assert max_subarray_sum([-2,1,-3,4,-1,2,3,-5,4]) == 8 + assert max_subarray_sum([-2,1,-3,1,-1,2,1,-5,4]) == 4 + + +if __name__ == "__main__": + pytest.main() \ No newline at end of file