diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index 69bad0e20..595c54aad 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -1,4 +1,4 @@ -name: simple_calculator unit test +name: simple_calculator, max_subarray_sum, and two_sum unit test on: [push] @@ -28,6 +28,7 @@ jobs: run: | coverage run -m pytest tests/tests_1b.py -v -s coverage run -m pytest tests/tests_1c.py -v -s + coverage run -m pytest tests/tests_1d.py -v -s - name: Generate Coverage Report run: | coverage report -m \ No newline at end of file diff --git a/labs/lab_1/lab_1d.py b/labs/lab_1/lab_1d.py index ade4b4a8c..1506810a6 100644 --- a/labs/lab_1/lab_1d.py +++ b/labs/lab_1/lab_1d.py @@ -23,7 +23,7 @@ def two_sum(nums: list[int], target: int) -> list[int]: num_to_index = {} for index, num in enumerate(nums): - complement = target + num + complement = target - num if complement in num_to_index: return [num_to_index[complement], index] num_to_index[num] = index diff --git a/tests/tests_1c.py b/tests/tests_1c.py index 306242ae7..f6a08f6d7 100644 --- a/tests/tests_1c.py +++ b/tests/tests_1c.py @@ -1,7 +1,7 @@ """ -tests_1b.py +tests_1c.py -This module contains unit tests for the max_subarray_sum function defined in lab_1b.py. +This module contains unit tests for the max_subarray_sum function defined in lab_1c.py. """ import pytest diff --git a/tests/tests_1d.py b/tests/tests_1d.py new file mode 100644 index 000000000..73c5b8c86 --- /dev/null +++ b/tests/tests_1d.py @@ -0,0 +1,17 @@ +""" +tests_1d.py + +This module contains unit tests for the two_sum function defined in lab_1d.py. +""" + +import pytest +from labs.lab_1.lab_1d import two_sum + +def test(): + assert two_sum([2, 7, 11, 15], 18) == [1, 2] + assert two_sum([2, 7, 11, 15], 26) == [2, 3] + assert two_sum([2, 7, 11, 15], 22) == [1, 3] + + +if __name__ == "__main__": + pytest.main() \ No newline at end of file