@@ -281,49 +281,52 @@ i.e. their tests are:
281281- ** easier to maintain** - if at some point the data format changes
282282 from CSV to JSON, the bulk of the tests need not be updated
283283
284- > ## Exercise: Testing a Pure Function
285- >
286- > Add tests for ` compute_standard_deviation_by_data() ` that check for situations
287- > when there is only one file with multiple rows,
288- > multiple files with one row, and any other cases you can think of that should be tested.
289- >
290- > > ## Solution
291- > >
292- > > You might have thought of more tests, but we can easily extend the test by parametrizing
293- > > with more inputs and expected outputs:
294- > >
295- > > ``` python
296- > > @ pytest.mark.parametrize(' data,expected_output' , [
297- > > ([[[0 , 1 , 0 ], [0 , 2 , 0 ]]], [0 , 0 , 0 ]),
298- > > ([[[0 , 2 , 0 ]], [[0 , 1 , 0 ]]], [0 , math.sqrt(0.25 ), 0 ]),
299- > > ([[[0 , 1 , 0 ], [0 , 2 , 0 ]], [[0 , 1 , 0 ], [0 , 2 , 0 ]]], [0 , 0 , 0 ])
300- > > ],
301- > > ids = [' Two patients in same file' , ' Two patients in different files' , ' Two identical patients in two different files' ])
302- > > def test_compute_standard_deviation_by_day (data , expected_output ):
303- > > from inflammation.compute_data import compute_standard_deviation_by_data
304- > >
305- > > result = compute_standard_deviation_by_data(data)
306- > > npt.assert_array_almost_equal(result, expected_output)
307- > > ```
284+ ::: challenge
285+ ## Exercise: Testing a Pure Function
308286
287+ Add tests for ` compute_standard_deviation_by_data() ` that check for situations
288+ when there is only one file with multiple rows,
289+ multiple files with one row, and any other cases you can think of that should be tested.
290+
291+ :::: solution
292+
293+ You might have thought of more tests, but we can easily extend the test by parametrizing
294+ with more inputs and expected outputs:
295+
296+ ``` python
297+ @pytest.mark.parametrize (' data,expected_output' , [
298+ ([[[0 , 1 , 0 ], [0 , 2 , 0 ]]], [0 , 0 , 0 ]),
299+ ([[[0 , 2 , 0 ]], [[0 , 1 , 0 ]]], [0 , math.sqrt(0.25 ), 0 ]),
300+ ([[[0 , 1 , 0 ], [0 , 2 , 0 ]], [[0 , 1 , 0 ], [0 , 2 , 0 ]]], [0 , 0 , 0 ])
301+ ],
302+ ids = [' Two patients in same file' , ' Two patients in different files' , ' Two identical patients in two different files' ])
303+ def test_compute_standard_deviation_by_day (data , expected_output ):
304+ from inflammation.compute_data import compute_standard_deviation_by_data
305+
306+ result = compute_standard_deviation_by_data(data)
307+ npt.assert_array_almost_equal(result, expected_output)
309308```
310- > {: .solution}
311- {: .challenge}
312-
313- > ## Functional Programming
314- > ** Functional programming** is a programming paradigm where programs are constructed by
315- > applying and composing/chaining pure functions.
316- > Some programming languages, such as Haskell or Lisp, support writing pure functional code only.
317- > Other languages, such as Python, Java, C++, allow mixing ** functional** and ** procedural**
318- > programming paradigms.
319- > Read more in the [ extra episode on functional programming] ( ../functional-programming/index.html )
320- > and when it can be very useful to switch to this paradigm
321- > (e.g. to employ MapReduce approach for data processing).
322- {: .callout}
323-
324-
325- There are no definite rules in software design but making your complex logic out of
326- composed pure functions is a great place to start when trying to make your code readable,
309+
310+ ::::
311+ :::
312+
313+ ::: callout
314+
315+ ## Functional Programming
316+
317+ ** Functional programming** is a programming paradigm where programs are constructed by
318+ applying and composing/chaining pure functions.
319+ Some programming languages, such as Haskell or Lisp, support writing pure functional code only.
320+ Other languages, such as Python, Java, C++, allow mixing ** functional** and ** procedural**
321+ programming paradigms.
322+ Read more in the [ extra episode on functional programming] ( ../learners/functional-programming.md )
323+ and when it can be very useful to switch to this paradigm
324+ (e.g. to employ MapReduce approach for data processing).
325+
326+ :::
327+
328+ There are no definite rules in software design but making your complex logic out of
329+ composed pure functions is a great place to start when trying to make your code readable,
327330testable and maintainable. This is particularly useful for:
328331
329332* Data processing and analysis
@@ -339,46 +342,46 @@ which are characteristics of (but not limited to) the object-oriented programmin
339342In this episode, we mentioned [ pure functions] ( ./index.html#pure-functions )
340343and Functional Programming.
341344
342- These are examples of different [ programming paradigms] ( / programming-paradigms/index.html )
345+ These are examples of different [ programming paradigms] ( ../learners/ programming-paradigms.md )
343346and provide varied approaches to structuring your code -
344347each with certain strengths and weaknesses when used to solve particular types of problems.
345348In many cases, particularly with modern languages, a single language can allow many different
346349structural approaches and mixing programming paradigms within your code.
347- Once your software begins to get more complex - it is common to use aspects of [ different paradigm] ( ../programming-paradigms/index.html )
350+ Once your software begins to get more complex - it is common to use aspects of [ different paradigm] ( ../learners/ programming-paradigms.md )
348351to handle different subtasks.
349- Because of this, it is useful to know about the [ major paradigms] ( ../programming-paradigms/index.html ) ,
352+ Because of this, it is useful to know about the [ major paradigms] ( ../learners/ programming-paradigms.md ) ,
350353so you can recognise where it might be useful to switch.
351354This is outside of scope of this course - we have some extra episodes on the topics of
352- [ procedural programming] ( ../procedural-programming/index.html ) ,
353- [ functional programming] ( ../functional-programming/index.html ) and
354- [ object-oriented programming] ( ../object-oriented-programming/index.html ) if you want to know more.
355-
356- > ## So Which One is Python?
357- > Python is a multi-paradigm and multi-purpose programming language.
358- > You can use it as a procedural language and you can use it in a more object oriented way.
359- > It does tend to land more on the object oriented side as all its core data types
360- > (strings, integers, floats, booleans, lists,
361- > sets, arrays, tuples, dictionaries, files)
362- > as well as functions, modules and classes are objects.
363- >
364- > Since functions in Python are also objects that can be passed around like any other object,
365- > Python is also well suited to functional programming.
366- > One of the most popular Python libraries for data manipulation,
367- > [ Pandas] ( https://pandas.pydata.org/ ) (built on top of NumPy),
368- > supports a functional programming style
369- > as most of its functions on data are not changing the data (no side effects)
370- > but producing a new data to reflect the result of the function.
371- {: .callout}
355+ [ procedural programming] ( ../learners/procedural-programming.md ) ,
356+ [ functional programming] ( ../learners/functional-programming.md ) and
357+ [ object-oriented programming] ( ../learners/object-oriented-programming.md ) if you want to know more.
358+
359+ ::: callout
360+
361+ ## So Which One is Python?
362+
363+ Python is a multi-paradigm and multi-purpose programming language.
364+ You can use it as a procedural language and you can use it in a more object oriented way.
365+ It does tend to land more on the object oriented side as all its core data types
366+ (strings, integers, floats, booleans, lists,
367+ sets, arrays, tuples, dictionaries, files)
368+ as well as functions, modules and classes are objects.
369+
370+ Since functions in Python are also objects that can be passed around like any other object,
371+ Python is also well suited to functional programming.
372+ One of the most popular Python libraries for data manipulation,
373+ [ Pandas] ( https://pandas.pydata.org/ ) (built on top of NumPy),
374+ supports a functional programming style
375+ as most of its functions on data are not changing the data (no side effects)
376+ but producing a new data to reflect the result of the function.
377+ :::
372378
373379## Software Design and Architecture
374380
375- In this section so far we have been talking about ** software design** - the individual modules and
376- components of the software. We are now going to have a brief look into ** software architecture** -
377- which is about the overall structure that these software components fit into, a * design pattern*
378- with a common successful use of software components.
379-
380- {% include links.md %}
381- ```
381+ In this section so far we have been talking about ** software design** - the individual modules and
382+ components of the software. We are now going to have a brief look into ** software architecture** -
383+ which is about the overall structure that these software components fit into, a * design pattern*
384+ with a common successful use of software components.
382385
383386:::::::::::::::::::::::::::::::::::::::: keypoints
384387
@@ -387,5 +390,3 @@ with a common successful use of software components.
387390- Using pure functions that process data without side effects whenever possible makes the code easier to understand, test and maintain.
388391
389392::::::::::::::::::::::::::::::::::::::::::::::::::
390-
391-
0 commit comments