From 8146a13cdba5c8ae7a388c821996461bb992d59d Mon Sep 17 00:00:00 2001 From: Katy Huff Date: Fri, 11 Jan 2013 16:18:08 -0600 Subject: [PATCH] moves testing into python, appropriately or not... W. Trevor King: I dropped Readme1.md from the original 092cecd, because I had not been cherry-picking its history. It looked fairly similar to the "Building a Library of Code you Trust" section of our current README. Conflicts: python/testing/Readme1.md --- {testing => python/testing}/Readme.md | 54 ++++++++++++++++++++++ {testing => python/testing}/close_line.py | 0 {testing => python/testing}/evo_sol1.png | Bin {testing => python/testing}/mean.py | 0 {testing => python/testing}/test_mean.py | 0 {testing => python/testing}/test_prod.jpg | Bin 6 files changed, 54 insertions(+) rename {testing => python/testing}/Readme.md (89%) rename {testing => python/testing}/close_line.py (100%) rename {testing => python/testing}/evo_sol1.png (100%) rename {testing => python/testing}/mean.py (100%) rename {testing => python/testing}/test_mean.py (100%) rename {testing => python/testing}/test_prod.jpg (100%) diff --git a/testing/Readme.md b/python/testing/Readme.md similarity index 89% rename from testing/Readme.md rename to python/testing/Readme.md index 4cdf2e2..562892b 100644 --- a/testing/Readme.md +++ b/python/testing/Readme.md @@ -543,3 +543,57 @@ p1 = np.array([0.0, 0.0]) p2 = np.array([1.0, 1.0]) data = np.array([[0.3, 0.6], [0.25, 0.5], [1.0, 0.75]]) ``` +Building a Library of Code you Trust +==================================== + +Suppose we’re going to be dealing a lot with these animal count files, +and doing many different kinds of analysis with them. In the +introduction to Python lesson we wrote a function that reads these files +but it’s stuck off in an IPython notebook. We could copy and paste it +into a new notebook every time we want to use it but that gets tedious +and makes it difficult to add features to the function. The ideal +solution would be to keep the function in one spot and use it over and +over again from many different places. Python modules to the rescue! + +We’re going to move beyond the IPython notebook. Most Python code is +stored in \`.py\` files and then used in other \`.py\` files where it +has been pulled in using an \`import\` statement. Today we’ll show you +how to do that. + +Exercises +========= + +Exercise 1 +---------- + +Make a new text file called \`animals.py\`. Copy the file reading +function from yesterday’s IPython notebook into the file and modify it +so that it returns the columns of the file as lists (instead of printing +certain lines). + +Exercise 2 +---------- + +We’re going to make a function to calculate the mean of all the values +in a list, but we’re going to write the tests for it first. Make a new +text file called \`test\_animals.py\`. Make a function called +\`test\_mean\` that runs your theoretical mean function through several +tests. + +Exercise 3 +---------- + +Write the mean function in \`animals.py\` and verify that it passes your +tests. + +Exercise 4 +---------- + +Write tests for a function that will take a file name and animal name as +arguments, and return the average number of animals per sighting. + +Exercise 5 +---------- + +Write a function that takes a file name and animal name and returns the +average number of animals per sighting. Make sure it passes your tests. diff --git a/testing/close_line.py b/python/testing/close_line.py similarity index 100% rename from testing/close_line.py rename to python/testing/close_line.py diff --git a/testing/evo_sol1.png b/python/testing/evo_sol1.png similarity index 100% rename from testing/evo_sol1.png rename to python/testing/evo_sol1.png diff --git a/testing/mean.py b/python/testing/mean.py similarity index 100% rename from testing/mean.py rename to python/testing/mean.py diff --git a/testing/test_mean.py b/python/testing/test_mean.py similarity index 100% rename from testing/test_mean.py rename to python/testing/test_mean.py diff --git a/testing/test_prod.jpg b/python/testing/test_prod.jpg similarity index 100% rename from testing/test_prod.jpg rename to python/testing/test_prod.jpg -- 2.26.2