Skip to content

Commit 7f84cad

Browse files
committed
deploy: 0a3cfa9
1 parent dc44b93 commit 7f84cad

6 files changed

Lines changed: 123 additions & 3 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"""
2+
3+
Test driven development:
4+
5+
6+
Example from Coding Bat: List-2 > sum13
7+
8+
https://codingbat.com/prob/p167025
9+
10+
Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count.
11+
12+
13+
sum13([1, 2, 2, 1]) → 6
14+
sum13([1, 1]) → 2
15+
sum13([1, 2, 2, 1, 13]) → 6
16+
sum13([1, 2, 2, 1]) → 6
17+
sum13([1, 1]) → 2
18+
sum13([1, 2, 2, 1, 13]) → 6
19+
sum13([1, 2, 13, 2, 1, 13]) → 4
20+
sum13([13, 1, 2, 13, 2, 1, 13]) → 3
21+
sum13([]) → 0
22+
sum13([13]) → 0
23+
sum13([13, 13]) → 0
24+
sum13([13, 0, 13]) → 0
25+
sum13([13, 1, 13]) → 0
26+
sum13([5, 7, 2]) → 14
27+
sum13([5, 13, 2]) → 5
28+
sum13([0]) → 0
29+
sum13([13, 0]) → 0
30+
"""
31+
32+
import pytest
33+
34+
def sum13(nums):
35+
"""
36+
non-functional -- but the tests will run (and fail)
37+
"""
38+
return None
39+
40+
# def sum13(nums):
41+
# """
42+
# simple sum -- no special handling of 13 -- should pass some tests.
43+
# """
44+
# return sum(nums)
45+
46+
# def sum13(nums):
47+
# """
48+
# using a comprehension to filter out the 13s
49+
50+
# - more tests should pass, but not all.
51+
# """
52+
# return sum(n for n in nums if n!=13)
53+
54+
55+
# def sum13(nums):
56+
# """
57+
# darn -- comprehension can't handle the "after a 13" case
58+
59+
# do it from scratch with while loop
60+
61+
# fails the two 13s in a row test!
62+
# """
63+
# total = 0
64+
# i = 0
65+
# while i < len(nums):
66+
# if nums[i] != 13:
67+
# total += nums[i]
68+
# else:
69+
# i += 1
70+
# i += 1
71+
# return total
72+
73+
74+
# def sum13(nums):
75+
# """
76+
# Use a for loop, and keep track of the previous 13
77+
78+
# passes all tests!
79+
# """
80+
# print(nums)
81+
# total = 0
82+
# prev_13 = False
83+
# for i, n in enumerate(nums):
84+
# if n == 13:
85+
# prev_13 = True
86+
# continue
87+
# elif prev_13:
88+
# prev_13 = False
89+
# continue
90+
# else:
91+
# total += n
92+
# return total
93+
94+
95+
# def sum13(nums):
96+
# """
97+
# Use the iterator protocol -- nifty? but not any simpler really.
98+
99+
# Fails for repeated 13 in middle
100+
101+
# Works with any iterable, so that's nice.
102+
# """
103+
# total = 0
104+
# nums_i = iter(nums)
105+
# for n in nums_i:
106+
# if n != 13:
107+
# total += n
108+
# else:
109+
# try:
110+
# next(nums_i)
111+
# # this is necessary for the case where there's a 13 at the end.
112+
# except StopIteration:
113+
# break
114+
# return total

_sources/exercises/unit_testing/unit_testing.rst.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ Another Example:
9797

9898
Here's another example from the codingbat site:
9999

100+
:download:`sum_13.py <sum_13.py>`
101+
102+
and
103+
100104
:download:`test_sum_13.py <test_sum_13.py>`
101105

102106

_sources/index.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Programming in Python
99

1010
This site holds a set of materials for an introductory course in Python.
1111

12-
THe course was originally developed by a wide variety of instructors for the
12+
The course was originally developed by a wide variety of instructors for the
1313
`University of Washington Professional and Continuing Education Python Certificate <https://www.pce.uw.edu/certificates/python-programming>`_
1414
`Introductory class <https://www.pce.uw.edu/courses/programming-in-python>`_
1515

exercises/unit_testing/unit_testing.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ <h2>Making tests pass<a class="headerlink" href="#making-tests-pass" title="Link
161161
<section id="another-example">
162162
<h2>Another Example:<a class="headerlink" href="#another-example" title="Link to this heading"></a></h2>
163163
<p>Here’s another example from the codingbat site:</p>
164+
<p><a class="reference download internal" download="" href="../../_downloads/cf0e3abf3a3e6d68c80290cc35c03eee/sum_13.py"><code class="xref download docutils literal notranslate"><span class="pre">sum_13.py</span></code></a></p>
165+
<p>and</p>
164166
<p><a class="reference download internal" download="" href="../../_downloads/ee444efb16b7b47ca2fe80eaf6107a91/test_sum_13.py"><code class="xref download docutils literal notranslate"><span class="pre">test_sum_13.py</span></code></a></p>
165167
</section>
166168
<section id="doing-your-own">

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<section id="programming-in-python">
9494
<h1>Programming in Python<a class="headerlink" href="#programming-in-python" title="Link to this heading"></a></h1>
9595
<p>This site holds a set of materials for an introductory course in Python.</p>
96-
<p>THe course was originally developed by a wide variety of instructors for the
96+
<p>The course was originally developed by a wide variety of instructors for the
9797
<a class="reference external" href="https://www.pce.uw.edu/certificates/python-programming">University of Washington Professional and Continuing Education Python Certificate</a>
9898
<a class="reference external" href="https://www.pce.uw.edu/courses/programming-in-python">Introductory class</a></p>
9999
<p>This site can be thought of as the textbook for an introduction to programming in Python:

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)