Repository navigation
Description
Student: Raj Manoj Patil
Task: R23-T034 · 4 of 10
Repository: https://github.com/S-AI-Projects/TheAlgorithms-Python
Assigned working branch: student/e26b07f0759
Goal
Use Hypothesis to test the code against a trusted reference or a mathematical property over thousands of random inputs. Metric properties: d(a,a)=0, d(a,b)=d(b,a), d(a,c) ≤ d(a,b)+d(b,c), and |len(a)-len(b)| ≤ d(a,b) ≤ max(len(a),len(b)).
Steps
- Write test_edit_distance_properties.py in work/R23-T034/ using
hypothesisstrategies. - Implement the property/reference checks described in the goal.
- Run it; if Hypothesis finds a failing input, reduce it to a minimal example and either fix the code (with a doctest) or document the limitation.
- Explain each property in PROPERTIES.md.
- Make the code change in the repository: strings/edit_distance.py: doctests for metric properties (symmetry, identical strings, empty strings) and validation for non-string input. Re-run the automated check and the repo's own tests afterwards.
- Prepare the PR: on branch R23-T034, commit the code change plus your work/R23-T034/ evidence, put your findings in the PR description and open the PR against the org fork. For a later upstream PR, create a second branch containing only the code change (no work/ folder).
Done when
☐ Property tests: d(a,a)=0, d(a,b)=d(b,a), the triangle inequality, and |len(a)−len(b)| ≤ d(a,b) ≤ max(len(a),len(b)), each over ≥1,000 examples.
☐ strings/edit_distance.py gains doctests for empty strings and symmetry and a TypeError for non-strings.
☐ Existing 8 doctests pass (strings/edit_distance.py).
Additional task guidance
Additional curated task guidance
Item:
strings/edit_distance.py (46 lines; 8 doctests)
Task type:
Property-based testing
Code change (goes into the PR):
strings/edit_distance.py: doctests for metric properties (symmetry, identical strings, empty strings) and validation for non-string input.
Automated check:
uv run --with hypothesis pytest work/R23-T034/
Prerequisites:
Linux/WSL2/Codespaces with uv (https://docs.astral.sh/uv/getting-started/installation/); run uv sync --group=test once – it installs the Python version CI uses (.python-version = 3.15t) and the test dependencies, about 1–2 GB
Upstream PR rules:
Follow CONTRIBUTING.md: type hints on every parameter/return, doctests for valid and erroneous input, snake_case file names, no duplicate of an existing implementation, no hand edits to DIRECTORY.md. CI (pytest with doctests, ruff) must pass – bots close PRs without tests or type hints. Keep work/ (benchmarks, notes, property tests) out of the upstream branch; put results in the PR description.
Source (pinned):
https://github.com/TheAlgorithms/Python/blob/574d100b7181956e9c8384552fd078165e4cc326/strings/edit_distance.py
Change:
No change recorded
PR destination:
Preserved pilot guidance
Submission checklist
- Complete this task and its checks.
- Add the required evidence and link your pull request here.
- Select this S-AI-Projects fork as the PR base repository.
- Request instructor review.
Keep this PR focused on this task. Do not submit assignment PRs to the upstream repository.
Activity