-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Labels
preparationExercises to do before the classExercises to do before the classweek06Documenting projects and findging bugsDocumenting projects and findging bugs
Description
This exercise will show why it is important to keep documentation accurate, and how to do this automatically using docstrings and doctests.
Setup
- Make sure you've had a look at the course notes on documentation so that you understand some of the background around docstrings and doctests
- Fork and clone the
average_squaresrepository. (git clone git@github.com:<your_user_name>/average_squares.git) - Open the
squares.pyfile
Understanding
- Spend some time reading and understanding the code.
- Do you understand what it's meant to do? Do the docstrings help?
- Run the code with the default inputs. Does it produce the output you expect?
- Try running the code with other inputs. What happens?
Exercises
As you may have discovered, the code in squares.py does contain some mistakes. Thankfully the functions in the file include documentation that explains how they should behave.
Run the doctests
- Use the
doctestmodule to see whether the documentation of the code is accurate:python -m doctest squares.py - Try to understand the structure of the output - what errors are reported, are they what you expected from looking at the code in the previous steps?
Update the docstrings
- Look at the errors related to the
average_of_squaresfunction.- Figure out where the mismatch between the documentation (intended behaviour) and the actual behaviour of the function exists.
- Correct usage examples in the
average_of_squaresfunction that are incorrect
Correct the code and verify
- Re-run the code; again comparing the actual and expected behaviour. What is the error?
- Correct the error in the code and rerun
doctestto confirm that theaverage_of_squaresdocumentation is now correct
Repeat the process for convert_numbers
- Look at the
doctesterror from theconvert_numbersdocumentation. - Can you identify the bug? How would you fix this?
Submit a Pull Request
Once you have completed or made progress on the exercises
- Create a pull request (PR) from your branch to the upstream repository. Add a meaningful title to that PR and a link to this issue:
Answers UCL-COMP0233-22-23/RSE-Classwork#30
Sample Solution: UCL-COMP0233-2022-2023/average_squares#19
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
preparationExercises to do before the classExercises to do before the classweek06Documenting projects and findging bugsDocumenting projects and findging bugs