" '''Normalizes a rectangle so that it is at the origin and 1.0 units long on its longest axis.'''\n",
" assert len(rect) == 4, 'Rectangles must contain 4 coordinates'\n",
" llx, llyy, urx, ury = rect\n",
" llx, lly, urx, ury = rect\n",
" assert llx < urx, 'Invalid X coordinates'\n",
" assert lly < ury, 'Invalid Y coordinates'\n",
"\n",
...
...
@@ -141,6 +141,27 @@
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Post-conditions in lines 17, 18 check well formed output:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
...
...
@@ -244,20 +265,6 @@
"# Exercises"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pre- and Post-Conditions\n",
"\n",
"Suppose you are writing a function called average that calculates the average of the numbers in a list. What pre-conditions and post-conditions would you write for it? Compare your answer to your neighbor’s: can you think of a function that will pass your tests but not his/hers or vice versa?"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
...
...
@@ -286,12 +293,17 @@
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pre- and Post-Conditions\n",
"\n",
"Suppose you are writing a function called average that calculates the average of the numbers in a list. What pre-conditions and post-conditions would you write for it? Compare your answer to your neighbor’s: can you think of a function that will pass your tests but not his/hers or vice versa?"
"We found some suspicious features in our firs dataset \"inflammation-01.csv\". It is possible that other datasets are also affected by this?? We would like to check... Fast!"
"We found some suspicious features in our first dataset \"inflammation-01.csv\". It is possible that other datasets are also affected by this?? We would like to check... Fast!"
]
},
{
...
...
@@ -133,22 +133,6 @@
"<li>etc.."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Example 3. This loop overrides the value of a external variable:"
"In last section we discovered something suspicios in our inflammation data by drawing some plots. How can we use Python\n",
"In last section we discovered something suspicious in our inflammation data by drawing some plots. How can we use Python\n",
"to automatically detect the anomalies we found and take an action for each of them?"
]
},
...
...
@@ -38,7 +38,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This scheme is achieved in Python by means of the <code>if</code>/<code>else</code> clause:"
"This scheme is achieved in Python by means of the <code>if</code>/<code>else</code> clause. If there are multiple choices we make use of the <code>elif</code>:"
]
},
{
...
...
@@ -54,25 +54,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Sometimes there is no need to use a else, it depends on the logic of the problem:"
"<strong>Note the \"==\"</strong>. This symbol checks equality rather than \"=\" wich means assingment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Sometimes the flow of the decision is more complex. There are still multiple choices available \n",
"when the first condition is discarded. <br>\n",
"As an example imagine we want to know if a given number is positive negative or zero. We make use of the <code>elif</code> clause:"
"Sometimes there is no need to use a else, it depends on the logic of the problem:"
]
},
{
...
...
@@ -84,13 +73,6 @@
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<strong>Note the \"==\"</strong>. This symbol checks equality rather than \"=\" wich means assingment"
]
},
{
"cell_type": "markdown",
"metadata": {},
...
...
@@ -198,6 +180,20 @@
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
...
...
@@ -213,15 +209,6 @@
"First two files max inflammation seems to rise linearly. So let's write a code that check this behavior and show warning:"
"Suppose you are writing a function called average that calculates the average of the numbers in a list. What pre-conditions and post-conditions would you write for it? Compare your answer to your neighbor’s: can you think of a function that will pass your tests but not his/hers or vice versa?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# a possible pre-condition:\n",
"assert len(input) > 0, #'List length must be non-zero'\n",
"# a possible post-condition:\n",
"assert numpy.min(input) <= average <= numpy.max(input), #'Average should be between min and max of input values'"
]
},
{
"cell_type": "markdown",
"metadata": {},
...
...
@@ -394,10 +371,8 @@
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy\n",
...
...
@@ -409,6 +384,7 @@
" return None\n",
" lowest, highest = ranges[0]\n",
" for (low, high) in ranges[1:]:\n",
" assert low <= high, 'first element in range should be the lower one'\n",
" lowest = max(lowest, low)\n",
" highest = min(highest, high)\n",
" if lowest >= highest: # no overlap\n",
...
...
@@ -419,23 +395,33 @@
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"test_range_overlap()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pre- and Post-Conditions\n",
"\n",
"Suppose you are writing a function called average that calculates the average of the numbers in a list. What pre-conditions and post-conditions would you write for it? Compare your answer to your neighbor’s: can you think of a function that will pass your tests but not his/hers or vice versa?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
"source": [
"# a possible pre-condition:\n",
"assert len(input) > 0, #'List length must be non-zero'\n",
"# a possible post-condition:\n",
"assert numpy.min(input) <= average <= numpy.max(input), #'Average should be between min and max of input values'"