Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 13 additions & 3 deletions Algorithms/Python/SlidingWindowMinMax.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def slidingWindowFind(minmax, data, winSize):

print("\nMinimum sum:" + str(minVal))
print("Maximum sum:" + str(maxVal))




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)


3 changes: 3 additions & 0 deletions Hackerearth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ...new file...
# package marker for Hackerearth solutions
# ...new file...
Binary file added Hackerearth/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions Hackerearth/tests/test_time_conversion.py
Original file line number Diff line number Diff line change
@@ -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...
18 changes: 18 additions & 0 deletions Hackerearth/time_conversion.py
Original file line number Diff line number Diff line change
@@ -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...