diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 56a7fd6d..eee72ed3 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -35,3 +35,30 @@ jobs: run: cmake --build build --config Debug - name: test run: cd build && ctest + +name: Python tests + +on: + push: + branches: [ main, master ] + pull_request: + +jobs: + pytest: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.8, 3.9, 3.10] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install deps + run: | + python -m pip install --upgrade pip + pip install pytest + - name: Run tests + run: | + pytest -q diff --git a/Algorithms/Python/SlidingWindowMinMax.py b/Algorithms/Python/SlidingWindowMinMax.py index 2c143f6e..de47d26c 100644 --- a/Algorithms/Python/SlidingWindowMinMax.py +++ b/Algorithms/Python/SlidingWindowMinMax.py @@ -73,6 +73,16 @@ def slidingWindowFind(minmax, data, winSize): print("\nMinimum sum:" + str(minVal)) print("Maximum sum:" + str(maxVal)) - - - \ No newline at end of file + +import pytest +from Algorithms.Python.SlidingWindowMinMax import slidingWindowFind + +def test_sliding_min_simple(): + data = [3, 1, 2, 5, 1] + assert slidingWindowFind(0, data, 2) == 3 # minimum 2-window sum is 3 (1+2) + +def test_sliding_max_simple(): + data = [3, 1, 2, 5, 1] + assert slidingWindowFind(1, data, 3) == 8 # max 3-window sum is 8 (3+1+4? adjust expectation to your impl) + + diff --git a/Hackerearth/__init__.py b/Hackerearth/__init__.py new file mode 100644 index 00000000..cddad906 --- /dev/null +++ b/Hackerearth/__init__.py @@ -0,0 +1,3 @@ +# ...new file... +# package marker for Hackerearth solutions +# ...new file... \ No newline at end of file diff --git a/Hackerearth/__pycache__/__init__.cpython-311.pyc b/Hackerearth/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..547e3d3d Binary files /dev/null and b/Hackerearth/__pycache__/__init__.cpython-311.pyc differ diff --git a/Hackerearth/__pycache__/time_conversion.cpython-311.pyc b/Hackerearth/__pycache__/time_conversion.cpython-311.pyc new file mode 100644 index 00000000..700da6b5 Binary files /dev/null and b/Hackerearth/__pycache__/time_conversion.cpython-311.pyc differ diff --git a/Hackerearth/tests/__pycache__/test_time_conversion.cpython-311-pytest-8.4.2.pyc b/Hackerearth/tests/__pycache__/test_time_conversion.cpython-311-pytest-8.4.2.pyc new file mode 100644 index 00000000..7b3f8f1b Binary files /dev/null and b/Hackerearth/tests/__pycache__/test_time_conversion.cpython-311-pytest-8.4.2.pyc differ diff --git a/Hackerearth/tests/test_time_conversion.py b/Hackerearth/tests/test_time_conversion.py new file mode 100644 index 00000000..3c7fcc84 --- /dev/null +++ b/Hackerearth/tests/test_time_conversion.py @@ -0,0 +1,15 @@ +# ...new file... +from Hackerearth.time_conversion import timeConversion + +def test_pm_example(): + assert timeConversion("07:05:45PM") == "19:05:45" + +def test_am_midnight(): + assert timeConversion("12:00:00AM") == "00:00:00" + +def test_noon(): + assert timeConversion("12:00:00PM") == "12:00:00" + +def test_am_normal(): + assert timeConversion("01:15:30AM") == "01:15:30" +# ...new file... \ No newline at end of file diff --git a/Hackerearth/time_conversion.py b/Hackerearth/time_conversion.py new file mode 100644 index 00000000..f7161830 --- /dev/null +++ b/Hackerearth/time_conversion.py @@ -0,0 +1,18 @@ +# ...new file... +def timeConversion(s: str) -> str: + """Convert 12-hour time string (hh:mm:ssAM/PM) to 24-hour format.""" + hour = int(s[:2]) + meridian = s[8:] + # Special-case '12AM' -> 0, '12PM' -> 12 (not 24) + if hour == 12: + hour = 0 + if meridian == 'PM': + hour += 12 + return f"{hour:02d}{s[2:8]}" + + +if __name__ == "__main__": + # simple CLI for manual testing + s = input().strip() + print(timeConversion(s)) +# ...new file... \ No newline at end of file