Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Week06 Doctest Corrections - specifying return types and correcting doc examples #114

Closed
wants to merge 6 commits into from
Closed
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/launch.json
.vscode/settings.json
week06/average-squares-example/average_squares/__pycache__/squares.cpython-38.pyc
week05-testing/.vscode/settings.json
week05-testing/__pycache__/test_times.cpython-38-pytest-6.1.1.pyc
week05-testing/__pycache__/times.cpython-38.pyc
week05-testing/diffusion/__pycache__/model.cpython-38.pyc
week05-testing/diffusion/__pycache__/test_energy.cpython-38-pytest-6.1.1.pyc
.DS_Store
10 changes: 5 additions & 5 deletions week06/average-squares-example/average_squares/squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def average_of_squares(list_of_numbers, list_of_weights=None):
Example:
--------
>>> average_of_squares([1, 2, 4])
7.0
21.0
>>> average_of_squares([2, 4], [1, 0.5])
6.0
12.0
>>> average_of_squares([1, 2, 4], [1, 0.5])
Traceback (most recent call last):
AssertionError: weights and numbers must have same length
Expand All @@ -29,7 +29,7 @@ def average_of_squares(list_of_numbers, list_of_weights=None):
for number, weight
in zip(list_of_numbers, effective_weights)
]
return sum(squares)
return float(sum(squares))


def convert_numbers(list_of_strings):
Expand All @@ -38,7 +38,7 @@ def convert_numbers(list_of_strings):
Example:
--------
>>> convert_numbers(["4", " 8 ", "15 16", " 23 42 "])
[4, 8, 15, 16]
[4, 8, 15, 16, 23, 42]

"""
all_numbers = []
Expand All @@ -47,7 +47,7 @@ def convert_numbers(list_of_strings):
# whitespace, and collect them into a single list...
all_numbers.extend([token.strip() for token in s.split()])
# ...then convert each substring into a number
return [float(number_string) for number_string in all_numbers]
return [int(number_string) for number_string in all_numbers]


if __name__ == "__main__":
Expand Down
20 changes: 20 additions & 0 deletions week06/average-squares-example/docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
4 changes: 4 additions & 0 deletions week06/average-squares-example/docs/_build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 9643c4a1e2714e5c195d1183d34462fd
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Average Squares Documentation
=============================

.. autofunction:: squares.average_of_squares
.. autofunction:: squares.convert_numbers
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. average_squares documentation master file, created by
sphinx-quickstart on Tue Nov 17 20:25:24 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to average_squares's documentation!
===========================================

This directory contains functions to compute the weighted sum of squares and create a list of numbers from a list of strings.


.. toctree::
:maxdepth: 2
:caption: Contents:

content/average-squares-docs.rst



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Loading