Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using docstrings and doctests #30

Open
dpshelio opened this issue Nov 3, 2022 · 3 comments
Open

Using docstrings and doctests #30

dpshelio opened this issue Nov 3, 2022 · 3 comments
Labels
preparation Exercises to do before the class week06 Documenting projects and findging bugs

Comments

@dpshelio
Copy link
Contributor

dpshelio commented Nov 3, 2022

This exercise will show why it is important to keep documentation accurate, and how to do this automatically using docstrings and doctests.

Setup

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 doctest module 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_squares function.
    • 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_squares function 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 doctest to confirm that the average_of_squares documentation is now correct

Repeat the process for convert_numbers

  • Look at the doctest error from the convert_numbers documentation.
  • 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

@dpshelio dpshelio added week06 Documenting projects and findging bugs preparation Exercises to do before the class labels Nov 3, 2022
@anda-raluca
Copy link

@wenzhaojia2000
Copy link

Should be #30 not UCL-COMP0233-21-22/RSE-Classwork#30

@JingyaoLIz
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preparation Exercises to do before the class week06 Documenting projects and findging bugs
Projects
None yet
Development

No branches or pull requests

4 participants