Skip to content

Commit 03348c7

Browse files
committed
fixed a couple typos.
1 parent 5226456 commit 03348c7

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

source/exercises/mailroom/mailroom_with_tests.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Guidelines
1919

2020
Here are some suggestions on what should be refactored in your mailroom code.
2121

22-
As mentioned above, testing user interaction code (code with ``print`` and ``input`` functions) is harder than testing the rest of your code. Testing user interaction code requires more advanced unit testing methodologies that will be revisited in future courses. Therefore, you should refactor your code so that the user interaction code contains as little business logic as possible. It should only interact with the user either by asking them for input or by responding to their request to print out data. Separating business logic from user interaction code is a good practice in general and we will come back to this concept in later lessons.
22+
As mentioned above, testing user interaction code (code with ``print`` and ``input`` functions) is harder than testing the rest of your code.
23+
Testing user interaction code requires more advanced unit testing methodologies that will be revisited in future courses.
24+
Therefore, you should refactor your code so that the user interaction code contains as little business logic as possible.
25+
It should only interact with the user either by asking them for input or by responding to their request to print out data.
26+
Separating business logic from user interaction code is a good practice in general and we will come back to this concept in later lessons.
2327

2428
The refactoring in this lesson will allow you to unit test the functions with business logic, even if you don't test the user interaction code.
2529

@@ -68,7 +72,9 @@ Send Letters
6872
............
6973

7074
This function should require very little or no change to make it unit-testable.
71-
To make it testable, you'll need to follow the same "separation of concerns" approach: the code that creates the letters should be separate from the code that prints them to the screen. This both allows you to test the letter creation, and leaves the door open to do something else with the letters: save to to a file, send as an email, etc. So the code that makes a letter likley will return a string with the entire letter contents.
75+
To make it testable, you'll need to follow the same "separation of concerns" approach: the code that creates the letters should be separate from the code that prints them to the screen.
76+
This both allows you to test the letter creation, and leaves the door open to do something else with the letters: save to to a file, send as an email, etc.
77+
So the code that makes a letter likely will return a string with the entire letter contents.
7278

7379
For example:
7480

@@ -83,15 +89,15 @@ For example:
8389
expected = "Frank, thanks a lot!"
8490
assert get_letter_text("Frank") == expected
8591
86-
Note that some thought should go into the test of the letter. IF it's really simple, then checking comparing to a full letter is OK. But it might be better to test the important parts of the letter: Does it contain the correct name? does it contain the right amounts of money? rather than the entire text.
92+
Note that some thought should go into the test of the letter. If it's really simple, then simiply comparing to a full letter is OK. But it might be better to test the important parts of the letter: Does it contain the correct name? does it contain the right amounts of money? rather than the entire text.
8793

8894
When you are done, every function in mailroom that does not contain a ``print`` or ``input`` call should be tested.
8995

9096
And, critically: every function that contains a ``print`` or ``input`` should contain *no other logic at all*.
9197

9298
Yes, that does mean that that you'll have some very simple functions like:
9399

94-
..code-block:: python
100+
.. code-block:: python
95101
96102
def print_letter(donor):
97103
print(make_letter(donor))

source/exercises/string_formatting.rst

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ In this exercise we will reinforce the important concepts of string formatting,
1010

1111
Procedure
1212
=========
13-
Create a new file called ``strformat_lab.py`` in the exercise repo.
13+
Create a new file called ``string_formatting.py`` in the exercise repo -- or use the one that's there, if there is one.
1414

1515
When the empty script is available and runnable, complete the following four tasks.
1616

1717

1818
Task One
1919
--------
20-
* Write a format string that will take the following four element tuple:
20+
* Write a format string that will take the following four values:
2121

22-
``( 2, 123.4567, 10000, 12345.67)``
22+
``(2, 123.4567, 10000, 12345.67)``
2323

2424
and produce:
2525

2626
``'file_002 : 123.46, 1.00e+04, 1.23e+04'``
2727

28+
It should look like:
29+
30+
``print("some_stuff_in_here".format(2, 123.4567, 10000, 12345.67))``
2831

2932
Let's look at each of the four tuple elements in turn:
3033

@@ -61,7 +64,7 @@ So you need to find a string formatting operator that will "pad" the number with
6164
Task Two
6265
--------
6366

64-
Using your results from Task One, repeat the exercise, but this time using an alternate type of format string (hint: think about alternative ways to use .format() (keywords anyone?), and also consider f-strings if you've not used them already).
67+
Using your results from Task One, repeat the exercise, but this time use an alternate type of format string (hint: think about alternative ways to use .format() (keywords anyone?, or indexes?), and also consider f-strings if you've not used them already).
6568

6669

6770
Task Three
@@ -87,7 +90,7 @@ Hint: You can pass in a tuple of values to a function with a ``*``:
8790
8891
The idea here is that you may have a tuple of three numbers, but might also have 4 or 5 or 2 or....
8992

90-
so you can dynamically build up the format string to accommodate the length of the tuple.
93+
So you can dynamically build up the format string to accommodate the length of the tuple.
9194

9295
The string object has the ``format()`` method, so you can call it with a string that is bound to a name, not just a string literal. For example:
9396

@@ -187,7 +190,7 @@ or
187190

188191

189192
Task Six
190-
---------
193+
--------
191194
Often it's convenient to display data in columns. String formatting helps to make this straightforward.
192195

193196
Suppose you'd like to display something like:
@@ -206,7 +209,7 @@ Then you will need to use alignment specifiers. Do some research on this using t
206209

207210
* Write some Python code to print a table of several rows, each with a name, an age and a cost. Make sure some of the costs are in the hundreds and thousands to test your alignment specifiers.
208211

209-
* And for an extra task, given a tuple with 10 consecutive numbers, can you work how to quickly print the tuple in columns that are 5 charaters wide? It can be done on one short line!
212+
* And for an extra task, given a tuple with 10 consecutive numbers, can you work how to quickly print the tuple in columns that are 5 characters wide? It can be done on one short line!
210213

211214

212215
Resources on string formatting
@@ -227,10 +230,11 @@ https://mkaz.blog/code/python-string-format-cookbook/
227230

228231
Submitting Your Work
229232
====================
230-
Put the file in your student directory in a new subdirectory named for this lesson, and add it to your clone early.
233+
234+
Add the file to the develop brnach of your repo for this excercise.
231235

232236
Make frequent commits with good, clear messages about what you're doing and why.
233237

234-
When you're done and ready for the instructors to review your work, push your changes to your gitHub fork and then go to the gitHub website and make a pull request.
238+
When you're done and ready for the instructors to review your work, push your changes to gitHub fork and then go to the gitHub website and make a pull request.
235239

236-
Copy the gitHub link to the pull request, and use the +Submit Assignment link located in the top right corner to submit the URL here.
240+
Copy the gitHub link to the pull request, and provide it to the insstructors when you submit it in your LMS.

source/exercises/unit_testing/test_walnut_party.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,33 @@
2121
# from walnut_party import walnut_party3 as walnut_party
2222

2323

24-
def test_1():
25-
assert walnut_party(30, False) is False
24+
def test_too_few():
25+
assert not walnut_party(30, False)
2626

2727

28-
def test_2():
29-
assert walnut_party(50, False) is True
28+
def test_middle():
29+
assert walnut_party(50, False)
3030

3131

32-
def test_3():
33-
assert walnut_party(70, True) is True
32+
def test_too_many():
33+
assert walnut_party(70, True)
3434

3535

36-
def test_4():
37-
assert walnut_party(30, True) is False
36+
def test_middle50():
37+
assert walnut_party(50, True)
3838

3939

40-
def test_5():
41-
assert walnut_party(50, True) is True
40+
def test_upper_bound():
41+
assert walnut_party(60, False)
4242

4343

44-
def test_6():
45-
assert walnut_party(60, False) is True
44+
def test_just_too_big():
45+
assert not walnut_party(61, False)
4646

4747

48-
def test_7():
49-
assert walnut_party(61, False) is False
48+
def test_lower_bound():
49+
assert walnut_party(40, False)
5050

5151

52-
def test_8():
53-
assert walnut_party(40, False) is True
54-
55-
56-
def test_9():
52+
def test_just_too_small():
5753
assert walnut_party(39, False) is False
58-
59-
60-
def test_10():
61-
assert walnut_party(40, True) is True
62-
63-
64-
def test_11():
65-
assert walnut_party(39, True) is False

0 commit comments

Comments
 (0)