A Test‑Driven Development (TDD) playground for Python.
Implementations of classic data structures and algorithms in Python with unit tests, complexity analysis, and practical examples.
python-data-structures-and-algorithms
│
├── common/
├── data_structures/
├── algorithms/
│ ├── sorting/
│ ├── searching/
│ ├── graph/
│ └── dynamic_programming/
│
├── tests/
├── benchmarks/
└── pyproject.toml
└── README.md
└── requirements.txt
src/contains production codetests/mirrors the same structure and contains all unit tests
- Python ≥ 3.x
- pip
- pytest – test runner
- coverage – code coverage
- pytest-cov – coverage integration for pytest
- pylint – static code analysis
Create and activate a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # Linux / macOS
venv\Scripts\activate # WindowsInstall dependencies:
pip install -r requirements.txtUpdate dependencies
python -m pip install -r requirements.txt --upgradeRun all tests:
pytestStop after the first failure:
pytest -xRun a single test file:
pytest tests/algorithms/strings/test_stringutil.pyRun test from a venv:
.\.venv\Scripts\python.exe -m pytestRun code coverage:
coverage run --source=src -m pytest
coverage reportGenerate an HTML report:
coverage htmlpytest-cov also reports files without tests:
pytest --cov=src tests/
pytest --cov=src tests/ --cov-report=htmlpytest --cov=your_package --cov-report=term-missing --cov-report=htmlRun pylint on source and tests (ignoring missing docstrings):
pylint src --disable=missing-docstring
pylint tests --disable=missing-docstringUpdate requirements.txt:
pip freeze > requirements.txt